From 13ff200ba134b8704f37eca99c42b70dab0d17dc Mon Sep 17 00:00:00 2001 From: Xusheng Date: Thu, 1 Jul 2021 12:34:30 +0800 Subject: Remove snippet and kaitai plugin. Note their individual links. --- python/examples/kaitai/__init__.py | 14 - python/examples/kaitai/__main__.py | 183 - python/examples/kaitai/aix_utmp.py | 115 - python/examples/kaitai/allegro_dat.py | 364 -- python/examples/kaitai/andes_firmware.py | 63 - python/examples/kaitai/apm_partition_table.py | 193 - python/examples/kaitai/apple_single_double.py | 179 - python/examples/kaitai/asn1_der.py | 234 -- python/examples/kaitai/avantes_roh60.py | 111 - python/examples/kaitai/avi.py | 291 -- python/examples/kaitai/bcd.py | 110 - python/examples/kaitai/bitcoin_transaction.py | 201 - python/examples/kaitai/blender_blend.py | 321 -- python/examples/kaitai/bmp.py | 180 - python/examples/kaitai/bson.py | 403 -- python/examples/kaitai/code_6502.py | 455 -- python/examples/kaitai/cpio_old_le.py | 145 - python/examples/kaitai/cramfs.py | 339 -- python/examples/kaitai/creative_voice_file.py | 339 -- python/examples/kaitai/dbf.py | 219 - python/examples/kaitai/dex.py | 1083 ----- python/examples/kaitai/dicom.py | 4365 -------------------- python/examples/kaitai/dns_packet.py | 355 -- python/examples/kaitai/doom_wad.py | 653 --- python/examples/kaitai/dos_mz.py | 122 - python/examples/kaitai/dune_2_pak.py | 121 - python/examples/kaitai/edid.py | 432 -- python/examples/kaitai/elf.py | 1685 -------- python/examples/kaitai/ethernet_frame.py | 65 - python/examples/kaitai/exif.py | 35 - python/examples/kaitai/exif_be.py | 620 --- python/examples/kaitai/exif_le.py | 620 --- python/examples/kaitai/ext2.py | 534 --- python/examples/kaitai/fallout2_dat.py | 160 - python/examples/kaitai/fallout_dat.py | 155 - python/examples/kaitai/fasttracker_xm_module.py | 553 --- python/examples/kaitai/ftl_dat.py | 89 - python/examples/kaitai/genmidi_op2.py | 150 - python/examples/kaitai/gettext_mo.py | 544 --- python/examples/kaitai/gif.py | 463 --- python/examples/kaitai/glibc_utmp.py | 113 - python/examples/kaitai/google_protobuf.py | 150 - python/examples/kaitai/gpt_partition_table.py | 172 - python/examples/kaitai/gran_turismo_vol.py | 135 - python/examples/kaitai/gzip.py | 229 - python/examples/kaitai/hccap.py | 109 - python/examples/kaitai/hccapx.py | 100 - python/examples/kaitai/heaps_pak.py | 172 - .../kaitai/heroes_of_might_and_magic_agg.py | 115 - .../kaitai/heroes_of_might_and_magic_bmp.py | 33 - python/examples/kaitai/icc_4.py | 3369 --------------- python/examples/kaitai/icmp_packet.py | 133 - python/examples/kaitai/ico.py | 124 - python/examples/kaitai/id3v1_1.py | 217 - python/examples/kaitai/id3v2_3.py | 309 -- python/examples/kaitai/id3v2_4.py | 410 -- python/examples/kaitai/ines.py | 277 -- python/examples/kaitai/ipv4_packet.py | 157 - python/examples/kaitai/ipv6_packet.py | 54 - python/examples/kaitai/iso9660.py | 535 --- python/examples/kaitai/java_class.py | 951 ----- python/examples/kaitai/jpeg.py | 339 -- python/examples/kaitai/kaitaistruct.py | 379 -- python/examples/kaitai/kshelpers.py | 771 ---- python/examples/kaitai/luks.py | 144 - python/examples/kaitai/lvm2.py | 341 -- python/examples/kaitai/lzh.py | 160 - python/examples/kaitai/mach_o.py | 2739 ------------ python/examples/kaitai/magicavoxel_vox.py | 384 -- python/examples/kaitai/mbr_partition_table.py | 116 - python/examples/kaitai/menu.py | 847 ---- python/examples/kaitai/microsoft_cfb.py | 286 -- .../kaitai/microsoft_network_monitor_v2.py | 306 -- python/examples/kaitai/microsoft_pe.py | 758 ---- python/examples/kaitai/mifare_classic.py | 704 ---- python/examples/kaitai/monomakh_sapr_chg.py | 68 - python/examples/kaitai/msgpack.py | 466 --- python/examples/kaitai/nt_mdt.py | 1308 ------ python/examples/kaitai/nt_mdt_pal.py | 152 - python/examples/kaitai/ogg.py | 113 - python/examples/kaitai/openpgp_message.py | 992 ----- python/examples/kaitai/packet_ppi.py | 513 --- python/examples/kaitai/pcap.py | 234 -- python/examples/kaitai/pcx.py | 170 - python/examples/kaitai/pcx_dcx.py | 76 - python/examples/kaitai/png.py | 580 --- python/examples/kaitai/protocol_body.py | 259 -- python/examples/kaitai/psx_tim.py | 89 - python/examples/kaitai/python_pyc_27.py | 507 --- python/examples/kaitai/quake_mdl.py | 376 -- python/examples/kaitai/quake_pak.py | 109 - python/examples/kaitai/quicktime_mov.py | 478 --- python/examples/kaitai/rar.py | 322 -- python/examples/kaitai/regf.py | 545 --- python/examples/kaitai/renderware_binary_stream.py | 773 ---- python/examples/kaitai/rtcp_payload.py | 578 --- python/examples/kaitai/rtp_packet.py | 149 - python/examples/kaitai/ruby_marshal.py | 416 -- python/examples/kaitai/s3m.py | 484 --- python/examples/kaitai/saints_row_2_vpp_pc.py | 251 -- python/examples/kaitai/shapefile_index.py | 159 - python/examples/kaitai/shapefile_main.py | 878 ---- python/examples/kaitai/specpr.py | 403 -- python/examples/kaitai/sqlite3.py | 469 --- python/examples/kaitai/ssh_public_key.py | 251 -- python/examples/kaitai/standard_midi_file.py | 385 -- python/examples/kaitai/stl.py | 107 - python/examples/kaitai/swf.py | 403 -- python/examples/kaitai/systemd_journal.py | 358 -- python/examples/kaitai/tcp_segment.py | 56 - python/examples/kaitai/tga.py | 212 - python/examples/kaitai/tls_client_hello.py | 292 -- python/examples/kaitai/tr_dos_image.py | 317 -- python/examples/kaitai/tsm.py | 195 - python/examples/kaitai/ttf.py | 1817 -------- python/examples/kaitai/udp_datagram.py | 41 - python/examples/kaitai/uimage.py | 148 - python/examples/kaitai/vdi.py | 458 -- python/examples/kaitai/vfat.py | 359 -- python/examples/kaitai/view.py | 367 -- python/examples/kaitai/vlq_base128_be.py | 102 - python/examples/kaitai/vlq_base128_le.py | 108 - python/examples/kaitai/vmware_vmdk.py | 164 - python/examples/kaitai/vp8_ivf.py | 107 - python/examples/kaitai/warcraft_2_pud.py | 420 -- python/examples/kaitai/wav.py | 491 --- python/examples/kaitai/windows_evt_log.py | 299 -- python/examples/kaitai/windows_lnk_file.py | 460 --- python/examples/kaitai/windows_minidump.py | 540 --- python/examples/kaitai/windows_resource_file.py | 242 -- python/examples/kaitai/windows_shell_items.py | 189 - python/examples/kaitai/windows_systemtime.py | 51 - python/examples/kaitai/wmf.py | 459 -- python/examples/kaitai/xwd.py | 188 - python/examples/kaitai/zip.py | 502 --- 135 files changed, 55406 deletions(-) delete mode 100644 python/examples/kaitai/__init__.py delete mode 100755 python/examples/kaitai/__main__.py delete mode 100644 python/examples/kaitai/aix_utmp.py delete mode 100644 python/examples/kaitai/allegro_dat.py delete mode 100644 python/examples/kaitai/andes_firmware.py delete mode 100644 python/examples/kaitai/apm_partition_table.py delete mode 100644 python/examples/kaitai/apple_single_double.py delete mode 100644 python/examples/kaitai/asn1_der.py delete mode 100644 python/examples/kaitai/avantes_roh60.py delete mode 100644 python/examples/kaitai/avi.py delete mode 100644 python/examples/kaitai/bcd.py delete mode 100644 python/examples/kaitai/bitcoin_transaction.py delete mode 100644 python/examples/kaitai/blender_blend.py delete mode 100644 python/examples/kaitai/bmp.py delete mode 100644 python/examples/kaitai/bson.py delete mode 100644 python/examples/kaitai/code_6502.py delete mode 100644 python/examples/kaitai/cpio_old_le.py delete mode 100644 python/examples/kaitai/cramfs.py delete mode 100644 python/examples/kaitai/creative_voice_file.py delete mode 100644 python/examples/kaitai/dbf.py delete mode 100644 python/examples/kaitai/dex.py delete mode 100644 python/examples/kaitai/dicom.py delete mode 100644 python/examples/kaitai/dns_packet.py delete mode 100644 python/examples/kaitai/doom_wad.py delete mode 100644 python/examples/kaitai/dos_mz.py delete mode 100644 python/examples/kaitai/dune_2_pak.py delete mode 100644 python/examples/kaitai/edid.py delete mode 100644 python/examples/kaitai/elf.py delete mode 100644 python/examples/kaitai/ethernet_frame.py delete mode 100644 python/examples/kaitai/exif.py delete mode 100644 python/examples/kaitai/exif_be.py delete mode 100644 python/examples/kaitai/exif_le.py delete mode 100644 python/examples/kaitai/ext2.py delete mode 100644 python/examples/kaitai/fallout2_dat.py delete mode 100644 python/examples/kaitai/fallout_dat.py delete mode 100644 python/examples/kaitai/fasttracker_xm_module.py delete mode 100644 python/examples/kaitai/ftl_dat.py delete mode 100644 python/examples/kaitai/genmidi_op2.py delete mode 100644 python/examples/kaitai/gettext_mo.py delete mode 100644 python/examples/kaitai/gif.py delete mode 100644 python/examples/kaitai/glibc_utmp.py delete mode 100644 python/examples/kaitai/google_protobuf.py delete mode 100644 python/examples/kaitai/gpt_partition_table.py delete mode 100644 python/examples/kaitai/gran_turismo_vol.py delete mode 100644 python/examples/kaitai/gzip.py delete mode 100644 python/examples/kaitai/hccap.py delete mode 100644 python/examples/kaitai/hccapx.py delete mode 100644 python/examples/kaitai/heaps_pak.py delete mode 100644 python/examples/kaitai/heroes_of_might_and_magic_agg.py delete mode 100644 python/examples/kaitai/heroes_of_might_and_magic_bmp.py delete mode 100644 python/examples/kaitai/icc_4.py delete mode 100644 python/examples/kaitai/icmp_packet.py delete mode 100644 python/examples/kaitai/ico.py delete mode 100644 python/examples/kaitai/id3v1_1.py delete mode 100644 python/examples/kaitai/id3v2_3.py delete mode 100644 python/examples/kaitai/id3v2_4.py delete mode 100644 python/examples/kaitai/ines.py delete mode 100644 python/examples/kaitai/ipv4_packet.py delete mode 100644 python/examples/kaitai/ipv6_packet.py delete mode 100644 python/examples/kaitai/iso9660.py delete mode 100644 python/examples/kaitai/java_class.py delete mode 100644 python/examples/kaitai/jpeg.py delete mode 100644 python/examples/kaitai/kaitaistruct.py delete mode 100644 python/examples/kaitai/kshelpers.py delete mode 100644 python/examples/kaitai/luks.py delete mode 100644 python/examples/kaitai/lvm2.py delete mode 100644 python/examples/kaitai/lzh.py delete mode 100644 python/examples/kaitai/mach_o.py delete mode 100644 python/examples/kaitai/magicavoxel_vox.py delete mode 100644 python/examples/kaitai/mbr_partition_table.py delete mode 100644 python/examples/kaitai/menu.py delete mode 100644 python/examples/kaitai/microsoft_cfb.py delete mode 100644 python/examples/kaitai/microsoft_network_monitor_v2.py delete mode 100644 python/examples/kaitai/microsoft_pe.py delete mode 100644 python/examples/kaitai/mifare_classic.py delete mode 100644 python/examples/kaitai/monomakh_sapr_chg.py delete mode 100644 python/examples/kaitai/msgpack.py delete mode 100644 python/examples/kaitai/nt_mdt.py delete mode 100644 python/examples/kaitai/nt_mdt_pal.py delete mode 100644 python/examples/kaitai/ogg.py delete mode 100644 python/examples/kaitai/openpgp_message.py delete mode 100644 python/examples/kaitai/packet_ppi.py delete mode 100644 python/examples/kaitai/pcap.py delete mode 100644 python/examples/kaitai/pcx.py delete mode 100644 python/examples/kaitai/pcx_dcx.py delete mode 100644 python/examples/kaitai/png.py delete mode 100644 python/examples/kaitai/protocol_body.py delete mode 100644 python/examples/kaitai/psx_tim.py delete mode 100644 python/examples/kaitai/python_pyc_27.py delete mode 100644 python/examples/kaitai/quake_mdl.py delete mode 100644 python/examples/kaitai/quake_pak.py delete mode 100644 python/examples/kaitai/quicktime_mov.py delete mode 100644 python/examples/kaitai/rar.py delete mode 100644 python/examples/kaitai/regf.py delete mode 100644 python/examples/kaitai/renderware_binary_stream.py delete mode 100644 python/examples/kaitai/rtcp_payload.py delete mode 100644 python/examples/kaitai/rtp_packet.py delete mode 100644 python/examples/kaitai/ruby_marshal.py delete mode 100644 python/examples/kaitai/s3m.py delete mode 100644 python/examples/kaitai/saints_row_2_vpp_pc.py delete mode 100644 python/examples/kaitai/shapefile_index.py delete mode 100644 python/examples/kaitai/shapefile_main.py delete mode 100644 python/examples/kaitai/specpr.py delete mode 100644 python/examples/kaitai/sqlite3.py delete mode 100644 python/examples/kaitai/ssh_public_key.py delete mode 100644 python/examples/kaitai/standard_midi_file.py delete mode 100644 python/examples/kaitai/stl.py delete mode 100644 python/examples/kaitai/swf.py delete mode 100644 python/examples/kaitai/systemd_journal.py delete mode 100644 python/examples/kaitai/tcp_segment.py delete mode 100644 python/examples/kaitai/tga.py delete mode 100644 python/examples/kaitai/tls_client_hello.py delete mode 100644 python/examples/kaitai/tr_dos_image.py delete mode 100644 python/examples/kaitai/tsm.py delete mode 100644 python/examples/kaitai/ttf.py delete mode 100644 python/examples/kaitai/udp_datagram.py delete mode 100644 python/examples/kaitai/uimage.py delete mode 100644 python/examples/kaitai/vdi.py delete mode 100644 python/examples/kaitai/vfat.py delete mode 100644 python/examples/kaitai/view.py delete mode 100644 python/examples/kaitai/vlq_base128_be.py delete mode 100644 python/examples/kaitai/vlq_base128_le.py delete mode 100644 python/examples/kaitai/vmware_vmdk.py delete mode 100644 python/examples/kaitai/vp8_ivf.py delete mode 100644 python/examples/kaitai/warcraft_2_pud.py delete mode 100644 python/examples/kaitai/wav.py delete mode 100644 python/examples/kaitai/windows_evt_log.py delete mode 100644 python/examples/kaitai/windows_lnk_file.py delete mode 100644 python/examples/kaitai/windows_minidump.py delete mode 100644 python/examples/kaitai/windows_resource_file.py delete mode 100644 python/examples/kaitai/windows_shell_items.py delete mode 100644 python/examples/kaitai/windows_systemtime.py delete mode 100644 python/examples/kaitai/wmf.py delete mode 100644 python/examples/kaitai/xwd.py delete mode 100644 python/examples/kaitai/zip.py (limited to 'python/examples/kaitai') diff --git a/python/examples/kaitai/__init__.py b/python/examples/kaitai/__init__.py deleted file mode 100644 index 7ac825d2..00000000 --- a/python/examples/kaitai/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -import sys - -# invoked from python2 command line? (eg: python -m kaitai ...) -if sys.version_info[0] == 2 and sys.argv[0:] and sys.argv[0]=='-c': - pass -# invoked from python3 command line? (eg: python -m kaitai ...) -elif sys.version_info[0] == 3 and sys.argv[0:] and sys.argv[0]=='-m': - pass -# invoked from binja -else: - if sys.version_info[0] == 2: - import view - else: - from . import view diff --git a/python/examples/kaitai/__main__.py b/python/examples/kaitai/__main__.py deleted file mode 100755 index 33e8e549..00000000 --- a/python/examples/kaitai/__main__.py +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env python - -# test script - -from __future__ import print_function - -import io -import sys -import types -import importlib - -if sys.version_info[0] == 2: - import kaitaistruct - import kshelpers -else: - from . import kaitaistruct - from . import kshelpers - -NORMAL = '\033[0m' -BLACK = '\033[0;30m' -RED = '\033[0;31m' -GREEN = '\033[0;32m' -YELLOW = '\033[0;33m' -BLUE = '\033[0;34m' -PURPLE = '\033[0;35m' -CYAN = '\033[0;36m' -GRAY = '\033[0;37m' - -LBLACK = '\033[1;30m' -LRED = '\033[1;31m' -LGREEN = '\033[1;32m' -LYELLOW = '\033[1;33m' -LBLUE = '\033[1;34m' -LPURPLE = '\033[1;35m' -LCYAN = '\033[1;36m' -LGRAY = '\033[1;37m' - -def dump(obj, depth=0): - indent = ' '*depth - - print(('%s'+PURPLE+'%s'+NORMAL) % (indent, repr(obj))) - - kshelpers.exercise(obj) - for fieldName in kshelpers.getFieldNamesPrint(obj): - subObj = None - try: - subObj = getattr(obj, fieldName) - except Exception: - continue - if subObj == None: - continue - - subObjStr = kshelpers.objToStr(subObj) - - color = '' - - if type(subObj) == types.MethodType: - pass - elif isinstance(subObj, type): - pass - elif fieldName == '_debug': - color = RED - elif isinstance(subObj, list): - pass - elif isinstance(subObj, dict): - pass - elif isinstance(subObj, str): - color = CYAN - elif isinstance(subObj, bytes): - color = CYAN - elif type(subObj) == int: - color = YELLOW - elif str(type(subObj)).startswith('> 0) & 1) - return self._m_flag_fsid_v2 if hasattr(self, '_m_flag_fsid_v2') else None - - @property - def flag_holes(self): - if hasattr(self, '_m_flag_holes'): - return self._m_flag_holes if hasattr(self, '_m_flag_holes') else None - - self._m_flag_holes = ((self.flags >> 8) & 1) - return self._m_flag_holes if hasattr(self, '_m_flag_holes') else None - - @property - def flag_wrong_signature(self): - if hasattr(self, '_m_flag_wrong_signature'): - return self._m_flag_wrong_signature if hasattr(self, '_m_flag_wrong_signature') else None - - self._m_flag_wrong_signature = ((self.flags >> 9) & 1) - return self._m_flag_wrong_signature if hasattr(self, '_m_flag_wrong_signature') else None - - @property - def flag_sorted_dirs(self): - if hasattr(self, '_m_flag_sorted_dirs'): - return self._m_flag_sorted_dirs if hasattr(self, '_m_flag_sorted_dirs') else None - - self._m_flag_sorted_dirs = ((self.flags >> 1) & 1) - return self._m_flag_sorted_dirs if hasattr(self, '_m_flag_sorted_dirs') else None - - @property - def flag_shifted_root_offset(self): - if hasattr(self, '_m_flag_shifted_root_offset'): - return self._m_flag_shifted_root_offset if hasattr(self, '_m_flag_shifted_root_offset') else None - - self._m_flag_shifted_root_offset = ((self.flags >> 10) & 1) - return self._m_flag_shifted_root_offset if hasattr(self, '_m_flag_shifted_root_offset') else None - - - class ChunkedDataInode(KaitaiStruct): - SEQ_FIELDS = ["block_end_index", "raw_blocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_end_index']['start'] = self._io.pos() - self.block_end_index = [None] * (((self._parent.size + self._root.page_size) - 1) // self._root.page_size) - for i in range(((self._parent.size + self._root.page_size) - 1) // self._root.page_size): - if not 'arr' in self._debug['block_end_index']: - self._debug['block_end_index']['arr'] = [] - self._debug['block_end_index']['arr'].append({'start': self._io.pos()}) - self.block_end_index[i] = self._io.read_u4le() - self._debug['block_end_index']['arr'][i]['end'] = self._io.pos() - - self._debug['block_end_index']['end'] = self._io.pos() - self._debug['raw_blocks']['start'] = self._io.pos() - self.raw_blocks = self._io.read_bytes_full() - self._debug['raw_blocks']['end'] = self._io.pos() - - - class Inode(KaitaiStruct): - - class FileType(Enum): - fifo = 1 - chrdev = 2 - dir = 4 - blkdev = 6 - reg_file = 8 - symlink = 10 - socket = 12 - SEQ_FIELDS = ["mode", "uid", "size_gid", "namelen_offset", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['mode']['start'] = self._io.pos() - self.mode = self._io.read_u2le() - self._debug['mode']['end'] = self._io.pos() - self._debug['uid']['start'] = self._io.pos() - self.uid = self._io.read_u2le() - self._debug['uid']['end'] = self._io.pos() - self._debug['size_gid']['start'] = self._io.pos() - self.size_gid = self._io.read_u4le() - self._debug['size_gid']['end'] = self._io.pos() - self._debug['namelen_offset']['start'] = self._io.pos() - self.namelen_offset = self._io.read_u4le() - self._debug['namelen_offset']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.namelen)).decode(u"utf-8") - self._debug['name']['end'] = self._io.pos() - - @property - def attr(self): - if hasattr(self, '_m_attr'): - return self._m_attr if hasattr(self, '_m_attr') else None - - self._m_attr = ((self.mode >> 9) & 7) - return self._m_attr if hasattr(self, '_m_attr') else None - - @property - def as_reg_file(self): - if hasattr(self, '_m_as_reg_file'): - return self._m_as_reg_file if hasattr(self, '_m_as_reg_file') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_as_reg_file']['start'] = io.pos() - self._m_as_reg_file = self._root.ChunkedDataInode(io, self, self._root) - self._m_as_reg_file._read() - self._debug['_m_as_reg_file']['end'] = io.pos() - io.seek(_pos) - return self._m_as_reg_file if hasattr(self, '_m_as_reg_file') else None - - @property - def perm_u(self): - if hasattr(self, '_m_perm_u'): - return self._m_perm_u if hasattr(self, '_m_perm_u') else None - - self._m_perm_u = ((self.mode >> 6) & 7) - return self._m_perm_u if hasattr(self, '_m_perm_u') else None - - @property - def as_symlink(self): - if hasattr(self, '_m_as_symlink'): - return self._m_as_symlink if hasattr(self, '_m_as_symlink') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_as_symlink']['start'] = io.pos() - self._m_as_symlink = self._root.ChunkedDataInode(io, self, self._root) - self._m_as_symlink._read() - self._debug['_m_as_symlink']['end'] = io.pos() - io.seek(_pos) - return self._m_as_symlink if hasattr(self, '_m_as_symlink') else None - - @property - def perm_o(self): - if hasattr(self, '_m_perm_o'): - return self._m_perm_o if hasattr(self, '_m_perm_o') else None - - self._m_perm_o = (self.mode & 7) - return self._m_perm_o if hasattr(self, '_m_perm_o') else None - - @property - def size(self): - if hasattr(self, '_m_size'): - return self._m_size if hasattr(self, '_m_size') else None - - self._m_size = (self.size_gid & 16777215) - return self._m_size if hasattr(self, '_m_size') else None - - @property - def gid(self): - if hasattr(self, '_m_gid'): - return self._m_gid if hasattr(self, '_m_gid') else None - - self._m_gid = (self.size_gid >> 24) - return self._m_gid if hasattr(self, '_m_gid') else None - - @property - def perm_g(self): - if hasattr(self, '_m_perm_g'): - return self._m_perm_g if hasattr(self, '_m_perm_g') else None - - self._m_perm_g = ((self.mode >> 3) & 7) - return self._m_perm_g if hasattr(self, '_m_perm_g') else None - - @property - def namelen(self): - if hasattr(self, '_m_namelen'): - return self._m_namelen if hasattr(self, '_m_namelen') else None - - self._m_namelen = ((self.namelen_offset & 63) << 2) - return self._m_namelen if hasattr(self, '_m_namelen') else None - - @property - def as_dir(self): - if hasattr(self, '_m_as_dir'): - return self._m_as_dir if hasattr(self, '_m_as_dir') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_as_dir']['start'] = io.pos() - self._raw__m_as_dir = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_as_dir)) - self._m_as_dir = self._root.DirInode(io, self, self._root) - self._m_as_dir._read() - self._debug['_m_as_dir']['end'] = io.pos() - io.seek(_pos) - return self._m_as_dir if hasattr(self, '_m_as_dir') else None - - @property - def type(self): - if hasattr(self, '_m_type'): - return self._m_type if hasattr(self, '_m_type') else None - - self._m_type = KaitaiStream.resolve_enum(self._root.Inode.FileType, ((self.mode >> 12) & 15)) - return self._m_type if hasattr(self, '_m_type') else None - - @property - def offset(self): - if hasattr(self, '_m_offset'): - return self._m_offset if hasattr(self, '_m_offset') else None - - self._m_offset = (((self.namelen_offset >> 6) & 67108863) << 2) - return self._m_offset if hasattr(self, '_m_offset') else None - - - class DirInode(KaitaiStruct): - SEQ_FIELDS = ["children"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - if self._io.size() > 0: - self._debug['children']['start'] = self._io.pos() - self.children = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['children']: - self._debug['children']['arr'] = [] - self._debug['children']['arr'].append({'start': self._io.pos()}) - _t_children = self._root.Inode(self._io, self, self._root) - _t_children._read() - self.children.append(_t_children) - self._debug['children']['arr'][len(self.children) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['children']['end'] = self._io.pos() - - - - class Info(KaitaiStruct): - SEQ_FIELDS = ["crc", "edition", "blocks", "files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['crc']['start'] = self._io.pos() - self.crc = self._io.read_u4le() - self._debug['crc']['end'] = self._io.pos() - self._debug['edition']['start'] = self._io.pos() - self.edition = self._io.read_u4le() - self._debug['edition']['end'] = self._io.pos() - self._debug['blocks']['start'] = self._io.pos() - self.blocks = self._io.read_u4le() - self._debug['blocks']['end'] = self._io.pos() - self._debug['files']['start'] = self._io.pos() - self.files = self._io.read_u4le() - self._debug['files']['end'] = self._io.pos() - - - @property - def page_size(self): - if hasattr(self, '_m_page_size'): - return self._m_page_size if hasattr(self, '_m_page_size') else None - - self._m_page_size = 4096 - return self._m_page_size if hasattr(self, '_m_page_size') else None - - diff --git a/python/examples/kaitai/creative_voice_file.py b/python/examples/kaitai/creative_voice_file.py deleted file mode 100644 index 3ee67227..00000000 --- a/python/examples/kaitai/creative_voice_file.py +++ /dev/null @@ -1,339 +0,0 @@ -# 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 -import collections - - -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 CreativeVoiceFile(KaitaiStruct): - """Creative Voice File is a container file format for digital audio - wave data. Initial revisions were able to support only unsigned - 8-bit PCM and ADPCM data, later versions were revised to add support - for 16-bit PCM and a-law / u-law formats. - - This format was actively used in 1990s, around the advent of - Creative's sound cards (Sound Blaster family). It was a popular - choice for a digital sound container in lots of games and multimedia - software due to simplicity and availability of Creative's recording - / editing tools. - - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice - """ - - class BlockTypes(Enum): - terminator = 0 - sound_data = 1 - sound_data_cont = 2 - silence = 3 - marker = 4 - text = 5 - repeat_start = 6 - repeat_end = 7 - extra_info = 8 - sound_data_new = 9 - - class Codecs(Enum): - pcm_8bit_unsigned = 0 - adpcm_4bit = 1 - adpcm_2_6bit = 2 - adpcm_2_bit = 3 - pcm_16bit_signed = 4 - alaw = 6 - ulaw = 7 - adpcm_4_to_16bit = 512 - SEQ_FIELDS = ["magic", "header_size", "version", "checksum", "blocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x43\x72\x65\x61\x74\x69\x76\x65\x20\x56\x6F\x69\x63\x65\x20\x46\x69\x6C\x65\x1A") - self._debug['magic']['end'] = self._io.pos() - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_u2le() - self._debug['header_size']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2le() - self._debug['checksum']['end'] = self._io.pos() - self._debug['blocks']['start'] = self._io.pos() - self.blocks = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _t_blocks = self._root.Block(self._io, self, self._root) - _t_blocks._read() - self.blocks.append(_t_blocks) - self._debug['blocks']['arr'][len(self.blocks) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['blocks']['end'] = self._io.pos() - - class BlockMarker(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x04:_Marker - """ - SEQ_FIELDS = ["marker_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['marker_id']['start'] = self._io.pos() - self.marker_id = self._io.read_u2le() - self._debug['marker_id']['end'] = self._io.pos() - - - class BlockSilence(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x03:_Silence - """ - SEQ_FIELDS = ["duration_samples", "freq_div"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['duration_samples']['start'] = self._io.pos() - self.duration_samples = self._io.read_u2le() - self._debug['duration_samples']['end'] = self._io.pos() - self._debug['freq_div']['start'] = self._io.pos() - self.freq_div = self._io.read_u1() - self._debug['freq_div']['end'] = self._io.pos() - - @property - def sample_rate(self): - if hasattr(self, '_m_sample_rate'): - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - self._m_sample_rate = (1000000.0 / (256 - self.freq_div)) - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - @property - def duration_sec(self): - """Duration of silence, in seconds.""" - if hasattr(self, '_m_duration_sec'): - return self._m_duration_sec if hasattr(self, '_m_duration_sec') else None - - self._m_duration_sec = (self.duration_samples / self.sample_rate) - return self._m_duration_sec if hasattr(self, '_m_duration_sec') else None - - - class BlockSoundDataNew(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x09:_Sound_data_.28New_format.29 - """ - SEQ_FIELDS = ["sample_rate", "bits_per_sample", "num_channels", "codec", "reserved", "wave"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sample_rate']['start'] = self._io.pos() - self.sample_rate = self._io.read_u4le() - self._debug['sample_rate']['end'] = self._io.pos() - self._debug['bits_per_sample']['start'] = self._io.pos() - self.bits_per_sample = self._io.read_u1() - self._debug['bits_per_sample']['end'] = self._io.pos() - self._debug['num_channels']['start'] = self._io.pos() - self.num_channels = self._io.read_u1() - self._debug['num_channels']['end'] = self._io.pos() - self._debug['codec']['start'] = self._io.pos() - self.codec = KaitaiStream.resolve_enum(self._root.Codecs, self._io.read_u2le()) - self._debug['codec']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(4) - self._debug['reserved']['end'] = self._io.pos() - self._debug['wave']['start'] = self._io.pos() - self.wave = self._io.read_bytes_full() - self._debug['wave']['end'] = self._io.pos() - - - class Block(KaitaiStruct): - SEQ_FIELDS = ["block_type", "body_size1", "body_size2", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_type']['start'] = self._io.pos() - self.block_type = KaitaiStream.resolve_enum(self._root.BlockTypes, self._io.read_u1()) - self._debug['block_type']['end'] = self._io.pos() - if self.block_type != self._root.BlockTypes.terminator: - self._debug['body_size1']['start'] = self._io.pos() - self.body_size1 = self._io.read_u2le() - self._debug['body_size1']['end'] = self._io.pos() - - if self.block_type != self._root.BlockTypes.terminator: - self._debug['body_size2']['start'] = self._io.pos() - self.body_size2 = self._io.read_u1() - self._debug['body_size2']['end'] = self._io.pos() - - if self.block_type != self._root.BlockTypes.terminator: - self._debug['body']['start'] = self._io.pos() - _on = self.block_type - if _on == self._root.BlockTypes.sound_data_new: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockSoundDataNew(io, self, self._root) - self.body._read() - elif _on == self._root.BlockTypes.repeat_start: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockRepeatStart(io, self, self._root) - self.body._read() - elif _on == self._root.BlockTypes.marker: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockMarker(io, self, self._root) - self.body._read() - elif _on == self._root.BlockTypes.sound_data: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockSoundData(io, self, self._root) - self.body._read() - elif _on == self._root.BlockTypes.extra_info: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockExtraInfo(io, self, self._root) - self.body._read() - elif _on == self._root.BlockTypes.silence: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockSilence(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.body_size) - self._debug['body']['end'] = self._io.pos() - - - @property - def body_size(self): - """body_size is a 24-bit little-endian integer, so we're - emulating that by adding two standard-sized integers - (body_size1 and body_size2). - """ - if hasattr(self, '_m_body_size'): - return self._m_body_size if hasattr(self, '_m_body_size') else None - - if self.block_type != self._root.BlockTypes.terminator: - self._m_body_size = (self.body_size1 + (self.body_size2 << 16)) - - return self._m_body_size if hasattr(self, '_m_body_size') else None - - - class BlockRepeatStart(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x06:_Repeat_start - """ - SEQ_FIELDS = ["repeat_count_1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['repeat_count_1']['start'] = self._io.pos() - self.repeat_count_1 = self._io.read_u2le() - self._debug['repeat_count_1']['end'] = self._io.pos() - - - class BlockSoundData(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x01:_Sound_data - """ - SEQ_FIELDS = ["freq_div", "codec", "wave"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['freq_div']['start'] = self._io.pos() - self.freq_div = self._io.read_u1() - self._debug['freq_div']['end'] = self._io.pos() - self._debug['codec']['start'] = self._io.pos() - self.codec = KaitaiStream.resolve_enum(self._root.Codecs, self._io.read_u1()) - self._debug['codec']['end'] = self._io.pos() - self._debug['wave']['start'] = self._io.pos() - self.wave = self._io.read_bytes_full() - self._debug['wave']['end'] = self._io.pos() - - @property - def sample_rate(self): - if hasattr(self, '_m_sample_rate'): - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - self._m_sample_rate = (1000000.0 / (256 - self.freq_div)) - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - - class BlockExtraInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.multimedia.cx/index.php?title=Creative_Voice#Block_type_0x08:_Extra_info - """ - SEQ_FIELDS = ["freq_div", "codec", "num_channels_1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['freq_div']['start'] = self._io.pos() - self.freq_div = self._io.read_u2le() - self._debug['freq_div']['end'] = self._io.pos() - self._debug['codec']['start'] = self._io.pos() - self.codec = KaitaiStream.resolve_enum(self._root.Codecs, self._io.read_u1()) - self._debug['codec']['end'] = self._io.pos() - self._debug['num_channels_1']['start'] = self._io.pos() - self.num_channels_1 = self._io.read_u1() - self._debug['num_channels_1']['end'] = self._io.pos() - - @property - def num_channels(self): - """Number of channels (1 = mono, 2 = stereo).""" - if hasattr(self, '_m_num_channels'): - return self._m_num_channels if hasattr(self, '_m_num_channels') else None - - self._m_num_channels = (self.num_channels_1 + 1) - return self._m_num_channels if hasattr(self, '_m_num_channels') else None - - @property - def sample_rate(self): - if hasattr(self, '_m_sample_rate'): - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - self._m_sample_rate = (256000000.0 / (self.num_channels * (65536 - self.freq_div))) - return self._m_sample_rate if hasattr(self, '_m_sample_rate') else None - - - diff --git a/python/examples/kaitai/dbf.py b/python/examples/kaitai/dbf.py deleted file mode 100644 index ba026162..00000000 --- a/python/examples/kaitai/dbf.py +++ /dev/null @@ -1,219 +0,0 @@ -# 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 -import collections - - -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 Dbf(KaitaiStruct): - SEQ_FIELDS = ["header1", "header2", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header1']['start'] = self._io.pos() - self.header1 = self._root.Header1(self._io, self, self._root) - self.header1._read() - self._debug['header1']['end'] = self._io.pos() - self._debug['header2']['start'] = self._io.pos() - self._raw_header2 = self._io.read_bytes((self.header1.len_header - 12)) - io = KaitaiStream(BytesIO(self._raw_header2)) - self.header2 = self._root.Header2(io, self, self._root) - self.header2._read() - self._debug['header2']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [None] * (self.header1.num_records) - for i in range(self.header1.num_records): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - self.records[i] = self._io.read_bytes(self.header1.len_record) - self._debug['records']['arr'][i]['end'] = self._io.pos() - - self._debug['records']['end'] = self._io.pos() - - class Header2(KaitaiStruct): - SEQ_FIELDS = ["header_dbase_3", "header_dbase_7", "fields"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - if self._root.header1.dbase_level == 3: - self._debug['header_dbase_3']['start'] = self._io.pos() - self.header_dbase_3 = self._root.HeaderDbase3(self._io, self, self._root) - self.header_dbase_3._read() - self._debug['header_dbase_3']['end'] = self._io.pos() - - if self._root.header1.dbase_level == 7: - self._debug['header_dbase_7']['start'] = self._io.pos() - self.header_dbase_7 = self._root.HeaderDbase7(self._io, self, self._root) - self.header_dbase_7._read() - self._debug['header_dbase_7']['end'] = self._io.pos() - - self._debug['fields']['start'] = self._io.pos() - self.fields = [None] * (11) - for i in range(11): - if not 'arr' in self._debug['fields']: - self._debug['fields']['arr'] = [] - self._debug['fields']['arr'].append({'start': self._io.pos()}) - _t_fields = self._root.Field(self._io, self, self._root) - _t_fields._read() - self.fields[i] = _t_fields - self._debug['fields']['arr'][i]['end'] = self._io.pos() - - self._debug['fields']['end'] = self._io.pos() - - - class Field(KaitaiStruct): - SEQ_FIELDS = ["name", "datatype", "data_address", "length", "decimal_count", "reserved1", "work_area_id", "reserved2", "set_fields_flag", "reserved3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(11)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - self._debug['datatype']['start'] = self._io.pos() - self.datatype = self._io.read_u1() - self._debug['datatype']['end'] = self._io.pos() - self._debug['data_address']['start'] = self._io.pos() - self.data_address = self._io.read_u4le() - self._debug['data_address']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u1() - self._debug['length']['end'] = self._io.pos() - self._debug['decimal_count']['start'] = self._io.pos() - self.decimal_count = self._io.read_u1() - self._debug['decimal_count']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(2) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['work_area_id']['start'] = self._io.pos() - self.work_area_id = self._io.read_u1() - self._debug['work_area_id']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(2) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['set_fields_flag']['start'] = self._io.pos() - self.set_fields_flag = self._io.read_u1() - self._debug['set_fields_flag']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_bytes(8) - self._debug['reserved3']['end'] = self._io.pos() - - - class Header1(KaitaiStruct): - """ - .. seealso:: - - section 1.1 - http://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm - """ - SEQ_FIELDS = ["version", "last_update_y", "last_update_m", "last_update_d", "num_records", "len_header", "len_record"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['last_update_y']['start'] = self._io.pos() - self.last_update_y = self._io.read_u1() - self._debug['last_update_y']['end'] = self._io.pos() - self._debug['last_update_m']['start'] = self._io.pos() - self.last_update_m = self._io.read_u1() - self._debug['last_update_m']['end'] = self._io.pos() - self._debug['last_update_d']['start'] = self._io.pos() - self.last_update_d = self._io.read_u1() - self._debug['last_update_d']['end'] = self._io.pos() - self._debug['num_records']['start'] = self._io.pos() - self.num_records = self._io.read_u4le() - self._debug['num_records']['end'] = self._io.pos() - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u2le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['len_record']['start'] = self._io.pos() - self.len_record = self._io.read_u2le() - self._debug['len_record']['end'] = self._io.pos() - - @property - def dbase_level(self): - if hasattr(self, '_m_dbase_level'): - return self._m_dbase_level if hasattr(self, '_m_dbase_level') else None - - self._m_dbase_level = (self.version & 7) - return self._m_dbase_level if hasattr(self, '_m_dbase_level') else None - - - class HeaderDbase3(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "reserved2", "reserved3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(3) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(13) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_bytes(4) - self._debug['reserved3']['end'] = self._io.pos() - - - class HeaderDbase7(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "has_incomplete_transaction", "dbase_iv_encryption", "reserved2", "production_mdx", "language_driver_id", "reserved3", "language_driver_name", "reserved4"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['reserved1']['end'] = self._io.pos() - self._debug['has_incomplete_transaction']['start'] = self._io.pos() - self.has_incomplete_transaction = self._io.read_u1() - self._debug['has_incomplete_transaction']['end'] = self._io.pos() - self._debug['dbase_iv_encryption']['start'] = self._io.pos() - self.dbase_iv_encryption = self._io.read_u1() - self._debug['dbase_iv_encryption']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(12) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['production_mdx']['start'] = self._io.pos() - self.production_mdx = self._io.read_u1() - self._debug['production_mdx']['end'] = self._io.pos() - self._debug['language_driver_id']['start'] = self._io.pos() - self.language_driver_id = self._io.read_u1() - self._debug['language_driver_id']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['reserved3']['end'] = self._io.pos() - self._debug['language_driver_name']['start'] = self._io.pos() - self.language_driver_name = self._io.read_bytes(32) - self._debug['language_driver_name']['end'] = self._io.pos() - self._debug['reserved4']['start'] = self._io.pos() - self.reserved4 = self._io.read_bytes(4) - self._debug['reserved4']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/dex.py b/python/examples/kaitai/dex.py deleted file mode 100644 index b90441bc..00000000 --- a/python/examples/kaitai/dex.py +++ /dev/null @@ -1,1083 +0,0 @@ -# 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 -import collections - - -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)) - -from .vlq_base128_le import VlqBase128Le -class Dex(KaitaiStruct): - """Android OS applications executables are typically stored in its own - format, optimized for more efficient execution in Dalvik virtual - machine. - - This format is loosely similar to Java .class file format and - generally holds the similar set of data: i.e. classes, methods, - fields, annotations, etc. - - .. seealso:: - Source - https://source.android.com/devices/tech/dalvik/dex-format - """ - - class ClassAccessFlags(Enum): - public = 1 - private = 2 - protected = 4 - static = 8 - final = 16 - interface = 512 - abstract = 1024 - synthetic = 4096 - annotation = 8192 - enum = 16384 - SEQ_FIELDS = ["header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.HeaderItem(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class HeaderItem(KaitaiStruct): - - class EndianConstant(Enum): - endian_constant = 305419896 - reverse_endian_constant = 2018915346 - SEQ_FIELDS = ["magic", "version_str", "checksum", "signature", "file_size", "header_size", "endian_tag", "link_size", "link_off", "map_off", "string_ids_size", "string_ids_off", "type_ids_size", "type_ids_off", "proto_ids_size", "proto_ids_off", "field_ids_size", "field_ids_off", "method_ids_size", "method_ids_off", "class_defs_size", "class_defs_off", "data_size", "data_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x64\x65\x78\x0A") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_str']['start'] = self._io.pos() - self.version_str = (KaitaiStream.bytes_terminate(self._io.read_bytes(4), 0, False)).decode(u"ascii") - self._debug['version_str']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u4le() - self._debug['checksum']['end'] = self._io.pos() - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.read_bytes(20) - self._debug['signature']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u4le() - self._debug['file_size']['end'] = self._io.pos() - 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['endian_tag']['start'] = self._io.pos() - self.endian_tag = KaitaiStream.resolve_enum(self._root.HeaderItem.EndianConstant, self._io.read_u4le()) - self._debug['endian_tag']['end'] = self._io.pos() - self._debug['link_size']['start'] = self._io.pos() - self.link_size = self._io.read_u4le() - self._debug['link_size']['end'] = self._io.pos() - self._debug['link_off']['start'] = self._io.pos() - self.link_off = self._io.read_u4le() - self._debug['link_off']['end'] = self._io.pos() - self._debug['map_off']['start'] = self._io.pos() - self.map_off = self._io.read_u4le() - self._debug['map_off']['end'] = self._io.pos() - self._debug['string_ids_size']['start'] = self._io.pos() - self.string_ids_size = self._io.read_u4le() - self._debug['string_ids_size']['end'] = self._io.pos() - self._debug['string_ids_off']['start'] = self._io.pos() - self.string_ids_off = self._io.read_u4le() - self._debug['string_ids_off']['end'] = self._io.pos() - self._debug['type_ids_size']['start'] = self._io.pos() - self.type_ids_size = self._io.read_u4le() - self._debug['type_ids_size']['end'] = self._io.pos() - self._debug['type_ids_off']['start'] = self._io.pos() - self.type_ids_off = self._io.read_u4le() - self._debug['type_ids_off']['end'] = self._io.pos() - self._debug['proto_ids_size']['start'] = self._io.pos() - self.proto_ids_size = self._io.read_u4le() - self._debug['proto_ids_size']['end'] = self._io.pos() - self._debug['proto_ids_off']['start'] = self._io.pos() - self.proto_ids_off = self._io.read_u4le() - self._debug['proto_ids_off']['end'] = self._io.pos() - self._debug['field_ids_size']['start'] = self._io.pos() - self.field_ids_size = self._io.read_u4le() - self._debug['field_ids_size']['end'] = self._io.pos() - self._debug['field_ids_off']['start'] = self._io.pos() - self.field_ids_off = self._io.read_u4le() - self._debug['field_ids_off']['end'] = self._io.pos() - self._debug['method_ids_size']['start'] = self._io.pos() - self.method_ids_size = self._io.read_u4le() - self._debug['method_ids_size']['end'] = self._io.pos() - self._debug['method_ids_off']['start'] = self._io.pos() - self.method_ids_off = self._io.read_u4le() - self._debug['method_ids_off']['end'] = self._io.pos() - self._debug['class_defs_size']['start'] = self._io.pos() - self.class_defs_size = self._io.read_u4le() - self._debug['class_defs_size']['end'] = self._io.pos() - self._debug['class_defs_off']['start'] = self._io.pos() - self.class_defs_off = self._io.read_u4le() - self._debug['class_defs_off']['end'] = self._io.pos() - self._debug['data_size']['start'] = self._io.pos() - self.data_size = self._io.read_u4le() - self._debug['data_size']['end'] = self._io.pos() - self._debug['data_off']['start'] = self._io.pos() - self.data_off = self._io.read_u4le() - self._debug['data_off']['end'] = self._io.pos() - - - class MapList(KaitaiStruct): - SEQ_FIELDS = ["size", "list"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - self._debug['list']['start'] = self._io.pos() - self.list = [None] * (self.size) - for i in range(self.size): - if not 'arr' in self._debug['list']: - self._debug['list']['arr'] = [] - self._debug['list']['arr'].append({'start': self._io.pos()}) - _t_list = self._root.MapItem(self._io, self, self._root) - _t_list._read() - self.list[i] = _t_list - self._debug['list']['arr'][i]['end'] = self._io.pos() - - self._debug['list']['end'] = self._io.pos() - - - class EncodedValue(KaitaiStruct): - - class ValueTypeEnum(Enum): - byte = 0 - short = 2 - char = 3 - int = 4 - long = 6 - float = 16 - double = 17 - method_type = 21 - method_handle = 22 - string = 23 - type = 24 - field = 25 - method = 26 - enum = 27 - array = 28 - annotation = 29 - null = 30 - boolean = 31 - SEQ_FIELDS = ["value_arg", "value_type", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value_arg']['start'] = self._io.pos() - self.value_arg = self._io.read_bits_int(3) - self._debug['value_arg']['end'] = self._io.pos() - self._debug['value_type']['start'] = self._io.pos() - self.value_type = KaitaiStream.resolve_enum(self._root.EncodedValue.ValueTypeEnum, self._io.read_bits_int(5)) - self._debug['value_type']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['value']['start'] = self._io.pos() - _on = self.value_type - if _on == self._root.EncodedValue.ValueTypeEnum.int: - self.value = self._io.read_s4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.annotation: - self.value = self._root.EncodedAnnotation(self._io, self, self._root) - self.value._read() - elif _on == self._root.EncodedValue.ValueTypeEnum.long: - self.value = self._io.read_s8le() - elif _on == self._root.EncodedValue.ValueTypeEnum.method_handle: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.byte: - self.value = self._io.read_s1() - elif _on == self._root.EncodedValue.ValueTypeEnum.array: - self.value = self._root.EncodedArray(self._io, self, self._root) - self.value._read() - elif _on == self._root.EncodedValue.ValueTypeEnum.method_type: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.short: - self.value = self._io.read_s2le() - elif _on == self._root.EncodedValue.ValueTypeEnum.method: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.double: - self.value = self._io.read_f8le() - elif _on == self._root.EncodedValue.ValueTypeEnum.float: - self.value = self._io.read_f4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.type: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.enum: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.field: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.string: - self.value = self._io.read_u4le() - elif _on == self._root.EncodedValue.ValueTypeEnum.char: - self.value = self._io.read_u2le() - self._debug['value']['end'] = self._io.pos() - - - class CallSiteIdItem(KaitaiStruct): - SEQ_FIELDS = ["call_site_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['call_site_off']['start'] = self._io.pos() - self.call_site_off = self._io.read_u4le() - self._debug['call_site_off']['end'] = self._io.pos() - - - class MethodIdItem(KaitaiStruct): - SEQ_FIELDS = ["class_idx", "proto_idx", "name_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_idx']['start'] = self._io.pos() - self.class_idx = self._io.read_u2le() - self._debug['class_idx']['end'] = self._io.pos() - self._debug['proto_idx']['start'] = self._io.pos() - self.proto_idx = self._io.read_u2le() - self._debug['proto_idx']['end'] = self._io.pos() - self._debug['name_idx']['start'] = self._io.pos() - self.name_idx = self._io.read_u4le() - self._debug['name_idx']['end'] = self._io.pos() - - @property - def class_name(self): - """the definer of this method.""" - if hasattr(self, '_m_class_name'): - return self._m_class_name if hasattr(self, '_m_class_name') else None - - self._m_class_name = self._root.type_ids[self.class_idx].type_name - return self._m_class_name if hasattr(self, '_m_class_name') else None - - @property - def proto_desc(self): - """the short-form descriptor of the prototype of this method.""" - if hasattr(self, '_m_proto_desc'): - return self._m_proto_desc if hasattr(self, '_m_proto_desc') else None - - self._m_proto_desc = self._root.proto_ids[self.proto_idx].shorty_desc - return self._m_proto_desc if hasattr(self, '_m_proto_desc') else None - - @property - def method_name(self): - """the name of this method.""" - if hasattr(self, '_m_method_name'): - return self._m_method_name if hasattr(self, '_m_method_name') else None - - self._m_method_name = self._root.string_ids[self.name_idx].value.data - return self._m_method_name if hasattr(self, '_m_method_name') else None - - - class TypeItem(KaitaiStruct): - SEQ_FIELDS = ["type_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type_idx']['start'] = self._io.pos() - self.type_idx = self._io.read_u2le() - self._debug['type_idx']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = self._root.type_ids[self.type_idx].type_name - return self._m_value if hasattr(self, '_m_value') else None - - - class TypeIdItem(KaitaiStruct): - SEQ_FIELDS = ["descriptor_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['descriptor_idx']['start'] = self._io.pos() - self.descriptor_idx = self._io.read_u4le() - self._debug['descriptor_idx']['end'] = self._io.pos() - - @property - def type_name(self): - if hasattr(self, '_m_type_name'): - return self._m_type_name if hasattr(self, '_m_type_name') else None - - self._m_type_name = self._root.string_ids[self.descriptor_idx].value.data - return self._m_type_name if hasattr(self, '_m_type_name') else None - - - class AnnotationElement(KaitaiStruct): - SEQ_FIELDS = ["name_idx", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_idx']['start'] = self._io.pos() - self.name_idx = VlqBase128Le(self._io) - self.name_idx._read() - self._debug['name_idx']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._root.EncodedValue(self._io, self, self._root) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - - class EncodedField(KaitaiStruct): - SEQ_FIELDS = ["field_idx_diff", "access_flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['field_idx_diff']['start'] = self._io.pos() - self.field_idx_diff = VlqBase128Le(self._io) - self.field_idx_diff._read() - self._debug['field_idx_diff']['end'] = self._io.pos() - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = VlqBase128Le(self._io) - self.access_flags._read() - self._debug['access_flags']['end'] = self._io.pos() - - - class EncodedArrayItem(KaitaiStruct): - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._root.EncodedArray(self._io, self, self._root) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - - class ClassDataItem(KaitaiStruct): - SEQ_FIELDS = ["static_fields_size", "instance_fields_size", "direct_methods_size", "virtual_methods_size", "static_fields", "instance_fields", "direct_methods", "virtual_methods"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['static_fields_size']['start'] = self._io.pos() - self.static_fields_size = VlqBase128Le(self._io) - self.static_fields_size._read() - self._debug['static_fields_size']['end'] = self._io.pos() - self._debug['instance_fields_size']['start'] = self._io.pos() - self.instance_fields_size = VlqBase128Le(self._io) - self.instance_fields_size._read() - self._debug['instance_fields_size']['end'] = self._io.pos() - self._debug['direct_methods_size']['start'] = self._io.pos() - self.direct_methods_size = VlqBase128Le(self._io) - self.direct_methods_size._read() - self._debug['direct_methods_size']['end'] = self._io.pos() - self._debug['virtual_methods_size']['start'] = self._io.pos() - self.virtual_methods_size = VlqBase128Le(self._io) - self.virtual_methods_size._read() - self._debug['virtual_methods_size']['end'] = self._io.pos() - self._debug['static_fields']['start'] = self._io.pos() - self.static_fields = [None] * (self.static_fields_size.value) - for i in range(self.static_fields_size.value): - if not 'arr' in self._debug['static_fields']: - self._debug['static_fields']['arr'] = [] - self._debug['static_fields']['arr'].append({'start': self._io.pos()}) - _t_static_fields = self._root.EncodedField(self._io, self, self._root) - _t_static_fields._read() - self.static_fields[i] = _t_static_fields - self._debug['static_fields']['arr'][i]['end'] = self._io.pos() - - self._debug['static_fields']['end'] = self._io.pos() - self._debug['instance_fields']['start'] = self._io.pos() - self.instance_fields = [None] * (self.instance_fields_size.value) - for i in range(self.instance_fields_size.value): - if not 'arr' in self._debug['instance_fields']: - self._debug['instance_fields']['arr'] = [] - self._debug['instance_fields']['arr'].append({'start': self._io.pos()}) - _t_instance_fields = self._root.EncodedField(self._io, self, self._root) - _t_instance_fields._read() - self.instance_fields[i] = _t_instance_fields - self._debug['instance_fields']['arr'][i]['end'] = self._io.pos() - - self._debug['instance_fields']['end'] = self._io.pos() - self._debug['direct_methods']['start'] = self._io.pos() - self.direct_methods = [None] * (self.direct_methods_size.value) - for i in range(self.direct_methods_size.value): - if not 'arr' in self._debug['direct_methods']: - self._debug['direct_methods']['arr'] = [] - self._debug['direct_methods']['arr'].append({'start': self._io.pos()}) - _t_direct_methods = self._root.EncodedMethod(self._io, self, self._root) - _t_direct_methods._read() - self.direct_methods[i] = _t_direct_methods - self._debug['direct_methods']['arr'][i]['end'] = self._io.pos() - - self._debug['direct_methods']['end'] = self._io.pos() - self._debug['virtual_methods']['start'] = self._io.pos() - self.virtual_methods = [None] * (self.virtual_methods_size.value) - for i in range(self.virtual_methods_size.value): - if not 'arr' in self._debug['virtual_methods']: - self._debug['virtual_methods']['arr'] = [] - self._debug['virtual_methods']['arr'].append({'start': self._io.pos()}) - _t_virtual_methods = self._root.EncodedMethod(self._io, self, self._root) - _t_virtual_methods._read() - self.virtual_methods[i] = _t_virtual_methods - self._debug['virtual_methods']['arr'][i]['end'] = self._io.pos() - - self._debug['virtual_methods']['end'] = self._io.pos() - - - class FieldIdItem(KaitaiStruct): - SEQ_FIELDS = ["class_idx", "type_idx", "name_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_idx']['start'] = self._io.pos() - self.class_idx = self._io.read_u2le() - self._debug['class_idx']['end'] = self._io.pos() - self._debug['type_idx']['start'] = self._io.pos() - self.type_idx = self._io.read_u2le() - self._debug['type_idx']['end'] = self._io.pos() - self._debug['name_idx']['start'] = self._io.pos() - self.name_idx = self._io.read_u4le() - self._debug['name_idx']['end'] = self._io.pos() - - @property - def class_name(self): - """the definer of this field.""" - if hasattr(self, '_m_class_name'): - return self._m_class_name if hasattr(self, '_m_class_name') else None - - self._m_class_name = self._root.type_ids[self.class_idx].type_name - return self._m_class_name if hasattr(self, '_m_class_name') else None - - @property - def type_name(self): - """the type of this field.""" - if hasattr(self, '_m_type_name'): - return self._m_type_name if hasattr(self, '_m_type_name') else None - - self._m_type_name = self._root.type_ids[self.type_idx].type_name - return self._m_type_name if hasattr(self, '_m_type_name') else None - - @property - def field_name(self): - """the name of this field.""" - if hasattr(self, '_m_field_name'): - return self._m_field_name if hasattr(self, '_m_field_name') else None - - self._m_field_name = self._root.string_ids[self.name_idx].value.data - return self._m_field_name if hasattr(self, '_m_field_name') else None - - - class EncodedAnnotation(KaitaiStruct): - SEQ_FIELDS = ["type_idx", "size", "elements"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type_idx']['start'] = self._io.pos() - self.type_idx = VlqBase128Le(self._io) - self.type_idx._read() - self._debug['type_idx']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = VlqBase128Le(self._io) - self.size._read() - self._debug['size']['end'] = self._io.pos() - self._debug['elements']['start'] = self._io.pos() - self.elements = [None] * (self.size.value) - for i in range(self.size.value): - if not 'arr' in self._debug['elements']: - self._debug['elements']['arr'] = [] - self._debug['elements']['arr'].append({'start': self._io.pos()}) - _t_elements = self._root.AnnotationElement(self._io, self, self._root) - _t_elements._read() - self.elements[i] = _t_elements - self._debug['elements']['arr'][i]['end'] = self._io.pos() - - self._debug['elements']['end'] = self._io.pos() - - - class ClassDefItem(KaitaiStruct): - SEQ_FIELDS = ["class_idx", "access_flags", "superclass_idx", "interfaces_off", "source_file_idx", "annotations_off", "class_data_off", "static_values_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_idx']['start'] = self._io.pos() - self.class_idx = self._io.read_u4le() - self._debug['class_idx']['end'] = self._io.pos() - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = KaitaiStream.resolve_enum(self._root.ClassAccessFlags, self._io.read_u4le()) - self._debug['access_flags']['end'] = self._io.pos() - self._debug['superclass_idx']['start'] = self._io.pos() - self.superclass_idx = self._io.read_u4le() - self._debug['superclass_idx']['end'] = self._io.pos() - self._debug['interfaces_off']['start'] = self._io.pos() - self.interfaces_off = self._io.read_u4le() - self._debug['interfaces_off']['end'] = self._io.pos() - self._debug['source_file_idx']['start'] = self._io.pos() - self.source_file_idx = self._io.read_u4le() - self._debug['source_file_idx']['end'] = self._io.pos() - self._debug['annotations_off']['start'] = self._io.pos() - self.annotations_off = self._io.read_u4le() - self._debug['annotations_off']['end'] = self._io.pos() - self._debug['class_data_off']['start'] = self._io.pos() - self.class_data_off = self._io.read_u4le() - self._debug['class_data_off']['end'] = self._io.pos() - self._debug['static_values_off']['start'] = self._io.pos() - self.static_values_off = self._io.read_u4le() - self._debug['static_values_off']['end'] = self._io.pos() - - @property - def type_name(self): - if hasattr(self, '_m_type_name'): - return self._m_type_name if hasattr(self, '_m_type_name') else None - - self._m_type_name = self._root.type_ids[self.class_idx].type_name - return self._m_type_name if hasattr(self, '_m_type_name') else None - - @property - def class_data(self): - if hasattr(self, '_m_class_data'): - return self._m_class_data if hasattr(self, '_m_class_data') else None - - if self.class_data_off != 0: - _pos = self._io.pos() - self._io.seek(self.class_data_off) - self._debug['_m_class_data']['start'] = self._io.pos() - self._m_class_data = self._root.ClassDataItem(self._io, self, self._root) - self._m_class_data._read() - self._debug['_m_class_data']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_class_data if hasattr(self, '_m_class_data') else None - - @property - def static_values(self): - if hasattr(self, '_m_static_values'): - return self._m_static_values if hasattr(self, '_m_static_values') else None - - if self.static_values_off != 0: - _pos = self._io.pos() - self._io.seek(self.static_values_off) - self._debug['_m_static_values']['start'] = self._io.pos() - self._m_static_values = self._root.EncodedArrayItem(self._io, self, self._root) - self._m_static_values._read() - self._debug['_m_static_values']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_static_values if hasattr(self, '_m_static_values') else None - - - class TypeList(KaitaiStruct): - SEQ_FIELDS = ["size", "list"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - self._debug['list']['start'] = self._io.pos() - self.list = [None] * (self.size) - for i in range(self.size): - if not 'arr' in self._debug['list']: - self._debug['list']['arr'] = [] - self._debug['list']['arr'].append({'start': self._io.pos()}) - _t_list = self._root.TypeItem(self._io, self, self._root) - _t_list._read() - self.list[i] = _t_list - self._debug['list']['arr'][i]['end'] = self._io.pos() - - self._debug['list']['end'] = self._io.pos() - - - class StringIdItem(KaitaiStruct): - SEQ_FIELDS = ["string_data_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['string_data_off']['start'] = self._io.pos() - self.string_data_off = self._io.read_u4le() - self._debug['string_data_off']['end'] = self._io.pos() - - class StringDataItem(KaitaiStruct): - SEQ_FIELDS = ["utf16_size", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['utf16_size']['start'] = self._io.pos() - self.utf16_size = VlqBase128Le(self._io) - self.utf16_size._read() - self._debug['utf16_size']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = (self._io.read_bytes(self.utf16_size.value)).decode(u"ascii") - self._debug['data']['end'] = self._io.pos() - - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - _pos = self._io.pos() - self._io.seek(self.string_data_off) - self._debug['_m_value']['start'] = self._io.pos() - self._m_value = self._root.StringIdItem.StringDataItem(self._io, self, self._root) - self._m_value._read() - self._debug['_m_value']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_value if hasattr(self, '_m_value') else None - - - class ProtoIdItem(KaitaiStruct): - SEQ_FIELDS = ["shorty_idx", "return_type_idx", "parameters_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['shorty_idx']['start'] = self._io.pos() - self.shorty_idx = self._io.read_u4le() - self._debug['shorty_idx']['end'] = self._io.pos() - self._debug['return_type_idx']['start'] = self._io.pos() - self.return_type_idx = self._io.read_u4le() - self._debug['return_type_idx']['end'] = self._io.pos() - self._debug['parameters_off']['start'] = self._io.pos() - self.parameters_off = self._io.read_u4le() - self._debug['parameters_off']['end'] = self._io.pos() - - @property - def shorty_desc(self): - """short-form descriptor string of this prototype, as pointed to by shorty_idx.""" - if hasattr(self, '_m_shorty_desc'): - return self._m_shorty_desc if hasattr(self, '_m_shorty_desc') else None - - self._m_shorty_desc = self._root.string_ids[self.shorty_idx].value.data - return self._m_shorty_desc if hasattr(self, '_m_shorty_desc') else None - - @property - def params_types(self): - """list of parameter types for this prototype.""" - if hasattr(self, '_m_params_types'): - return self._m_params_types if hasattr(self, '_m_params_types') else None - - if self.parameters_off != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.parameters_off) - self._debug['_m_params_types']['start'] = io.pos() - self._m_params_types = self._root.TypeList(io, self, self._root) - self._m_params_types._read() - self._debug['_m_params_types']['end'] = io.pos() - io.seek(_pos) - - return self._m_params_types if hasattr(self, '_m_params_types') else None - - @property - def return_type(self): - """return type of this prototype.""" - if hasattr(self, '_m_return_type'): - return self._m_return_type if hasattr(self, '_m_return_type') else None - - self._m_return_type = self._root.type_ids[self.return_type_idx].type_name - return self._m_return_type if hasattr(self, '_m_return_type') else None - - - class EncodedMethod(KaitaiStruct): - SEQ_FIELDS = ["method_idx_diff", "access_flags", "code_off"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['method_idx_diff']['start'] = self._io.pos() - self.method_idx_diff = VlqBase128Le(self._io) - self.method_idx_diff._read() - self._debug['method_idx_diff']['end'] = self._io.pos() - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = VlqBase128Le(self._io) - self.access_flags._read() - self._debug['access_flags']['end'] = self._io.pos() - self._debug['code_off']['start'] = self._io.pos() - self.code_off = VlqBase128Le(self._io) - self.code_off._read() - self._debug['code_off']['end'] = self._io.pos() - - - class MapItem(KaitaiStruct): - - class MapItemType(Enum): - header_item = 0 - string_id_item = 1 - type_id_item = 2 - proto_id_item = 3 - field_id_item = 4 - method_id_item = 5 - class_def_item = 6 - call_site_id_item = 7 - method_handle_item = 8 - map_list = 4096 - type_list = 4097 - annotation_set_ref_list = 4098 - annotation_set_item = 4099 - class_data_item = 8192 - code_item = 8193 - string_data_item = 8194 - debug_info_item = 8195 - annotation_item = 8196 - encoded_array_item = 8197 - annotations_directory_item = 8198 - SEQ_FIELDS = ["type", "unused", "size", "offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.MapItem.MapItemType, self._io.read_u2le()) - self._debug['type']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_u2le() - self._debug['unused']['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['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['end'] = self._io.pos() - - - class EncodedArray(KaitaiStruct): - SEQ_FIELDS = ["size", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = VlqBase128Le(self._io) - self.size._read() - self._debug['size']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [None] * (self.size.value) - for i in range(self.size.value): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - _t_values = self._root.EncodedValue(self._io, self, self._root) - _t_values._read() - self.values[i] = _t_values - self._debug['values']['arr'][i]['end'] = self._io.pos() - - self._debug['values']['end'] = self._io.pos() - - - @property - def string_ids(self): - """string identifiers list. - - These are identifiers for all the strings used by this file, either for - internal naming (e.g., type descriptors) or as constant objects referred to by code. - - This list must be sorted by string contents, using UTF-16 code point values - (not in a locale-sensitive manner), and it must not contain any duplicate entries. - """ - if hasattr(self, '_m_string_ids'): - return self._m_string_ids if hasattr(self, '_m_string_ids') else None - - _pos = self._io.pos() - self._io.seek(self.header.string_ids_off) - self._debug['_m_string_ids']['start'] = self._io.pos() - self._m_string_ids = [None] * (self.header.string_ids_size) - for i in range(self.header.string_ids_size): - if not 'arr' in self._debug['_m_string_ids']: - self._debug['_m_string_ids']['arr'] = [] - self._debug['_m_string_ids']['arr'].append({'start': self._io.pos()}) - _t__m_string_ids = self._root.StringIdItem(self._io, self, self._root) - _t__m_string_ids._read() - self._m_string_ids[i] = _t__m_string_ids - self._debug['_m_string_ids']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_string_ids']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_string_ids if hasattr(self, '_m_string_ids') else None - - @property - def method_ids(self): - """method identifiers list. - - These are identifiers for all methods referred to by this file, - whether defined in the file or not. - - This list must be sorted, where the defining type (by type_id index - is the major order, method name (by string_id index) is the intermediate - order, and method prototype (by proto_id index) is the minor order. - - The list must not contain any duplicate entries. - """ - if hasattr(self, '_m_method_ids'): - return self._m_method_ids if hasattr(self, '_m_method_ids') else None - - _pos = self._io.pos() - self._io.seek(self.header.method_ids_off) - self._debug['_m_method_ids']['start'] = self._io.pos() - self._m_method_ids = [None] * (self.header.method_ids_size) - for i in range(self.header.method_ids_size): - if not 'arr' in self._debug['_m_method_ids']: - self._debug['_m_method_ids']['arr'] = [] - self._debug['_m_method_ids']['arr'].append({'start': self._io.pos()}) - _t__m_method_ids = self._root.MethodIdItem(self._io, self, self._root) - _t__m_method_ids._read() - self._m_method_ids[i] = _t__m_method_ids - self._debug['_m_method_ids']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_method_ids']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_method_ids if hasattr(self, '_m_method_ids') else None - - @property - def link_data(self): - """data used in statically linked files. - - The format of the data in this section is left unspecified by this document. - - This section is empty in unlinked files, and runtime implementations may - use it as they see fit. - """ - if hasattr(self, '_m_link_data'): - return self._m_link_data if hasattr(self, '_m_link_data') else None - - _pos = self._io.pos() - self._io.seek(self.header.link_off) - self._debug['_m_link_data']['start'] = self._io.pos() - self._m_link_data = self._io.read_bytes(self.header.link_size) - self._debug['_m_link_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_link_data if hasattr(self, '_m_link_data') else None - - @property - def map(self): - if hasattr(self, '_m_map'): - return self._m_map if hasattr(self, '_m_map') else None - - _pos = self._io.pos() - self._io.seek(self.header.map_off) - self._debug['_m_map']['start'] = self._io.pos() - self._m_map = self._root.MapList(self._io, self, self._root) - self._m_map._read() - self._debug['_m_map']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_map if hasattr(self, '_m_map') else None - - @property - def class_defs(self): - """class definitions list. - - The classes must be ordered such that a given class's superclass and - implemented interfaces appear in the list earlier than the referring class. - - Furthermore, it is invalid for a definition for the same-named class to - appear more than once in the list. - """ - if hasattr(self, '_m_class_defs'): - return self._m_class_defs if hasattr(self, '_m_class_defs') else None - - _pos = self._io.pos() - self._io.seek(self.header.class_defs_off) - self._debug['_m_class_defs']['start'] = self._io.pos() - self._m_class_defs = [None] * (self.header.class_defs_size) - for i in range(self.header.class_defs_size): - if not 'arr' in self._debug['_m_class_defs']: - self._debug['_m_class_defs']['arr'] = [] - self._debug['_m_class_defs']['arr'].append({'start': self._io.pos()}) - _t__m_class_defs = self._root.ClassDefItem(self._io, self, self._root) - _t__m_class_defs._read() - self._m_class_defs[i] = _t__m_class_defs - self._debug['_m_class_defs']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_class_defs']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_class_defs if hasattr(self, '_m_class_defs') else None - - @property - def data(self): - """data area, containing all the support data for the tables listed above. - - Different items have different alignment requirements, and padding bytes - are inserted before each item if necessary to achieve proper alignment. - """ - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - _pos = self._io.pos() - self._io.seek(self.header.data_off) - self._debug['_m_data']['start'] = self._io.pos() - self._m_data = self._io.read_bytes(self.header.data_size) - self._debug['_m_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - @property - def type_ids(self): - """type identifiers list. - - These are identifiers for all types (classes, arrays, or primitive types) - referred to by this file, whether defined in the file or not. - - This list must be sorted by string_id index, and it must not contain any duplicate entries. - """ - if hasattr(self, '_m_type_ids'): - return self._m_type_ids if hasattr(self, '_m_type_ids') else None - - _pos = self._io.pos() - self._io.seek(self.header.type_ids_off) - self._debug['_m_type_ids']['start'] = self._io.pos() - self._m_type_ids = [None] * (self.header.type_ids_size) - for i in range(self.header.type_ids_size): - if not 'arr' in self._debug['_m_type_ids']: - self._debug['_m_type_ids']['arr'] = [] - self._debug['_m_type_ids']['arr'].append({'start': self._io.pos()}) - _t__m_type_ids = self._root.TypeIdItem(self._io, self, self._root) - _t__m_type_ids._read() - self._m_type_ids[i] = _t__m_type_ids - self._debug['_m_type_ids']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_type_ids']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_type_ids if hasattr(self, '_m_type_ids') else None - - @property - def proto_ids(self): - """method prototype identifiers list. - - These are identifiers for all prototypes referred to by this file. - - This list must be sorted in return-type (by type_id index) major order, - and then by argument list (lexicographic ordering, individual arguments - ordered by type_id index). The list must not contain any duplicate entries. - """ - if hasattr(self, '_m_proto_ids'): - return self._m_proto_ids if hasattr(self, '_m_proto_ids') else None - - _pos = self._io.pos() - self._io.seek(self.header.proto_ids_off) - self._debug['_m_proto_ids']['start'] = self._io.pos() - self._m_proto_ids = [None] * (self.header.proto_ids_size) - for i in range(self.header.proto_ids_size): - if not 'arr' in self._debug['_m_proto_ids']: - self._debug['_m_proto_ids']['arr'] = [] - self._debug['_m_proto_ids']['arr'].append({'start': self._io.pos()}) - _t__m_proto_ids = self._root.ProtoIdItem(self._io, self, self._root) - _t__m_proto_ids._read() - self._m_proto_ids[i] = _t__m_proto_ids - self._debug['_m_proto_ids']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_proto_ids']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_proto_ids if hasattr(self, '_m_proto_ids') else None - - @property - def field_ids(self): - """field identifiers list. - - These are identifiers for all fields referred to by this file, whether defined in the file or not. - - This list must be sorted, where the defining type (by type_id index) - is the major order, field name (by string_id index) is the intermediate - order, and type (by type_id index) is the minor order. - - The list must not contain any duplicate entries. - """ - if hasattr(self, '_m_field_ids'): - return self._m_field_ids if hasattr(self, '_m_field_ids') else None - - _pos = self._io.pos() - self._io.seek(self.header.field_ids_off) - self._debug['_m_field_ids']['start'] = self._io.pos() - self._m_field_ids = [None] * (self.header.field_ids_size) - for i in range(self.header.field_ids_size): - if not 'arr' in self._debug['_m_field_ids']: - self._debug['_m_field_ids']['arr'] = [] - self._debug['_m_field_ids']['arr'].append({'start': self._io.pos()}) - _t__m_field_ids = self._root.FieldIdItem(self._io, self, self._root) - _t__m_field_ids._read() - self._m_field_ids[i] = _t__m_field_ids - self._debug['_m_field_ids']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_field_ids']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_field_ids if hasattr(self, '_m_field_ids') else None - - diff --git a/python/examples/kaitai/dicom.py b/python/examples/kaitai/dicom.py deleted file mode 100644 index 4aa2d592..00000000 --- a/python/examples/kaitai/dicom.py +++ /dev/null @@ -1,4365 +0,0 @@ -# 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 -import collections - - -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 Dicom(KaitaiStruct): - """DICOM (Digital Imaging and Communications in Medicine), AKA NEMA - PS3, AKA ISO 12052:2006, is a file format and network protocol - standard for medical imaging purposes. This parser covers file - format, typically written by various medical equipment, such as - radiography, computer tomography scans, MRT, ultrasonography, etc. - - DICOM defines two transfer syntaxes: implicit and explicit. This - top-level parser attempts to autodetect and handle both of them. If - any problems arise, one can use `file_explicit` and `file_implicit` - subtypes to force parsing in particular transfer syntax. - - .. seealso:: - Source - http://dicom.nema.org/medical/dicom/current/output/html/part10.html#chapter_7 - """ - - class Tags(Enum): - file_meta_information_group_length = 131072 - file_meta_information_version = 131073 - media_storage_sop_class_uid = 131074 - media_storage_sop_instance_uid = 131075 - transfer_syntax_uid = 131088 - implementation_class_uid = 131090 - implementation_version_name = 131091 - source_application_entity_title = 131094 - sending_application_entity_title = 131095 - receiving_application_entity_title = 131096 - private_information_creator_uid = 131328 - private_information = 131330 - file_set_id = 266544 - file_set_descriptor_file_id = 266561 - specific_character_set_of_file_set_descriptor_file = 266562 - offset_of_the_first_directory_record_of_the_root_directory_entity = 266752 - offset_of_the_last_directory_record_of_the_root_directory_entity = 266754 - file_set_consistency_flag = 266770 - directory_record_sequence = 266784 - offset_of_the_next_directory_record = 267264 - record_in_use_flag = 267280 - offset_of_referenced_lower_level_directory_entity = 267296 - directory_record_type = 267312 - private_record_uid = 267314 - referenced_file_id = 267520 - mrdr_directory_record_offset = 267524 - referenced_sop_class_uid_in_file = 267536 - referenced_sop_instance_uid_in_file = 267537 - referenced_transfer_syntax_uid_in_file = 267538 - referenced_related_general_sop_class_uid_in_file = 267546 - number_of_references = 267776 - length_to_end = 524289 - specific_character_set = 524293 - language_code_sequence = 524294 - image_type = 524296 - recognition_code = 524304 - instance_creation_date = 524306 - instance_creation_time = 524307 - instance_creator_uid = 524308 - instance_coercion_datetime = 524309 - sop_class_uid = 524310 - sop_instance_uid = 524312 - related_general_sop_class_uid = 524314 - original_specialized_sop_class_uid = 524315 - study_date = 524320 - series_date = 524321 - acquisition_date = 524322 - content_date = 524323 - overlay_date = 524324 - curve_date = 524325 - acquisition_datetime = 524330 - study_time = 524336 - series_time = 524337 - acquisition_time = 524338 - content_time = 524339 - overlay_time = 524340 - curve_time = 524341 - data_set_type = 524352 - data_set_subtype = 524353 - nuclear_medicine_series_type = 524354 - accession_number = 524368 - issuer_of_accession_number_sequence = 524369 - query_retrieve_level = 524370 - query_retrieve_view = 524371 - retrieve_ae_title = 524372 - station_ae_title = 524373 - instance_availability = 524374 - failed_sop_instance_uid_list = 524376 - modality = 524384 - modalities_in_study = 524385 - sop_classes_in_study = 524386 - conversion_type = 524388 - presentation_intent_type = 524392 - manufacturer = 524400 - institution_name = 524416 - institution_address = 524417 - institution_code_sequence = 524418 - referring_physician_s_name = 524432 - referring_physician_s_address = 524434 - referring_physician_s_telephone_numbers = 524436 - referring_physician_identification_sequence = 524438 - consulting_physician_s_name = 524444 - consulting_physician_identification_sequence = 524445 - code_value = 524544 - extended_code_value = 524545 - coding_scheme_designator = 524546 - coding_scheme_version = 524547 - code_meaning = 524548 - mapping_resource = 524549 - context_group_version = 524550 - context_group_local_version = 524551 - extended_code_meaning = 524552 - context_group_extension_flag = 524555 - coding_scheme_uid = 524556 - context_group_extension_creator_uid = 524557 - context_identifier = 524559 - coding_scheme_identification_sequence = 524560 - coding_scheme_registry = 524562 - coding_scheme_external_id = 524564 - coding_scheme_name = 524565 - coding_scheme_responsible_organization = 524566 - context_uid = 524567 - mapping_resource_uid = 524568 - long_code_value = 524569 - urn_code_value = 524576 - equivalent_code_sequence = 524577 - mapping_resource_name = 524578 - context_group_identification_sequence = 524579 - mapping_resource_identification_sequence = 524580 - timezone_offset_from_utc = 524801 - private_data_element_characteristics_sequence = 525056 - private_group_reference = 525057 - private_creator_reference = 525058 - block_identifying_information_status = 525059 - nonidentifying_private_elements = 525060 - deidentification_action_sequence = 525061 - identifying_private_elements = 525062 - deidentification_action = 525063 - network_id = 528384 - station_name = 528400 - study_description = 528432 - procedure_code_sequence = 528434 - series_description = 528446 - series_description_code_sequence = 528447 - institutional_department_name = 528448 - physician_s__of_record = 528456 - physician_s__of_record_identification_sequence = 528457 - performing_physician_s_name = 528464 - performing_physician_identification_sequence = 528466 - name_of_physician_s__reading_study = 528480 - physician_s__reading_study_identification_sequence = 528482 - operators__name = 528496 - operator_identification_sequence = 528498 - admitting_diagnoses_description = 528512 - admitting_diagnoses_code_sequence = 528516 - manufacturer_s_model_name = 528528 - referenced_results_sequence = 528640 - referenced_study_sequence = 528656 - referenced_performed_procedure_step_sequence = 528657 - referenced_series_sequence = 528661 - referenced_patient_sequence = 528672 - referenced_visit_sequence = 528677 - referenced_overlay_sequence = 528688 - referenced_stereometric_instance_sequence = 528692 - referenced_waveform_sequence = 528698 - referenced_image_sequence = 528704 - referenced_curve_sequence = 528709 - referenced_instance_sequence = 528714 - referenced_real_world_value_mapping_instance_sequence = 528715 - referenced_sop_class_uid = 528720 - referenced_sop_instance_uid = 528725 - sop_classes_supported = 528730 - referenced_frame_number = 528736 - simple_frame_list = 528737 - calculated_frame_list = 528738 - time_range = 528739 - frame_extraction_sequence = 528740 - multi_frame_source_sop_instance_uid = 528743 - retrieve_url = 528784 - transaction_uid = 528789 - warning_reason = 528790 - failure_reason = 528791 - failed_sop_sequence = 528792 - referenced_sop_sequence = 528793 - other_failures_sequence = 528794 - studies_containing_other_referenced_instances_sequence = 528896 - related_series_sequence = 528976 - lossy_image_compression = 532752 - derivation_description = 532753 - source_image_sequence = 532754 - stage_name = 532768 - stage_number = 532770 - number_of_stages = 532772 - view_name = 532775 - view_number = 532776 - number_of_event_timers = 532777 - number_of_views_in_stage = 532778 - event_elapsed_time_s_ = 532784 - event_timer_name_s_ = 532786 - event_timer_sequence = 532787 - event_time_offset = 532788 - event_code_sequence = 532789 - start_trim = 532802 - stop_trim = 532803 - recommended_display_frame_rate = 532804 - transducer_position = 532992 - transducer_orientation = 532996 - anatomic_structure = 533000 - anatomic_region_sequence = 533016 - anatomic_region_modifier_sequence = 533024 - primary_anatomic_structure_sequence = 533032 - anatomic_structure__space_or_region_sequence = 533033 - primary_anatomic_structure_modifier_sequence = 533040 - transducer_position_sequence = 533056 - transducer_position_modifier_sequence = 533058 - transducer_orientation_sequence = 533060 - transducer_orientation_modifier_sequence = 533062 - anatomic_structure_space_or_region_code_sequence__trial_ = 533073 - anatomic_portal_of_entrance_code_sequence__trial_ = 533075 - anatomic_approach_direction_code_sequence__trial_ = 533077 - anatomic_perspective_description__trial_ = 533078 - anatomic_perspective_code_sequence__trial_ = 533079 - anatomic_location_of_examining_instrument_description__trial_ = 533080 - anatomic_location_of_examining_instrument_code_sequence__trial_ = 533081 - anatomic_structure_space_or_region_modifier_code_sequence__trial_ = 533082 - on_axis_background_anatomic_structure_code_sequence__trial_ = 533084 - alternate_representation_sequence = 536577 - irradiation_event_uid = 536592 - source_irradiation_event_sequence = 536593 - radiopharmaceutical_administration_event_uid = 536594 - identifying_comments = 540672 - frame_type = 561159 - referenced_image_evidence_sequence = 561298 - referenced_raw_data_sequence = 561441 - creator_version_uid = 561443 - derivation_image_sequence = 561444 - source_image_evidence_sequence = 561492 - pixel_presentation = 561669 - volumetric_properties = 561670 - volume_based_calculation_technique = 561671 - complex_image_component = 561672 - acquisition_contrast = 561673 - derivation_code_sequence = 561685 - referenced_presentation_state_sequence = 561719 - referenced_other_plane_sequence = 562192 - frame_display_sequence = 562264 - recommended_display_frame_rate_in_float = 562265 - skip_frame_range_flag = 562272 - patient_s_name = 1048592 - patient_id = 1048608 - issuer_of_patient_id = 1048609 - type_of_patient_id = 1048610 - issuer_of_patient_id_qualifiers_sequence = 1048612 - source_patient_group_identification_sequence = 1048614 - group_of_patients_identification_sequence = 1048615 - subject_relative_position_in_image = 1048616 - patient_s_birth_date = 1048624 - patient_s_birth_time = 1048626 - patient_s_birth_date_in_alternative_calendar = 1048627 - patient_s_death_date_in_alternative_calendar = 1048628 - patient_s_alternative_calendar = 1048629 - patient_s_sex = 1048640 - patient_s_insurance_plan_code_sequence = 1048656 - patient_s_primary_language_code_sequence = 1048833 - patient_s_primary_language_modifier_code_sequence = 1048834 - quality_control_subject = 1049088 - quality_control_subject_type_code_sequence = 1049089 - strain_description = 1049106 - strain_nomenclature = 1049107 - strain_stock_number = 1049108 - strain_source_registry_code_sequence = 1049109 - strain_stock_sequence = 1049110 - strain_source = 1049111 - strain_additional_information = 1049112 - strain_code_sequence = 1049113 - other_patient_ids = 1052672 - other_patient_names = 1052673 - other_patient_ids_sequence = 1052674 - patient_s_birth_name = 1052677 - patient_s_age = 1052688 - patient_s_size = 1052704 - patient_s_size_code_sequence = 1052705 - patient_s_weight = 1052720 - patient_s_address = 1052736 - insurance_plan_identification = 1052752 - patient_s_mother_s_birth_name = 1052768 - military_rank = 1052800 - branch_of_service = 1052801 - medical_record_locator = 1052816 - referenced_patient_photo_sequence = 1052928 - medical_alerts = 1056768 - allergies = 1057040 - country_of_residence = 1057104 - region_of_residence = 1057106 - patient_s_telephone_numbers = 1057108 - patient_s_telecom_information = 1057109 - ethnic_group = 1057120 - occupation = 1057152 - smoking_status = 1057184 - additional_patient_history = 1057200 - pregnancy_status = 1057216 - last_menstrual_date = 1057232 - patient_s_religious_preference = 1057264 - patient_species_description = 1057281 - patient_species_code_sequence = 1057282 - patient_s_sex_neutered = 1057283 - anatomical_orientation_type = 1057296 - patient_breed_description = 1057426 - patient_breed_code_sequence = 1057427 - breed_registration_sequence = 1057428 - breed_registration_number = 1057429 - breed_registry_code_sequence = 1057430 - responsible_person = 1057431 - responsible_person_role = 1057432 - responsible_organization = 1057433 - patient_comments = 1064960 - examined_body_thickness = 1086513 - clinical_trial_sponsor_name = 1179664 - clinical_trial_protocol_id = 1179680 - clinical_trial_protocol_name = 1179681 - clinical_trial_site_id = 1179696 - clinical_trial_site_name = 1179697 - clinical_trial_subject_id = 1179712 - clinical_trial_subject_reading_id = 1179714 - clinical_trial_time_point_id = 1179728 - clinical_trial_time_point_description = 1179729 - clinical_trial_coordinating_center_name = 1179744 - patient_identity_removed = 1179746 - de_identification_method = 1179747 - de_identification_method_code_sequence = 1179748 - clinical_trial_series_id = 1179761 - clinical_trial_series_description = 1179762 - clinical_trial_protocol_ethics_committee_name = 1179777 - clinical_trial_protocol_ethics_committee_approval_number = 1179778 - consent_for_clinical_trial_use_sequence = 1179779 - distribution_type = 1179780 - consent_for_distribution_flag = 1179781 - cad_file_format = 1310755 - component_reference_system = 1310756 - component_manufacturing_procedure = 1310757 - component_manufacturer = 1310760 - material_thickness = 1310768 - material_pipe_diameter = 1310770 - material_isolation_diameter = 1310772 - material_grade = 1310786 - material_properties_description = 1310788 - material_properties_file_format__retired_ = 1310789 - material_notes = 1310790 - component_shape = 1310800 - curvature_type = 1310802 - outer_diameter = 1310804 - inner_diameter = 1310806 - component_welder_ids = 1310976 - secondary_approval_status = 1310977 - secondary_review_date = 1310978 - secondary_review_time = 1310979 - secondary_reviewer_name = 1310980 - repair_id = 1310981 - multiple_component_approval_sequence = 1310982 - other_approval_status = 1310983 - other_secondary_approval_status = 1310984 - actual_environmental_conditions = 1314832 - expiry_date = 1314848 - environmental_conditions = 1314880 - evaluator_sequence = 1318914 - evaluator_number = 1318916 - evaluator_name = 1318918 - evaluation_attempt = 1318920 - indication_sequence = 1318930 - indication_number = 1318932 - indication_label = 1318934 - indication_description = 1318936 - indication_type = 1318938 - indication_disposition = 1318940 - indication_roi_sequence = 1318942 - indication_physical_property_sequence = 1318960 - property_label = 1318962 - coordinate_system_number_of_axes = 1319426 - coordinate_system_axes_sequence = 1319428 - coordinate_system_axis_description = 1319430 - coordinate_system_data_set_mapping = 1319432 - coordinate_system_axis_number = 1319434 - coordinate_system_axis_type = 1319436 - coordinate_system_axis_units = 1319438 - coordinate_system_axis_values = 1319440 - coordinate_system_transform_sequence = 1319456 - transform_description = 1319458 - transform_number_of_axes = 1319460 - transform_order_of_axes = 1319462 - transformed_axis_units = 1319464 - coordinate_system_transform_rotation_and_scale_matrix = 1319466 - coordinate_system_transform_translation_matrix = 1319468 - internal_detector_frame_time = 1323025 - number_of_frames_integrated = 1323026 - detector_temperature_sequence = 1323040 - sensor_name = 1323042 - horizontal_offset_of_sensor = 1323044 - vertical_offset_of_sensor = 1323046 - sensor_temperature = 1323048 - dark_current_sequence = 1323072 - dark_current_counts = 1323088 - gain_correction_reference_sequence = 1323104 - air_counts = 1323120 - kv_used_in_gain_calibration = 1323121 - ma_used_in_gain_calibration = 1323122 - number_of_frames_used_for_integration = 1323123 - filter_material_used_in_gain_calibration = 1323124 - filter_thickness_used_in_gain_calibration = 1323125 - date_of_gain_calibration = 1323126 - time_of_gain_calibration = 1323127 - bad_pixel_image = 1323136 - calibration_notes = 1323161 - pulser_equipment_sequence = 1327106 - pulser_type = 1327108 - pulser_notes = 1327110 - receiver_equipment_sequence = 1327112 - amplifier_type = 1327114 - receiver_notes = 1327116 - pre_amplifier_equipment_sequence = 1327118 - pre_amplifier_notes = 1327119 - transmit_transducer_sequence = 1327120 - receive_transducer_sequence = 1327121 - number_of_elements = 1327122 - element_shape = 1327123 - element_dimension_a = 1327124 - element_dimension_b = 1327125 - element_pitch_a = 1327126 - measured_beam_dimension_a = 1327127 - measured_beam_dimension_b = 1327128 - location_of_measured_beam_diameter = 1327129 - nominal_frequency = 1327130 - measured_center_frequency = 1327131 - measured_bandwidth = 1327132 - element_pitch_b = 1327133 - pulser_settings_sequence = 1327136 - pulse_width = 1327138 - excitation_frequency = 1327140 - modulation_type = 1327142 - damping = 1327144 - receiver_settings_sequence = 1327152 - acquired_soundpath_length = 1327153 - acquisition_compression_type = 1327154 - acquisition_sample_size = 1327155 - rectifier_smoothing = 1327156 - dac_sequence = 1327157 - dac_type = 1327158 - dac_gain_points = 1327160 - dac_time_points = 1327162 - dac_amplitude = 1327164 - pre_amplifier_settings_sequence = 1327168 - transmit_transducer_settings_sequence = 1327184 - receive_transducer_settings_sequence = 1327185 - incident_angle = 1327186 - coupling_technique = 1327188 - coupling_medium = 1327190 - coupling_velocity = 1327191 - probe_center_location_x = 1327192 - probe_center_location_z = 1327193 - sound_path_length = 1327194 - delay_law_identifier = 1327196 - gate_settings_sequence = 1327200 - gate_threshold = 1327202 - velocity_of_sound = 1327204 - calibration_settings_sequence = 1327216 - calibration_procedure = 1327218 - procedure_version = 1327220 - procedure_creation_date = 1327222 - procedure_expiration_date = 1327224 - procedure_last_modified_date = 1327226 - calibration_time = 1327228 - calibration_date = 1327230 - probe_drive_equipment_sequence = 1327232 - drive_type = 1327233 - probe_drive_notes = 1327234 - drive_probe_sequence = 1327235 - probe_inductance = 1327236 - probe_resistance = 1327237 - receive_probe_sequence = 1327238 - probe_drive_settings_sequence = 1327239 - bridge_resistors = 1327240 - probe_orientation_angle = 1327241 - user_selected_gain_y = 1327243 - user_selected_phase = 1327244 - user_selected_offset_x = 1327245 - user_selected_offset_y = 1327246 - channel_settings_sequence = 1327249 - channel_threshold = 1327250 - scanner_settings_sequence = 1327258 - scan_procedure = 1327259 - translation_rate_x = 1327260 - translation_rate_y = 1327261 - channel_overlap = 1327263 - image_quality_indicator_type = 1327264 - image_quality_indicator_material = 1327265 - image_quality_indicator_size = 1327266 - linac_energy = 1331202 - linac_output = 1331204 - active_aperture = 1331456 - total_aperture = 1331457 - aperture_elevation = 1331458 - main_lobe_angle = 1331459 - main_roof_angle = 1331460 - connector_type = 1331461 - wedge_model_number = 1331462 - wedge_angle_float = 1331463 - wedge_roof_angle = 1331464 - wedge_element_1_position = 1331465 - wedge_material_velocity = 1331466 - wedge_material = 1331467 - wedge_offset_z = 1331468 - wedge_origin_offset_x = 1331469 - wedge_time_delay = 1331470 - wedge_name = 1331471 - wedge_manufacturer_name = 1331472 - wedge_description = 1331473 - nominal_beam_angle = 1331474 - wedge_offset_x = 1331475 - wedge_offset_y = 1331476 - wedge_total_length = 1331477 - wedge_in_contact_length = 1331478 - wedge_front_gap = 1331479 - wedge_total_height = 1331480 - wedge_front_height = 1331481 - wedge_rear_height = 1331482 - wedge_total_width = 1331483 - wedge_in_contact_width = 1331484 - wedge_chamfer_height = 1331485 - wedge_curve = 1331486 - radius_along_the_wedge = 1331487 - contrast_bolus_agent = 1572880 - contrast_bolus_agent_sequence = 1572882 - contrast_bolus_t1_relaxivity = 1572883 - contrast_bolus_administration_route_sequence = 1572884 - body_part_examined = 1572885 - scanning_sequence = 1572896 - sequence_variant = 1572897 - scan_options = 1572898 - mr_acquisition_type = 1572899 - sequence_name = 1572900 - angio_flag = 1572901 - intervention_drug_information_sequence = 1572902 - intervention_drug_stop_time = 1572903 - intervention_drug_dose = 1572904 - intervention_drug_code_sequence = 1572905 - additional_drug_sequence = 1572906 - radionuclide = 1572912 - radiopharmaceutical = 1572913 - energy_window_centerline = 1572914 - energy_window_total_width = 1572915 - intervention_drug_name = 1572916 - intervention_drug_start_time = 1572917 - intervention_sequence = 1572918 - therapy_type = 1572919 - intervention_status = 1572920 - therapy_description = 1572921 - intervention_description = 1572922 - cine_rate = 1572928 - initial_cine_run_state = 1572930 - slice_thickness = 1572944 - kvp = 1572960 - counts_accumulated = 1572976 - acquisition_termination_condition = 1572977 - effective_duration = 1572978 - acquisition_start_condition = 1572979 - acquisition_start_condition_data = 1572980 - acquisition_termination_condition_data = 1572981 - repetition_time = 1572992 - echo_time = 1572993 - inversion_time = 1572994 - number_of_averages = 1572995 - imaging_frequency = 1572996 - imaged_nucleus = 1572997 - echo_number_s_ = 1572998 - magnetic_field_strength = 1572999 - spacing_between_slices = 1573000 - number_of_phase_encoding_steps = 1573001 - data_collection_diameter = 1573008 - echo_train_length = 1573009 - percent_sampling = 1573011 - percent_phase_field_of_view = 1573012 - pixel_bandwidth = 1573013 - device_serial_number = 1576960 - device_uid = 1576962 - device_id = 1576963 - plate_id = 1576964 - generator_id = 1576965 - grid_id = 1576966 - cassette_id = 1576967 - gantry_id = 1576968 - secondary_capture_device_id = 1576976 - hardcopy_creation_device_id = 1576977 - date_of_secondary_capture = 1576978 - time_of_secondary_capture = 1576980 - secondary_capture_device_manufacturer = 1576982 - hardcopy_device_manufacturer = 1576983 - secondary_capture_device_manufacturer_s_model_name = 1576984 - secondary_capture_device_software_versions = 1576985 - hardcopy_device_software_version = 1576986 - hardcopy_device_manufacturer_s_model_name = 1576987 - software_version_s_ = 1576992 - video_image_format_acquired = 1576994 - digital_image_format_acquired = 1576995 - protocol_name = 1577008 - contrast_bolus_route = 1577024 - contrast_bolus_volume = 1577025 - contrast_bolus_start_time = 1577026 - contrast_bolus_stop_time = 1577027 - contrast_bolus_total_dose = 1577028 - syringe_counts = 1577029 - contrast_flow_rate = 1577030 - contrast_flow_duration = 1577031 - contrast_bolus_ingredient = 1577032 - contrast_bolus_ingredient_concentration = 1577033 - spatial_resolution = 1577040 - trigger_time = 1577056 - trigger_source_or_type = 1577057 - nominal_interval = 1577058 - frame_time = 1577059 - cardiac_framing_type = 1577060 - frame_time_vector = 1577061 - frame_delay = 1577062 - image_trigger_delay = 1577063 - multiplex_group_time_offset = 1577064 - trigger_time_offset = 1577065 - synchronization_trigger = 1577066 - synchronization_channel = 1577068 - trigger_sample_position = 1577070 - radiopharmaceutical_route = 1577072 - radiopharmaceutical_volume = 1577073 - radiopharmaceutical_start_time = 1577074 - radiopharmaceutical_stop_time = 1577075 - radionuclide_total_dose = 1577076 - radionuclide_half_life = 1577077 - radionuclide_positron_fraction = 1577078 - radiopharmaceutical_specific_activity = 1577079 - radiopharmaceutical_start_datetime = 1577080 - radiopharmaceutical_stop_datetime = 1577081 - beat_rejection_flag = 1577088 - low_r_r_value = 1577089 - high_r_r_value = 1577090 - intervals_acquired = 1577091 - intervals_rejected = 1577092 - pvc_rejection = 1577093 - skip_beats = 1577094 - heart_rate = 1577096 - cardiac_number_of_images = 1577104 - trigger_window = 1577108 - reconstruction_diameter = 1577216 - distance_source_to_detector = 1577232 - distance_source_to_patient = 1577233 - estimated_radiographic_magnification_factor = 1577236 - gantry_detector_tilt = 1577248 - gantry_detector_slew = 1577249 - table_height = 1577264 - table_traverse = 1577265 - table_motion = 1577268 - table_vertical_increment = 1577269 - table_lateral_increment = 1577270 - table_longitudinal_increment = 1577271 - table_angle = 1577272 - table_type = 1577274 - rotation_direction = 1577280 - angular_position = 1577281 - radial_position = 1577282 - scan_arc = 1577283 - angular_step = 1577284 - center_of_rotation_offset = 1577285 - rotation_offset = 1577286 - field_of_view_shape = 1577287 - field_of_view_dimension_s_ = 1577289 - exposure_time = 1577296 - x_ray_tube_current = 1577297 - exposure = 1577298 - exposure_in__as = 1577299 - average_pulse_width = 1577300 - radiation_setting = 1577301 - rectification_type = 1577302 - radiation_mode = 1577306 - image_and_fluoroscopy_area_dose_product = 1577310 - filter_type = 1577312 - type_of_filters = 1577313 - intensifier_size = 1577314 - imager_pixel_spacing = 1577316 - grid = 1577318 - generator_power = 1577328 - collimator_grid_name = 1577344 - collimator_type = 1577345 - focal_distance = 1577346 - x_focus_center = 1577347 - y_focus_center = 1577348 - focal_spot_s_ = 1577360 - anode_target_material = 1577361 - body_part_thickness = 1577376 - compression_force = 1577378 - paddle_description = 1577380 - date_of_last_calibration = 1577472 - time_of_last_calibration = 1577473 - datetime_of_last_calibration = 1577474 - convolution_kernel = 1577488 - upper_lower_pixel_values = 1577536 - actual_frame_duration = 1577538 - count_rate = 1577539 - preferred_playback_sequencing = 1577540 - receive_coil_name = 1577552 - transmit_coil_name = 1577553 - plate_type = 1577568 - phosphor_type = 1577569 - water_equivalent_diameter = 1577585 - water_equivalent_diameter_calculation_method_code_sequence = 1577586 - scan_velocity = 1577728 - whole_body_technique = 1577729 - scan_length = 1577730 - acquisition_matrix = 1577744 - in_plane_phase_encoding_direction = 1577746 - flip_angle = 1577748 - variable_flip_angle_flag = 1577749 - sar = 1577750 - db_dt = 1577752 - b1rms = 1577760 - acquisition_device_processing_description = 1577984 - acquisition_device_processing_code = 1577985 - cassette_orientation = 1577986 - cassette_size = 1577987 - exposures_on_plate = 1577988 - relative_x_ray_exposure = 1577989 - exposure_index = 1578001 - target_exposure_index = 1578002 - deviation_index = 1578003 - column_angulation = 1578064 - tomo_layer_height = 1578080 - tomo_angle = 1578096 - tomo_time = 1578112 - tomo_type = 1578128 - tomo_class = 1578129 - number_of_tomosynthesis_source_images = 1578133 - positioner_motion = 1578240 - positioner_type = 1578248 - positioner_primary_angle = 1578256 - positioner_secondary_angle = 1578257 - positioner_primary_angle_increment = 1578272 - positioner_secondary_angle_increment = 1578273 - detector_primary_angle = 1578288 - detector_secondary_angle = 1578289 - shutter_shape = 1578496 - shutter_left_vertical_edge = 1578498 - shutter_right_vertical_edge = 1578500 - shutter_upper_horizontal_edge = 1578502 - shutter_lower_horizontal_edge = 1578504 - center_of_circular_shutter = 1578512 - radius_of_circular_shutter = 1578514 - vertices_of_the_polygonal_shutter = 1578528 - shutter_presentation_value = 1578530 - shutter_overlay_group = 1578531 - shutter_presentation_color_cielab_value = 1578532 - collimator_shape = 1578752 - collimator_left_vertical_edge = 1578754 - collimator_right_vertical_edge = 1578756 - collimator_upper_horizontal_edge = 1578758 - collimator_lower_horizontal_edge = 1578760 - center_of_circular_collimator = 1578768 - radius_of_circular_collimator = 1578770 - vertices_of_the_polygonal_collimator = 1578784 - acquisition_time_synchronized = 1579008 - time_source = 1579009 - time_distribution_protocol = 1579010 - ntp_source_address = 1579011 - page_number_vector = 1581057 - frame_label_vector = 1581058 - frame_primary_angle_vector = 1581059 - frame_secondary_angle_vector = 1581060 - slice_location_vector = 1581061 - display_window_label_vector = 1581062 - nominal_scanned_pixel_spacing = 1581072 - digitizing_device_transport_direction = 1581088 - rotation_of_scanned_film = 1581104 - biopsy_target_sequence = 1581121 - target_uid = 1581122 - localizing_cursor_position = 1581123 - calculated_target_position = 1581124 - target_label = 1581125 - displayed_z_value = 1581126 - ivus_acquisition = 1585408 - ivus_pullback_rate = 1585409 - ivus_gated_rate = 1585410 - ivus_pullback_start_frame_number = 1585411 - ivus_pullback_stop_frame_number = 1585412 - lesion_number = 1585413 - acquisition_comments = 1589248 - output_power = 1593344 - transducer_data = 1593360 - focus_depth = 1593362 - processing_function = 1593376 - postprocessing_function = 1593377 - mechanical_index = 1593378 - bone_thermal_index = 1593380 - cranial_thermal_index = 1593382 - soft_tissue_thermal_index = 1593383 - soft_tissue_focus_thermal_index = 1593384 - soft_tissue_surface_thermal_index = 1593385 - dynamic_range = 1593392 - total_gain = 1593408 - depth_of_scan_field = 1593424 - patient_position = 1593600 - view_position = 1593601 - projection_eponymous_name_code_sequence = 1593604 - image_transformation_matrix = 1593872 - image_translation_vector = 1593874 - sensitivity = 1597440 - sequence_of_ultrasound_regions = 1597457 - region_spatial_format = 1597458 - region_data_type = 1597460 - region_flags = 1597462 - region_location_min_x0 = 1597464 - region_location_min_y0 = 1597466 - region_location_max_x1 = 1597468 - region_location_max_y1 = 1597470 - reference_pixel_x0 = 1597472 - reference_pixel_y0 = 1597474 - physical_units_x_direction = 1597476 - physical_units_y_direction = 1597478 - reference_pixel_physical_value_x = 1597480 - reference_pixel_physical_value_y = 1597482 - physical_delta_x = 1597484 - physical_delta_y = 1597486 - transducer_frequency = 1597488 - transducer_type = 1597489 - pulse_repetition_frequency = 1597490 - doppler_correction_angle = 1597492 - steering_angle = 1597494 - doppler_sample_volume_x_position__retired_ = 1597496 - doppler_sample_volume_x_position = 1597497 - doppler_sample_volume_y_position__retired_ = 1597498 - doppler_sample_volume_y_position = 1597499 - tm_line_position_x0__retired_ = 1597500 - tm_line_position_x0 = 1597501 - tm_line_position_y0__retired_ = 1597502 - tm_line_position_y0 = 1597503 - tm_line_position_x1__retired_ = 1597504 - tm_line_position_x1 = 1597505 - tm_line_position_y1__retired_ = 1597506 - tm_line_position_y1 = 1597507 - pixel_component_organization = 1597508 - pixel_component_mask = 1597510 - pixel_component_range_start = 1597512 - pixel_component_range_stop = 1597514 - pixel_component_physical_units = 1597516 - pixel_component_data_type = 1597518 - number_of_table_break_points = 1597520 - table_of_x_break_points = 1597522 - table_of_y_break_points = 1597524 - number_of_table_entries = 1597526 - table_of_pixel_values = 1597528 - table_of_parameter_values = 1597530 - r_wave_time_vector = 1597536 - detector_conditions_nominal_flag = 1601536 - detector_temperature = 1601537 - detector_type = 1601540 - detector_configuration = 1601541 - detector_description = 1601542 - detector_mode = 1601544 - detector_id = 1601546 - date_of_last_detector_calibration = 1601548 - time_of_last_detector_calibration = 1601550 - exposures_on_detector_since_last_calibration = 1601552 - exposures_on_detector_since_manufactured = 1601553 - detector_time_since_last_exposure = 1601554 - detector_active_time = 1601556 - detector_activation_offset_from_exposure = 1601558 - detector_binning = 1601562 - detector_element_physical_size = 1601568 - detector_element_spacing = 1601570 - detector_active_shape = 1601572 - detector_active_dimension_s_ = 1601574 - detector_active_origin = 1601576 - detector_manufacturer_name = 1601578 - detector_manufacturer_s_model_name = 1601579 - field_of_view_origin = 1601584 - field_of_view_rotation = 1601586 - field_of_view_horizontal_flip = 1601588 - pixel_data_area_origin_relative_to_fov = 1601590 - pixel_data_area_rotation_angle_relative_to_fov = 1601592 - grid_absorbing_material = 1601600 - grid_spacing_material = 1601601 - grid_thickness = 1601602 - grid_pitch = 1601604 - grid_aspect_ratio = 1601606 - grid_period = 1601608 - grid_focal_distance = 1601612 - filter_material = 1601616 - filter_thickness_minimum = 1601618 - filter_thickness_maximum = 1601620 - filter_beam_path_length_minimum = 1601622 - filter_beam_path_length_maximum = 1601624 - exposure_control_mode = 1601632 - exposure_control_mode_description = 1601634 - exposure_status = 1601636 - phototimer_setting = 1601637 - exposure_time_in__s = 1605968 - x_ray_tube_current_in__a = 1605969 - content_qualification = 1609732 - pulse_sequence_name = 1609733 - mr_imaging_modifier_sequence = 1609734 - echo_pulse_sequence = 1609736 - inversion_recovery = 1609737 - flow_compensation = 1609744 - multiple_spin_echo = 1609745 - multi_planar_excitation = 1609746 - phase_contrast = 1609748 - time_of_flight_contrast = 1609749 - spoiling = 1609750 - steady_state_pulse_sequence = 1609751 - echo_planar_pulse_sequence = 1609752 - tag_angle_first_axis = 1609753 - magnetization_transfer = 1609760 - t2_preparation = 1609761 - blood_signal_nulling = 1609762 - saturation_recovery = 1609764 - spectrally_selected_suppression = 1609765 - spectrally_selected_excitation = 1609766 - spatial_pre_saturation = 1609767 - tagging = 1609768 - oversampling_phase = 1609769 - tag_spacing_first_dimension = 1609776 - geometry_of_k_space_traversal = 1609778 - segmented_k_space_traversal = 1609779 - rectilinear_phase_encode_reordering = 1609780 - tag_thickness = 1609781 - partial_fourier_direction = 1609782 - cardiac_synchronization_technique = 1609783 - receive_coil_manufacturer_name = 1609793 - mr_receive_coil_sequence = 1609794 - receive_coil_type = 1609795 - quadrature_receive_coil = 1609796 - multi_coil_definition_sequence = 1609797 - multi_coil_configuration = 1609798 - multi_coil_element_name = 1609799 - multi_coil_element_used = 1609800 - mr_transmit_coil_sequence = 1609801 - transmit_coil_manufacturer_name = 1609808 - transmit_coil_type = 1609809 - spectral_width = 1609810 - chemical_shift_reference = 1609811 - volume_localization_technique = 1609812 - mr_acquisition_frequency_encoding_steps = 1609816 - de_coupling = 1609817 - de_coupled_nucleus = 1609824 - de_coupling_frequency = 1609825 - de_coupling_method = 1609826 - de_coupling_chemical_shift_reference = 1609827 - k_space_filtering = 1609828 - time_domain_filtering = 1609829 - number_of_zero_fills = 1609830 - baseline_correction = 1609831 - parallel_reduction_factor_in_plane = 1609833 - cardiac_r_r_interval_specified = 1609840 - acquisition_duration = 1609843 - frame_acquisition_datetime = 1609844 - diffusion_directionality = 1609845 - diffusion_gradient_direction_sequence = 1609846 - parallel_acquisition = 1609847 - parallel_acquisition_technique = 1609848 - inversion_times = 1609849 - metabolite_map_description = 1609856 - partial_fourier = 1609857 - effective_echo_time = 1609858 - metabolite_map_code_sequence = 1609859 - chemical_shift_sequence = 1609860 - cardiac_signal_source = 1609861 - diffusion_b_value = 1609863 - diffusion_gradient_orientation = 1609865 - velocity_encoding_direction = 1609872 - velocity_encoding_minimum_value = 1609873 - velocity_encoding_acquisition_sequence = 1609874 - number_of_k_space_trajectories = 1609875 - coverage_of_k_space = 1609876 - spectroscopy_acquisition_phase_rows = 1609877 - parallel_reduction_factor_in_plane__retired_ = 1609878 - transmitter_frequency = 1609880 - resonant_nucleus = 1609984 - frequency_correction = 1609985 - mr_spectroscopy_fov_geometry_sequence = 1609987 - slab_thickness = 1609988 - slab_orientation = 1609989 - mid_slab_position = 1609990 - mr_spatial_saturation_sequence = 1609991 - mr_timing_and_related_parameters_sequence = 1610002 - mr_echo_sequence = 1610004 - mr_modifier_sequence = 1610005 - mr_diffusion_sequence = 1610007 - cardiac_synchronization_sequence = 1610008 - mr_averages_sequence = 1610009 - mr_fov_geometry_sequence = 1610021 - volume_localization_sequence = 1610022 - spectroscopy_acquisition_data_columns = 1610023 - diffusion_anisotropy_type = 1610055 - frame_reference_datetime = 1610065 - mr_metabolite_map_sequence = 1610066 - parallel_reduction_factor_out_of_plane = 1610069 - spectroscopy_acquisition_out_of_plane_phase_steps = 1610073 - bulk_motion_status = 1610086 - parallel_reduction_factor_second_in_plane = 1610088 - cardiac_beat_rejection_technique = 1610089 - respiratory_motion_compensation_technique = 1610096 - respiratory_signal_source = 1610097 - bulk_motion_compensation_technique = 1610098 - bulk_motion_signal_source = 1610099 - applicable_safety_standard_agency = 1610100 - applicable_safety_standard_description = 1610101 - operating_mode_sequence = 1610102 - operating_mode_type = 1610103 - operating_mode = 1610104 - specific_absorption_rate_definition = 1610105 - gradient_output_type = 1610112 - specific_absorption_rate_value = 1610113 - gradient_output = 1610114 - flow_compensation_direction = 1610115 - tagging_delay = 1610116 - respiratory_motion_compensation_technique_description = 1610117 - respiratory_signal_source_id = 1610118 - chemical_shift_minimum_integration_limit_in_hz = 1610133 - chemical_shift_maximum_integration_limit_in_hz = 1610134 - mr_velocity_encoding_sequence = 1610135 - first_order_phase_correction = 1610136 - water_referenced_phase_correction = 1610137 - mr_spectroscopy_acquisition_type = 1610240 - respiratory_cycle_position = 1610260 - velocity_encoding_maximum_value = 1610263 - tag_spacing_second_dimension = 1610264 - tag_angle_second_axis = 1610265 - frame_acquisition_duration = 1610272 - mr_image_frame_type_sequence = 1610278 - mr_spectroscopy_frame_type_sequence = 1610279 - mr_acquisition_phase_encoding_steps_in_plane = 1610289 - mr_acquisition_phase_encoding_steps_out_of_plane = 1610290 - spectroscopy_acquisition_phase_columns = 1610292 - cardiac_cycle_position = 1610294 - specific_absorption_rate_sequence = 1610297 - rf_echo_train_length = 1610304 - gradient_echo_train_length = 1610305 - arterial_spin_labeling_contrast = 1610320 - mr_arterial_spin_labeling_sequence = 1610321 - asl_technique_description = 1610322 - asl_slab_number = 1610323 - asl_slab_thickness = 1610324 - asl_slab_orientation = 1610325 - asl_mid_slab_position = 1610326 - asl_context = 1610327 - asl_pulse_train_duration = 1610328 - asl_crusher_flag = 1610329 - asl_crusher_flow_limit = 1610330 - asl_crusher_description = 1610331 - asl_bolus_cut_off_flag = 1610332 - asl_bolus_cut_off_timing_sequence = 1610333 - asl_bolus_cut_off_technique = 1610334 - asl_bolus_cut_off_delay_time = 1610335 - asl_slab_sequence = 1610336 - chemical_shift_minimum_integration_limit_in_ppm = 1610389 - chemical_shift_maximum_integration_limit_in_ppm = 1610390 - water_reference_acquisition = 1610391 - echo_peak_position = 1610392 - ct_acquisition_type_sequence = 1610497 - acquisition_type = 1610498 - tube_angle = 1610499 - ct_acquisition_details_sequence = 1610500 - revolution_time = 1610501 - single_collimation_width = 1610502 - total_collimation_width = 1610503 - ct_table_dynamics_sequence = 1610504 - table_speed = 1610505 - table_feed_per_rotation = 1610512 - spiral_pitch_factor = 1610513 - ct_geometry_sequence = 1610514 - data_collection_center__patient_ = 1610515 - ct_reconstruction_sequence = 1610516 - reconstruction_algorithm = 1610517 - convolution_kernel_group = 1610518 - reconstruction_field_of_view = 1610519 - reconstruction_target_center__patient_ = 1610520 - reconstruction_angle = 1610521 - image_filter = 1610528 - ct_exposure_sequence = 1610529 - reconstruction_pixel_spacing = 1610530 - exposure_modulation_type = 1610531 - estimated_dose_saving = 1610532 - ct_x_ray_details_sequence = 1610533 - ct_position_sequence = 1610534 - table_position = 1610535 - exposure_time_in_ms = 1610536 - ct_image_frame_type_sequence = 1610537 - x_ray_tube_current_in_ma = 1610544 - exposure_in_mas = 1610546 - constant_volume_flag = 1610547 - fluoroscopy_flag = 1610548 - distance_source_to_data_collection_center = 1610549 - contrast_bolus_agent_number = 1610551 - contrast_bolus_ingredient_code_sequence = 1610552 - contrast_administration_profile_sequence = 1610560 - contrast_bolus_usage_sequence = 1610561 - contrast_bolus_agent_administered = 1610562 - contrast_bolus_agent_detected = 1610563 - contrast_bolus_agent_phase = 1610564 - ctdivol = 1610565 - ctdi_phantom_type_code_sequence = 1610566 - calcium_scoring_mass_factor_patient = 1610577 - calcium_scoring_mass_factor_device = 1610578 - energy_weighting_factor = 1610579 - ct_additional_x_ray_source_sequence = 1610592 - projection_pixel_calibration_sequence = 1610753 - distance_source_to_isocenter = 1610754 - distance_object_to_table_top = 1610755 - object_pixel_spacing_in_center_of_beam = 1610756 - positioner_position_sequence = 1610757 - table_position_sequence = 1610758 - collimator_shape_sequence = 1610759 - planes_in_acquisition = 1610768 - xa_xrf_frame_characteristics_sequence = 1610770 - frame_acquisition_sequence = 1610775 - x_ray_receptor_type = 1610784 - acquisition_protocol_name = 1610787 - acquisition_protocol_description = 1610788 - contrast_bolus_ingredient_opaque = 1610789 - distance_receptor_plane_to_detector_housing = 1610790 - intensifier_active_shape = 1610791 - intensifier_active_dimension_s_ = 1610792 - physical_detector_size = 1610793 - position_of_isocenter_projection = 1610800 - field_of_view_sequence = 1610802 - field_of_view_description = 1610803 - exposure_control_sensing_regions_sequence = 1610804 - exposure_control_sensing_region_shape = 1610805 - exposure_control_sensing_region_left_vertical_edge = 1610806 - exposure_control_sensing_region_right_vertical_edge = 1610807 - exposure_control_sensing_region_upper_horizontal_edge = 1610808 - exposure_control_sensing_region_lower_horizontal_edge = 1610809 - center_of_circular_exposure_control_sensing_region = 1610816 - radius_of_circular_exposure_control_sensing_region = 1610817 - vertices_of_the_polygonal_exposure_control_sensing_region = 1610818 - column_angulation__patient_ = 1610823 - beam_angle = 1610825 - frame_detector_parameters_sequence = 1610833 - calculated_anatomy_thickness = 1610834 - calibration_sequence = 1610837 - object_thickness_sequence = 1610838 - plane_identification = 1610839 - field_of_view_dimension_s__in_float = 1610849 - isocenter_reference_system_sequence = 1610850 - positioner_isocenter_primary_angle = 1610851 - positioner_isocenter_secondary_angle = 1610852 - positioner_isocenter_detector_rotation_angle = 1610853 - table_x_position_to_isocenter = 1610854 - table_y_position_to_isocenter = 1610855 - table_z_position_to_isocenter = 1610856 - table_horizontal_rotation_angle = 1610857 - table_head_tilt_angle = 1610864 - table_cradle_tilt_angle = 1610865 - frame_display_shutter_sequence = 1610866 - acquired_image_area_dose_product = 1610867 - c_arm_positioner_tabletop_relationship = 1610868 - x_ray_geometry_sequence = 1610870 - irradiation_event_identification_sequence = 1610871 - x_ray_3d_frame_type_sequence = 1611012 - contributing_sources_sequence = 1611014 - x_ray_3d_acquisition_sequence = 1611015 - primary_positioner_scan_arc = 1611016 - secondary_positioner_scan_arc = 1611017 - primary_positioner_scan_start_angle = 1611024 - secondary_positioner_scan_start_angle = 1611025 - primary_positioner_increment = 1611028 - secondary_positioner_increment = 1611029 - start_acquisition_datetime = 1611030 - end_acquisition_datetime = 1611031 - primary_positioner_increment_sign = 1611032 - secondary_positioner_increment_sign = 1611033 - application_name = 1611044 - application_version = 1611045 - application_manufacturer = 1611046 - algorithm_type = 1611047 - algorithm_description = 1611048 - x_ray_3d_reconstruction_sequence = 1611056 - reconstruction_description = 1611057 - per_projection_acquisition_sequence = 1611064 - detector_position_sequence = 1611073 - x_ray_acquisition_dose_sequence = 1611074 - x_ray_source_isocenter_primary_angle = 1611075 - x_ray_source_isocenter_secondary_angle = 1611076 - breast_support_isocenter_primary_angle = 1611077 - breast_support_isocenter_secondary_angle = 1611078 - breast_support_x_position_to_isocenter = 1611079 - breast_support_y_position_to_isocenter = 1611080 - breast_support_z_position_to_isocenter = 1611081 - detector_isocenter_primary_angle = 1611088 - detector_isocenter_secondary_angle = 1611089 - detector_x_position_to_isocenter = 1611090 - detector_y_position_to_isocenter = 1611091 - detector_z_position_to_isocenter = 1611092 - x_ray_grid_sequence = 1611093 - x_ray_filter_sequence = 1611094 - detector_active_area_tlhc_position = 1611095 - detector_active_area_orientation = 1611096 - positioner_primary_angle_direction = 1611097 - diffusion_b_matrix_sequence = 1611265 - diffusion_b_value_xx = 1611266 - diffusion_b_value_xy = 1611267 - diffusion_b_value_xz = 1611268 - diffusion_b_value_yy = 1611269 - diffusion_b_value_yz = 1611270 - diffusion_b_value_zz = 1611271 - functional_mr_sequence = 1611297 - functional_settling_phase_frames_present = 1611298 - functional_sync_pulse = 1611299 - settling_phase_frame = 1611300 - decay_correction_datetime = 1611521 - start_density_threshold = 1611541 - start_relative_density_difference_threshold = 1611542 - start_cardiac_trigger_count_threshold = 1611543 - start_respiratory_trigger_count_threshold = 1611544 - termination_counts_threshold = 1611545 - termination_density_threshold = 1611552 - termination_relative_density_threshold = 1611553 - termination_time_threshold = 1611554 - termination_cardiac_trigger_count_threshold = 1611555 - termination_respiratory_trigger_count_threshold = 1611556 - detector_geometry = 1611557 - transverse_detector_separation = 1611558 - axial_detector_dimension = 1611559 - radiopharmaceutical_agent_number = 1611561 - pet_frame_acquisition_sequence = 1611570 - pet_detector_motion_details_sequence = 1611571 - pet_table_dynamics_sequence = 1611572 - pet_position_sequence = 1611573 - pet_frame_correction_factors_sequence = 1611574 - radiopharmaceutical_usage_sequence = 1611575 - attenuation_correction_source = 1611576 - number_of_iterations = 1611577 - number_of_subsets = 1611584 - pet_reconstruction_sequence = 1611593 - pet_frame_type_sequence = 1611601 - time_of_flight_information_used = 1611605 - reconstruction_type = 1611606 - decay_corrected = 1611608 - attenuation_corrected = 1611609 - scatter_corrected = 1611616 - dead_time_corrected = 1611617 - gantry_motion_corrected = 1611618 - patient_motion_corrected = 1611619 - count_loss_normalization_corrected = 1611620 - randoms_corrected = 1611621 - non_uniform_radial_sampling_corrected = 1611622 - sensitivity_calibrated = 1611623 - detector_normalization_correction = 1611624 - iterative_reconstruction_method = 1611625 - attenuation_correction_temporal_relationship = 1611632 - patient_physiological_state_sequence = 1611633 - patient_physiological_state_code_sequence = 1611634 - depth_s__of_focus = 1611777 - excluded_intervals_sequence = 1611779 - exclusion_start_datetime = 1611780 - exclusion_duration = 1611781 - us_image_description_sequence = 1611782 - image_data_type_sequence = 1611783 - data_type = 1611784 - transducer_scan_pattern_code_sequence = 1611785 - aliased_data_type = 1611787 - position_measuring_device_used = 1611788 - transducer_geometry_code_sequence = 1611789 - transducer_beam_steering_code_sequence = 1611790 - transducer_application_code_sequence = 1611791 - zero_velocity_pixel_value = 1611792 - contributing_equipment_sequence = 1613825 - contribution_datetime = 1613826 - contribution_description = 1613827 - study_instance_uid = 2097165 - series_instance_uid = 2097166 - study_id = 2097168 - series_number = 2097169 - acquisition_number = 2097170 - instance_number = 2097171 - isotope_number = 2097172 - phase_number = 2097173 - interval_number = 2097174 - time_slot_number = 2097175 - angle_number = 2097176 - item_number = 2097177 - patient_orientation = 2097184 - overlay_number = 2097186 - curve_number = 2097188 - lut_number = 2097190 - image_position = 2097200 - image_position__patient_ = 2097202 - image_orientation = 2097205 - image_orientation__patient_ = 2097207 - location = 2097232 - frame_of_reference_uid = 2097234 - laterality = 2097248 - image_laterality = 2097250 - image_geometry_type = 2097264 - masking_image = 2097280 - report_number = 2097322 - temporal_position_identifier = 2097408 - number_of_temporal_positions = 2097413 - temporal_resolution = 2097424 - synchronization_frame_of_reference_uid = 2097664 - sop_instance_uid_of_concatenation_source = 2097730 - series_in_study = 2101248 - acquisitions_in_series = 2101249 - images_in_acquisition = 2101250 - images_in_series = 2101251 - acquisitions_in_study = 2101252 - images_in_study = 2101253 - reference = 2101280 - position_reference_indicator = 2101312 - slice_location = 2101313 - other_study_numbers = 2101360 - number_of_patient_related_studies = 2101760 - number_of_patient_related_series = 2101762 - number_of_patient_related_instances = 2101764 - number_of_study_related_series = 2101766 - number_of_study_related_instances = 2101768 - number_of_series_related_instances = 2101769 - modifying_device_id = 2110465 - modified_image_id = 2110466 - modified_image_date = 2110467 - modifying_device_manufacturer = 2110468 - modified_image_time = 2110469 - modified_image_description = 2110470 - image_comments = 2113536 - original_image_identification = 2117632 - original_image_identification_nomenclature = 2117634 - stack_id = 2134102 - in_stack_position_number = 2134103 - frame_anatomy_sequence = 2134129 - frame_laterality = 2134130 - frame_content_sequence = 2134289 - plane_position_sequence = 2134291 - plane_orientation_sequence = 2134294 - temporal_position_index = 2134312 - nominal_cardiac_trigger_delay_time = 2134355 - nominal_cardiac_trigger_time_prior_to_r_peak = 2134356 - actual_cardiac_trigger_time_prior_to_r_peak = 2134357 - frame_acquisition_number = 2134358 - dimension_index_values = 2134359 - frame_comments = 2134360 - concatenation_uid = 2134369 - in_concatenation_number = 2134370 - in_concatenation_total_number = 2134371 - dimension_organization_uid = 2134372 - dimension_index_pointer = 2134373 - functional_group_pointer = 2134375 - unassigned_shared_converted_attributes_sequence = 2134384 - unassigned_per_frame_converted_attributes_sequence = 2134385 - conversion_source_attributes_sequence = 2134386 - dimension_index_private_creator = 2134547 - dimension_organization_sequence = 2134561 - dimension_index_sequence = 2134562 - concatenation_frame_offset_number = 2134568 - functional_group_private_creator = 2134584 - nominal_percentage_of_cardiac_phase = 2134593 - nominal_percentage_of_respiratory_phase = 2134597 - starting_respiratory_amplitude = 2134598 - starting_respiratory_phase = 2134599 - ending_respiratory_amplitude = 2134600 - ending_respiratory_phase = 2134601 - respiratory_trigger_type = 2134608 - r_r_interval_time_nominal = 2134609 - actual_cardiac_trigger_delay_time = 2134610 - respiratory_synchronization_sequence = 2134611 - respiratory_interval_time = 2134612 - nominal_respiratory_trigger_delay_time = 2134613 - respiratory_trigger_delay_threshold = 2134614 - actual_respiratory_trigger_delay_time = 2134615 - image_position__volume_ = 2134785 - image_orientation__volume_ = 2134786 - ultrasound_acquisition_geometry = 2134791 - apex_position = 2134792 - volume_to_transducer_mapping_matrix = 2134793 - volume_to_table_mapping_matrix = 2134794 - volume_to_transducer_relationship = 2134795 - patient_frame_of_reference_source = 2134796 - temporal_position_time_offset = 2134797 - plane_position__volume__sequence = 2134798 - plane_orientation__volume__sequence = 2134799 - temporal_position_sequence = 2134800 - dimension_organization_type = 2134801 - volume_frame_of_reference_uid = 2134802 - table_frame_of_reference_uid = 2134803 - dimension_description_label = 2135073 - patient_orientation_in_frame_sequence = 2135120 - frame_label = 2135123 - acquisition_index = 2135320 - contributing_sop_instances_reference_sequence = 2135337 - reconstruction_index = 2135350 - light_path_filter_pass_through_wavelength = 2228225 - light_path_filter_pass_band = 2228226 - image_path_filter_pass_through_wavelength = 2228227 - image_path_filter_pass_band = 2228228 - patient_eye_movement_commanded = 2228229 - patient_eye_movement_command_code_sequence = 2228230 - spherical_lens_power = 2228231 - cylinder_lens_power = 2228232 - cylinder_axis = 2228233 - emmetropic_magnification = 2228234 - intra_ocular_pressure = 2228235 - horizontal_field_of_view = 2228236 - pupil_dilated = 2228237 - degree_of_dilation = 2228238 - stereo_baseline_angle = 2228240 - stereo_baseline_displacement = 2228241 - stereo_horizontal_pixel_offset = 2228242 - stereo_vertical_pixel_offset = 2228243 - stereo_rotation = 2228244 - acquisition_device_type_code_sequence = 2228245 - illumination_type_code_sequence = 2228246 - light_path_filter_type_stack_code_sequence = 2228247 - image_path_filter_type_stack_code_sequence = 2228248 - lenses_code_sequence = 2228249 - channel_description_code_sequence = 2228250 - refractive_state_sequence = 2228251 - mydriatic_agent_code_sequence = 2228252 - relative_image_position_code_sequence = 2228253 - camera_angle_of_view = 2228254 - stereo_pairs_sequence = 2228256 - left_image_sequence = 2228257 - right_image_sequence = 2228258 - stereo_pairs_present = 2228264 - axial_length_of_the_eye = 2228272 - ophthalmic_frame_location_sequence = 2228273 - reference_coordinates = 2228274 - depth_spatial_resolution = 2228277 - maximum_depth_distortion = 2228278 - along_scan_spatial_resolution = 2228279 - maximum_along_scan_distortion = 2228280 - ophthalmic_image_orientation = 2228281 - depth_of_transverse_image = 2228289 - mydriatic_agent_concentration_units_sequence = 2228290 - across_scan_spatial_resolution = 2228296 - maximum_across_scan_distortion = 2228297 - mydriatic_agent_concentration = 2228302 - illumination_wave_length = 2228309 - illumination_power = 2228310 - illumination_bandwidth = 2228311 - mydriatic_agent_sequence = 2228312 - ophthalmic_axial_measurements_right_eye_sequence = 2232327 - ophthalmic_axial_measurements_left_eye_sequence = 2232328 - ophthalmic_axial_measurements_device_type = 2232329 - ophthalmic_axial_length_measurements_type = 2232336 - ophthalmic_axial_length_sequence = 2232338 - ophthalmic_axial_length = 2232345 - lens_status_code_sequence = 2232356 - vitreous_status_code_sequence = 2232357 - iol_formula_code_sequence = 2232360 - iol_formula_detail = 2232361 - keratometer_index = 2232371 - source_of_ophthalmic_axial_length_code_sequence = 2232373 - target_refraction = 2232375 - refractive_procedure_occurred = 2232377 - refractive_surgery_type_code_sequence = 2232384 - ophthalmic_ultrasound_method_code_sequence = 2232388 - ophthalmic_axial_length_measurements_sequence = 2232400 - iol_power = 2232403 - predicted_refractive_error = 2232404 - ophthalmic_axial_length_velocity = 2232409 - lens_status_description = 2232421 - vitreous_status_description = 2232422 - iol_power_sequence = 2232464 - lens_constant_sequence = 2232466 - iol_manufacturer = 2232467 - lens_constant_description = 2232468 - implant_name = 2232469 - keratometry_measurement_type_code_sequence = 2232470 - implant_part_number = 2232471 - referenced_ophthalmic_axial_measurements_sequence = 2232576 - ophthalmic_axial_length_measurements_segment_name_code_sequence = 2232577 - refractive_error_before_refractive_surgery_code_sequence = 2232579 - iol_power_for_exact_emmetropia = 2232609 - iol_power_for_exact_target_refraction = 2232610 - anterior_chamber_depth_definition_code_sequence = 2232613 - lens_thickness_sequence = 2232615 - anterior_chamber_depth_sequence = 2232616 - lens_thickness = 2232624 - anterior_chamber_depth = 2232625 - source_of_lens_thickness_data_code_sequence = 2232626 - source_of_anterior_chamber_depth_data_code_sequence = 2232627 - source_of_refractive_measurements_sequence = 2232628 - source_of_refractive_measurements_code_sequence = 2232629 - ophthalmic_axial_length_measurement_modified = 2232640 - ophthalmic_axial_length_data_source_code_sequence = 2232656 - ophthalmic_axial_length_acquisition_method_code_sequence = 2232659 - signal_to_noise_ratio = 2232661 - ophthalmic_axial_length_data_source_description = 2232665 - ophthalmic_axial_length_measurements_total_length_sequence = 2232848 - ophthalmic_axial_length_measurements_segmental_length_sequence = 2232849 - ophthalmic_axial_length_measurements_length_summation_sequence = 2232850 - ultrasound_ophthalmic_axial_length_measurements_sequence = 2232864 - optical_ophthalmic_axial_length_measurements_sequence = 2232869 - ultrasound_selected_ophthalmic_axial_length_sequence = 2232880 - ophthalmic_axial_length_selection_method_code_sequence = 2232912 - optical_selected_ophthalmic_axial_length_sequence = 2232917 - selected_segmental_ophthalmic_axial_length_sequence = 2232919 - selected_total_ophthalmic_axial_length_sequence = 2232928 - ophthalmic_axial_length_quality_metric_sequence = 2232930 - ophthalmic_axial_length_quality_metric_type_code_sequence = 2232933 - ophthalmic_axial_length_quality_metric_type_description = 2232947 - intraocular_lens_calculations_right_eye_sequence = 2233088 - intraocular_lens_calculations_left_eye_sequence = 2233104 - referenced_ophthalmic_axial_length_measurement_qc_image_sequence = 2233136 - ophthalmic_mapping_device_type = 2233365 - acquisition_method_code_sequence = 2233376 - acquisition_method_algorithm_sequence = 2233379 - ophthalmic_thickness_map_type_code_sequence = 2233398 - ophthalmic_thickness_mapping_normals_sequence = 2233411 - retinal_thickness_definition_code_sequence = 2233413 - pixel_value_mapping_to_coded_concept_sequence = 2233424 - mapped_pixel_value = 2233426 - pixel_value_mapping_explanation = 2233428 - ophthalmic_thickness_map_quality_threshold_sequence = 2233432 - ophthalmic_thickness_map_threshold_quality_rating = 2233440 - anatomic_structure_reference_point = 2233443 - registration_to_localizer_sequence = 2233445 - registered_localizer_units = 2233446 - registered_localizer_top_left_hand_corner = 2233447 - registered_localizer_bottom_right_hand_corner = 2233448 - ophthalmic_thickness_map_quality_rating_sequence = 2233456 - relevant_opt_attributes_sequence = 2233458 - transformation_method_code_sequence = 2233618 - transformation_algorithm_sequence = 2233619 - ophthalmic_axial_length_method = 2233621 - ophthalmic_fov = 2233623 - two_dimensional_to_three_dimensional_map_sequence = 2233624 - wide_field_ophthalmic_photography_quality_rating_sequence = 2233637 - wide_field_ophthalmic_photography_quality_threshold_sequence = 2233638 - wide_field_ophthalmic_photography_threshold_quality_rating = 2233639 - x_coordinates_center_pixel_view_angle = 2233640 - y_coordinates_center_pixel_view_angle = 2233641 - number_of_map_points = 2233648 - two_dimensional_to_three_dimensional_map_data = 2233649 - visual_field_horizontal_extent = 2359312 - visual_field_vertical_extent = 2359313 - visual_field_shape = 2359314 - screening_test_mode_code_sequence = 2359318 - maximum_stimulus_luminance = 2359320 - background_luminance = 2359328 - stimulus_color_code_sequence = 2359329 - background_illumination_color_code_sequence = 2359332 - stimulus_area = 2359333 - stimulus_presentation_time = 2359336 - fixation_sequence = 2359346 - fixation_monitoring_code_sequence = 2359347 - visual_field_catch_trial_sequence = 2359348 - fixation_checked_quantity = 2359349 - patient_not_properly_fixated_quantity = 2359350 - presented_visual_stimuli_data_flag = 2359351 - number_of_visual_stimuli = 2359352 - excessive_fixation_losses_data_flag = 2359353 - excessive_fixation_losses = 2359360 - stimuli_retesting_quantity = 2359362 - comments_on_patient_s_performance_of_visual_field = 2359364 - false_negatives_estimate_flag = 2359365 - false_negatives_estimate = 2359366 - negative_catch_trials_quantity = 2359368 - false_negatives_quantity = 2359376 - excessive_false_negatives_data_flag = 2359377 - excessive_false_negatives = 2359378 - false_positives_estimate_flag = 2359379 - false_positives_estimate = 2359380 - catch_trials_data_flag = 2359381 - positive_catch_trials_quantity = 2359382 - test_point_normals_data_flag = 2359383 - test_point_normals_sequence = 2359384 - global_deviation_probability_normals_flag = 2359385 - false_positives_quantity = 2359392 - excessive_false_positives_data_flag = 2359393 - excessive_false_positives = 2359394 - visual_field_test_normals_flag = 2359395 - results_normals_sequence = 2359396 - age_corrected_sensitivity_deviation_algorithm_sequence = 2359397 - global_deviation_from_normal = 2359398 - generalized_defect_sensitivity_deviation_algorithm_sequence = 2359399 - localized_deviation_from_normal = 2359400 - patient_reliability_indicator = 2359401 - visual_field_mean_sensitivity = 2359408 - global_deviation_probability = 2359409 - local_deviation_probability_normals_flag = 2359410 - localized_deviation_probability = 2359411 - short_term_fluctuation_calculated = 2359412 - short_term_fluctuation = 2359413 - short_term_fluctuation_probability_calculated = 2359414 - short_term_fluctuation_probability = 2359415 - corrected_localized_deviation_from_normal_calculated = 2359416 - corrected_localized_deviation_from_normal = 2359417 - corrected_localized_deviation_from_normal_probability_calculated = 2359424 - corrected_localized_deviation_from_normal_probability = 2359425 - global_deviation_probability_sequence = 2359427 - localized_deviation_probability_sequence = 2359429 - foveal_sensitivity_measured = 2359430 - foveal_sensitivity = 2359431 - visual_field_test_duration = 2359432 - visual_field_test_point_sequence = 2359433 - visual_field_test_point_x_coordinate = 2359440 - visual_field_test_point_y_coordinate = 2359441 - age_corrected_sensitivity_deviation_value = 2359442 - stimulus_results = 2359443 - sensitivity_value = 2359444 - retest_stimulus_seen = 2359445 - retest_sensitivity_value = 2359446 - visual_field_test_point_normals_sequence = 2359447 - quantified_defect = 2359448 - age_corrected_sensitivity_deviation_probability_value = 2359552 - generalized_defect_corrected_sensitivity_deviation_flag = 2359554 - generalized_defect_corrected_sensitivity_deviation_value = 2359555 - generalized_defect_corrected_sensitivity_deviation_probability_value = 2359556 - minimum_sensitivity_value = 2359557 - blind_spot_localized = 2359558 - blind_spot_x_coordinate = 2359559 - blind_spot_y_coordinate = 2359560 - visual_acuity_measurement_sequence = 2359568 - refractive_parameters_used_on_patient_sequence = 2359570 - measurement_laterality = 2359571 - ophthalmic_patient_clinical_information_left_eye_sequence = 2359572 - ophthalmic_patient_clinical_information_right_eye_sequence = 2359573 - foveal_point_normative_data_flag = 2359575 - foveal_point_probability_value = 2359576 - screening_baseline_measured = 2359584 - screening_baseline_measured_sequence = 2359586 - screening_baseline_type = 2359588 - screening_baseline_value = 2359590 - algorithm_source = 2359810 - data_set_name = 2360070 - data_set_version = 2360071 - data_set_source = 2360072 - data_set_description = 2360073 - visual_field_test_reliability_global_index_sequence = 2360087 - visual_field_global_results_index_sequence = 2360096 - data_observation_sequence = 2360101 - index_normals_flag = 2360120 - index_probability = 2360129 - index_probability_sequence = 2360132 - samples_per_pixel = 2621442 - samples_per_pixel_used = 2621443 - photometric_interpretation = 2621444 - image_dimensions = 2621445 - planar_configuration = 2621446 - number_of_frames = 2621448 - frame_increment_pointer = 2621449 - frame_dimension_pointer = 2621450 - rows = 2621456 - columns = 2621457 - planes = 2621458 - ultrasound_color_data_present = 2621460 - pixel_spacing = 2621488 - zoom_factor = 2621489 - zoom_center = 2621490 - pixel_aspect_ratio = 2621492 - image_format = 2621504 - manipulated_image = 2621520 - corrected_image = 2621521 - compression_recognition_code = 2621535 - compression_code = 2621536 - compression_originator = 2621537 - compression_label = 2621538 - compression_description = 2621539 - compression_sequence = 2621541 - compression_step_pointers = 2621542 - repeat_interval = 2621544 - bits_grouped = 2621545 - perimeter_table = 2621552 - perimeter_value = 2621553 - predictor_rows = 2621568 - predictor_columns = 2621569 - predictor_constants = 2621570 - blocked_pixels = 2621584 - block_rows = 2621585 - block_columns = 2621586 - row_overlap = 2621587 - column_overlap = 2621588 - bits_allocated = 2621696 - bits_stored = 2621697 - high_bit = 2621698 - pixel_representation = 2621699 - smallest_valid_pixel_value = 2621700 - largest_valid_pixel_value = 2621701 - smallest_image_pixel_value = 2621702 - largest_image_pixel_value = 2621703 - smallest_pixel_value_in_series = 2621704 - largest_pixel_value_in_series = 2621705 - smallest_image_pixel_value_in_plane = 2621712 - largest_image_pixel_value_in_plane = 2621713 - pixel_padding_value = 2621728 - pixel_padding_range_limit = 2621729 - float_pixel_padding_value = 2621730 - double_float_pixel_padding_value = 2621731 - float_pixel_padding_range_limit = 2621732 - double_float_pixel_padding_range_limit = 2621733 - image_location = 2621952 - quality_control_image = 2622208 - burned_in_annotation = 2622209 - recognizable_visual_features = 2622210 - longitudinal_temporal_information_modified = 2622211 - referenced_color_palette_instance_uid = 2622212 - transform_label = 2622464 - transform_version_number = 2622465 - number_of_transform_steps = 2622466 - sequence_of_compressed_data = 2622467 - details_of_coefficients = 2622468 - dct_label = 2623232 - data_block_description = 2623233 - data_block = 2623234 - normalization_factor_format = 2623248 - zonal_map_number_format = 2623264 - zonal_map_location = 2623265 - zonal_map_format = 2623266 - adaptive_map_format = 2623280 - code_number_format = 2623296 - pixel_spacing_calibration_type = 2624002 - pixel_spacing_calibration_description = 2624004 - pixel_intensity_relationship = 2625600 - pixel_intensity_relationship_sign = 2625601 - window_center = 2625616 - window_width = 2625617 - rescale_intercept = 2625618 - rescale_slope = 2625619 - rescale_type = 2625620 - window_center___width_explanation = 2625621 - voi_lut_function = 2625622 - gray_scale = 2625664 - recommended_viewing_mode = 2625680 - gray_lookup_table_descriptor = 2625792 - red_palette_color_lookup_table_descriptor = 2625793 - green_palette_color_lookup_table_descriptor = 2625794 - blue_palette_color_lookup_table_descriptor = 2625795 - alpha_palette_color_lookup_table_descriptor = 2625796 - large_red_palette_color_lookup_table_descriptor = 2625809 - large_green_palette_color_lookup_table_descriptor = 2625810 - large_blue_palette_color_lookup_table_descriptor = 2625811 - palette_color_lookup_table_uid = 2625945 - gray_lookup_table_data = 2626048 - red_palette_color_lookup_table_data = 2626049 - green_palette_color_lookup_table_data = 2626050 - blue_palette_color_lookup_table_data = 2626051 - alpha_palette_color_lookup_table_data = 2626052 - large_red_palette_color_lookup_table_data = 2626065 - large_green_palette_color_lookup_table_data = 2626066 - large_blue_palette_color_lookup_table_data = 2626067 - large_palette_color_lookup_table_uid = 2626068 - segmented_red_palette_color_lookup_table_data = 2626081 - segmented_green_palette_color_lookup_table_data = 2626082 - segmented_blue_palette_color_lookup_table_data = 2626083 - segmented_alpha_palette_color_lookup_table_data = 2626084 - breast_implant_present = 2626304 - partial_view = 2626384 - partial_view_description = 2626385 - partial_view_code_sequence = 2626386 - spatial_locations_preserved = 2626394 - data_frame_assignment_sequence = 2626561 - data_path_assignment = 2626562 - bits_mapped_to_color_lookup_table = 2626563 - blending_lut_1_sequence = 2626564 - blending_lut_1_transfer_function = 2626565 - blending_weight_constant = 2626566 - blending_lookup_table_descriptor = 2626567 - blending_lookup_table_data = 2626568 - enhanced_palette_color_lookup_table_sequence = 2626571 - blending_lut_2_sequence = 2626572 - blending_lut_2_transfer_function = 2626573 - data_path_id = 2626574 - rgb_lut_transfer_function = 2626575 - alpha_lut_transfer_function = 2626576 - icc_profile = 2629632 - color_space = 2629634 - lossy_image_compression_ = 2629904 - lossy_image_compression_ratio = 2629906 - lossy_image_compression_method = 2629908 - modality_lut_sequence = 2633728 - lut_descriptor = 2633730 - lut_explanation = 2633731 - modality_lut_type = 2633732 - lut_data = 2633734 - voi_lut_sequence = 2633744 - softcopy_voi_lut_sequence = 2634000 - image_presentation_comments = 2637824 - bi_plane_acquisition_sequence = 2641920 - representative_frame_number = 2646032 - frame_numbers_of_interest__foi_ = 2646048 - frame_of_interest_description = 2646050 - frame_of_interest_type = 2646051 - mask_pointer_s_ = 2646064 - r_wave_pointer = 2646080 - mask_subtraction_sequence = 2646272 - mask_operation = 2646273 - applicable_frame_range = 2646274 - mask_frame_numbers = 2646288 - contrast_frame_averaging = 2646290 - mask_sub_pixel_shift = 2646292 - tid_offset = 2646304 - mask_operation_explanation = 2646416 - equipment_administrator_sequence = 2650112 - number_of_display_subsystems = 2650113 - current_configuration_id = 2650114 - display_subsystem_id = 2650115 - display_subsystem_name = 2650116 - display_subsystem_description = 2650117 - system_status = 2650118 - system_status_comment = 2650119 - target_luminance_characteristics_sequence = 2650120 - luminance_characteristics_id = 2650121 - display_subsystem_configuration_sequence = 2650122 - configuration_id = 2650123 - configuration_name = 2650124 - configuration_description = 2650125 - referenced_target_luminance_characteristics_id = 2650126 - qa_results_sequence = 2650127 - display_subsystem_qa_results_sequence = 2650128 - configuration_qa_results_sequence = 2650129 - measurement_equipment_sequence = 2650130 - measurement_functions = 2650131 - measurement_equipment_type = 2650132 - visual_evaluation_result_sequence = 2650133 - display_calibration_result_sequence = 2650134 - ddl_value = 2650135 - ciexy_white_point = 2650136 - display_function_type = 2650137 - gamma_value = 2650138 - number_of_luminance_points = 2650139 - luminance_response_sequence = 2650140 - target_minimum_luminance = 2650141 - target_maximum_luminance = 2650142 - luminance_value = 2650143 - luminance_response_description = 2650144 - white_point_flag = 2650145 - display_device_type_code_sequence = 2650146 - display_subsystem_sequence = 2650147 - luminance_result_sequence = 2650148 - ambient_light_value_source = 2650149 - measured_characteristics = 2650150 - luminance_uniformity_result_sequence = 2650151 - visual_evaluation_test_sequence = 2650152 - test_result = 2650153 - test_result_comment = 2650154 - test_image_validation = 2650155 - test_pattern_code_sequence = 2650156 - measurement_pattern_code_sequence = 2650157 - visual_evaluation_method_code_sequence = 2650158 - pixel_data_provider_url = 2654176 - data_point_rows = 2658305 - data_point_columns = 2658306 - signal_domain_columns = 2658307 - largest_monochrome_pixel_value = 2658457 - data_representation = 2658568 - pixel_measures_sequence = 2658576 - frame_voi_lut_sequence = 2658610 - pixel_value_transformation_sequence = 2658629 - signal_domain_rows = 2658869 - display_filter_percentage = 2659345 - frame_pixel_shift_sequence = 2659349 - subtraction_item_id = 2659350 - pixel_intensity_relationship_lut_sequence = 2659362 - frame_pixel_data_properties_sequence = 2659395 - geometrical_properties = 2659396 - geometric_maximum_distortion = 2659397 - image_processing_applied = 2659398 - mask_selection_mode = 2659412 - lut_function = 2659444 - mask_visibility_percentage = 2659448 - pixel_shift_sequence = 2659585 - region_pixel_shift_sequence = 2659586 - vertices_of_the_region = 2659587 - multi_frame_presentation_sequence = 2659589 - pixel_shift_frame_range = 2659590 - lut_frame_range = 2659591 - image_to_equipment_mapping_matrix = 2659616 - equipment_coordinate_system_identification = 2659639 - study_status_id = 3276810 - study_priority_id = 3276812 - study_id_issuer = 3276818 - study_verified_date = 3276850 - study_verified_time = 3276851 - study_read_date = 3276852 - study_read_time = 3276853 - scheduled_study_start_date = 3280896 - scheduled_study_start_time = 3280897 - scheduled_study_stop_date = 3280912 - scheduled_study_stop_time = 3280913 - scheduled_study_location = 3280928 - scheduled_study_location_ae_title = 3280929 - reason_for_study = 3280944 - requesting_physician_identification_sequence = 3280945 - requesting_physician = 3280946 - requesting_service = 3280947 - requesting_service_code_sequence = 3280948 - study_arrival_date = 3280960 - study_arrival_time = 3280961 - study_completion_date = 3280976 - study_completion_time = 3280977 - study_component_status_id = 3280981 - requested_procedure_description = 3280992 - requested_procedure_code_sequence = 3280996 - requested_contrast_agent = 3281008 - study_comments = 3293184 - referenced_patient_alias_sequence = 3670020 - visit_status_id = 3670024 - admission_id = 3670032 - issuer_of_admission_id = 3670033 - issuer_of_admission_id_sequence = 3670036 - route_of_admissions = 3670038 - scheduled_admission_date = 3670042 - scheduled_admission_time = 3670043 - scheduled_discharge_date = 3670044 - scheduled_discharge_time = 3670045 - scheduled_patient_institution_residence = 3670046 - admitting_date = 3670048 - admitting_time = 3670049 - discharge_date = 3670064 - discharge_time = 3670066 - discharge_diagnosis_description = 3670080 - discharge_diagnosis_code_sequence = 3670084 - special_needs = 3670096 - service_episode_id = 3670112 - issuer_of_service_episode_id = 3670113 - service_episode_description = 3670114 - issuer_of_service_episode_id_sequence = 3670116 - pertinent_documents_sequence = 3670272 - pertinent_resources_sequence = 3670273 - resource_description = 3670274 - current_patient_location = 3670784 - patient_s_institution_residence = 3671040 - patient_state = 3671296 - patient_clinical_trial_participation_sequence = 3671298 - visit_comments = 3686400 - waveform_originality = 3801092 - number_of_waveform_channels = 3801093 - number_of_waveform_samples = 3801104 - sampling_frequency = 3801114 - multiplex_group_label = 3801120 - channel_definition_sequence = 3801600 - waveform_channel_number = 3801602 - channel_label = 3801603 - channel_status = 3801605 - channel_source_sequence = 3801608 - channel_source_modifiers_sequence = 3801609 - source_waveform_sequence = 3801610 - channel_derivation_description = 3801612 - channel_sensitivity = 3801616 - channel_sensitivity_units_sequence = 3801617 - channel_sensitivity_correction_factor = 3801618 - channel_baseline = 3801619 - channel_time_skew = 3801620 - channel_sample_skew = 3801621 - channel_offset = 3801624 - waveform_bits_stored = 3801626 - filter_low_frequency = 3801632 - filter_high_frequency = 3801633 - notch_filter_frequency = 3801634 - notch_filter_bandwidth = 3801635 - waveform_data_display_scale = 3801648 - waveform_display_background_cielab_value = 3801649 - waveform_presentation_group_sequence = 3801664 - presentation_group_number = 3801665 - channel_display_sequence = 3801666 - channel_recommended_display_cielab_value = 3801668 - channel_position = 3801669 - display_shading_flag = 3801670 - fractional_channel_display_scale = 3801671 - absolute_channel_display_scale = 3801672 - multiplexed_audio_channels_description_code_sequence = 3801856 - channel_identification_code = 3801857 - channel_mode = 3801858 - scheduled_station_ae_title = 4194305 - scheduled_procedure_step_start_date = 4194306 - scheduled_procedure_step_start_time = 4194307 - scheduled_procedure_step_end_date = 4194308 - scheduled_procedure_step_end_time = 4194309 - scheduled_performing_physician_s_name = 4194310 - scheduled_procedure_step_description = 4194311 - scheduled_protocol_code_sequence = 4194312 - scheduled_procedure_step_id = 4194313 - stage_code_sequence = 4194314 - scheduled_performing_physician_identification_sequence = 4194315 - scheduled_station_name = 4194320 - scheduled_procedure_step_location = 4194321 - pre_medication = 4194322 - scheduled_procedure_step_status = 4194336 - order_placer_identifier_sequence = 4194342 - order_filler_identifier_sequence = 4194343 - local_namespace_entity_id = 4194353 - universal_entity_id = 4194354 - universal_entity_id_type = 4194355 - identifier_type_code = 4194357 - assigning_facility_sequence = 4194358 - assigning_jurisdiction_code_sequence = 4194361 - assigning_agency_or_department_code_sequence = 4194362 - scheduled_procedure_step_sequence = 4194560 - referenced_non_image_composite_sop_instance_sequence = 4194848 - performed_station_ae_title = 4194881 - performed_station_name = 4194882 - performed_location = 4194883 - performed_procedure_step_start_date = 4194884 - performed_procedure_step_start_time = 4194885 - performed_procedure_step_end_date = 4194896 - performed_procedure_step_end_time = 4194897 - performed_procedure_step_status = 4194898 - performed_procedure_step_id = 4194899 - performed_procedure_step_description = 4194900 - performed_procedure_type_description = 4194901 - performed_protocol_code_sequence = 4194912 - performed_protocol_type = 4194913 - scheduled_step_attributes_sequence = 4194928 - request_attributes_sequence = 4194933 - comments_on_the_performed_procedure_step = 4194944 - performed_procedure_step_discontinuation_reason_code_sequence = 4194945 - quantity_sequence = 4194963 - quantity = 4194964 - measuring_units_sequence = 4194965 - billing_item_sequence = 4194966 - total_time_of_fluoroscopy = 4195072 - total_number_of_exposures = 4195073 - entrance_dose = 4195074 - exposed_area = 4195075 - distance_source_to_entrance = 4195078 - distance_source_to_support = 4195079 - exposure_dose_sequence = 4195086 - comments_on_radiation_dose = 4195088 - x_ray_output = 4195090 - half_value_layer = 4195092 - organ_dose = 4195094 - organ_exposed = 4195096 - billing_procedure_step_sequence = 4195104 - film_consumption_sequence = 4195105 - billing_supplies_and_devices_sequence = 4195108 - referenced_procedure_step_sequence = 4195120 - performed_series_sequence = 4195136 - comments_on_the_scheduled_procedure_step = 4195328 - protocol_context_sequence = 4195392 - content_item_modifier_sequence = 4195393 - scheduled_specimen_sequence = 4195584 - specimen_accession_number = 4195594 - container_identifier = 4195602 - issuer_of_the_container_identifier_sequence = 4195603 - alternate_container_identifier_sequence = 4195605 - container_type_code_sequence = 4195608 - container_description = 4195610 - container_component_sequence = 4195616 - specimen_sequence = 4195664 - specimen_identifier = 4195665 - specimen_description_sequence__trial_ = 4195666 - specimen_description__trial_ = 4195667 - specimen_uid = 4195668 - acquisition_context_sequence = 4195669 - acquisition_context_description = 4195670 - specimen_description_sequence = 4195680 - issuer_of_the_specimen_identifier_sequence = 4195682 - specimen_type_code_sequence = 4195738 - specimen_short_description = 4195840 - specimen_detailed_description = 4195842 - specimen_preparation_sequence = 4195856 - specimen_preparation_step_content_item_sequence = 4195858 - specimen_localization_content_item_sequence = 4195872 - slide_identifier = 4196090 - image_center_point_coordinates_sequence = 4196122 - x_offset_in_slide_coordinate_system = 4196138 - y_offset_in_slide_coordinate_system = 4196154 - z_offset_in_slide_coordinate_system = 4196170 - pixel_spacing_sequence = 4196568 - coordinate_system_axis_code_sequence = 4196570 - measurement_units_code_sequence = 4196586 - vital_stain_code_sequence__trial_ = 4196856 - requested_procedure_id = 4198401 - reason_for_the_requested_procedure = 4198402 - requested_procedure_priority = 4198403 - patient_transport_arrangements = 4198404 - requested_procedure_location = 4198405 - placer_order_number___procedure = 4198406 - filler_order_number___procedure = 4198407 - confidentiality_code = 4198408 - reporting_priority = 4198409 - reason_for_requested_procedure_code_sequence = 4198410 - names_of_intended_recipients_of_results = 4198416 - intended_recipients_of_results_identification_sequence = 4198417 - reason_for_performed_procedure_code_sequence = 4198418 - requested_procedure_description__trial_ = 4198496 - person_identification_code_sequence = 4198657 - person_s_address = 4198658 - person_s_telephone_numbers = 4198659 - person_s_telecom_information = 4198660 - requested_procedure_comments = 4199424 - reason_for_the_imaging_service_request = 4202497 - issue_date_of_imaging_service_request = 4202500 - issue_time_of_imaging_service_request = 4202501 - placer_order_number___imaging_service_request__retired_ = 4202502 - filler_order_number___imaging_service_request__retired_ = 4202503 - order_entered_by = 4202504 - order_enterer_s_location = 4202505 - order_callback_phone_number = 4202512 - order_callback_telecom_information = 4202513 - placer_order_number___imaging_service_request = 4202518 - filler_order_number___imaging_service_request = 4202519 - imaging_service_request_comments = 4203520 - confidentiality_constraint_on_patient_data_description = 4206593 - general_purpose_scheduled_procedure_step_status = 4210689 - general_purpose_performed_procedure_step_status = 4210690 - general_purpose_scheduled_procedure_step_priority = 4210691 - scheduled_processing_applications_code_sequence = 4210692 - scheduled_procedure_step_start_datetime = 4210693 - multiple_copies_flag = 4210694 - performed_processing_applications_code_sequence = 4210695 - human_performer_code_sequence = 4210697 - scheduled_procedure_step_modification_datetime = 4210704 - expected_completion_datetime = 4210705 - resulting_general_purpose_performed_procedure_steps_sequence = 4210709 - referenced_general_purpose_scheduled_procedure_step_sequence = 4210710 - scheduled_workitem_code_sequence = 4210712 - performed_workitem_code_sequence = 4210713 - input_availability_flag = 4210720 - input_information_sequence = 4210721 - relevant_information_sequence = 4210722 - referenced_general_purpose_scheduled_procedure_step_transaction_uid = 4210723 - scheduled_station_name_code_sequence = 4210725 - scheduled_station_class_code_sequence = 4210726 - scheduled_station_geographic_location_code_sequence = 4210727 - performed_station_name_code_sequence = 4210728 - performed_station_class_code_sequence = 4210729 - performed_station_geographic_location_code_sequence = 4210736 - requested_subsequent_workitem_code_sequence = 4210737 - non_dicom_output_code_sequence = 4210738 - output_information_sequence = 4210739 - scheduled_human_performers_sequence = 4210740 - actual_human_performers_sequence = 4210741 - human_performer_s_organization = 4210742 - human_performer_s_name = 4210743 - raw_data_handling = 4210752 - input_readiness_state = 4210753 - performed_procedure_step_start_datetime = 4210768 - performed_procedure_step_end_datetime = 4210769 - procedure_step_cancellation_datetime = 4210770 - output_destination_sequence = 4210800 - dicom_storage_sequence = 4210801 - stow_rs_storage_sequence = 4210802 - storage_url = 4210803 - xds_storage_sequence = 4210804 - entrance_dose_in_mgy = 4227842 - parametric_map_frame_type_sequence = 4231314 - referenced_image_real_world_value_mapping_sequence = 4231316 - real_world_value_mapping_sequence = 4231318 - pixel_value_mapping_code_sequence = 4231320 - lut_label = 4231696 - real_world_value_last_value_mapped = 4231697 - real_world_value_lut_data = 4231698 - double_float_real_world_value_last_value_mapped = 4231699 - double_float_real_world_value_first_value_mapped = 4231700 - real_world_value_first_value_mapped = 4231702 - quantity_definition_sequence = 4231712 - real_world_value_intercept = 4231716 - real_world_value_slope = 4231717 - findings_flag__trial_ = 4235271 - relationship_type = 4235280 - findings_sequence__trial_ = 4235296 - findings_group_uid__trial_ = 4235297 - referenced_findings_group_uid__trial_ = 4235298 - findings_group_recording_date__trial_ = 4235299 - findings_group_recording_time__trial_ = 4235300 - findings_source_category_code_sequence__trial_ = 4235302 - verifying_organization = 4235303 - documenting_organization_identifier_code_sequence__trial_ = 4235304 - verification_datetime = 4235312 - observation_datetime = 4235314 - value_type = 4235328 - concept_name_code_sequence = 4235331 - measurement_precision_description__trial_ = 4235335 - continuity_of_content = 4235344 - urgency_or_priority_alerts__trial_ = 4235351 - sequencing_indicator__trial_ = 4235360 - document_identifier_code_sequence__trial_ = 4235366 - document_author__trial_ = 4235367 - document_author_identifier_code_sequence__trial_ = 4235368 - identifier_code_sequence__trial_ = 4235376 - verifying_observer_sequence = 4235379 - object_binary_identifier__trial_ = 4235380 - verifying_observer_name = 4235381 - documenting_observer_identifier_code_sequence__trial_ = 4235382 - author_observer_sequence = 4235384 - participant_sequence = 4235386 - custodial_organization_sequence = 4235388 - participation_type = 4235392 - participation_datetime = 4235394 - observer_type = 4235396 - procedure_identifier_code_sequence__trial_ = 4235397 - verifying_observer_identification_code_sequence = 4235400 - object_directory_binary_identifier__trial_ = 4235401 - equivalent_cda_document_sequence = 4235408 - referenced_waveform_channels = 4235440 - date_of_document_or_verbal_transaction__trial_ = 4235536 - time_of_document_creation_or_verbal_transaction__trial_ = 4235538 - datetime = 4235552 - date = 4235553 - time = 4235554 - person_name = 4235555 - uid = 4235556 - report_status_id__trial_ = 4235557 - temporal_range_type = 4235568 - referenced_sample_positions = 4235570 - referenced_frame_numbers = 4235574 - referenced_time_offsets = 4235576 - referenced_datetime = 4235578 - text_value = 4235616 - floating_point_value = 4235617 - rational_numerator_value = 4235618 - rational_denominator_value = 4235619 - observation_category_code_sequence__trial_ = 4235623 - concept_code_sequence = 4235624 - bibliographic_citation__trial_ = 4235626 - purpose_of_reference_code_sequence = 4235632 - observation_uid = 4235633 - referenced_observation_uid__trial_ = 4235634 - referenced_observation_class__trial_ = 4235635 - referenced_object_observation_class__trial_ = 4235636 - annotation_group_number = 4235648 - observation_date__trial_ = 4235666 - observation_time__trial_ = 4235667 - measurement_automation__trial_ = 4235668 - modifier_code_sequence = 4235669 - identification_description__trial_ = 4235812 - coordinates_set_geometric_type__trial_ = 4235920 - algorithm_code_sequence__trial_ = 4235926 - algorithm_description__trial_ = 4235927 - pixel_coordinates_set__trial_ = 4235930 - measured_value_sequence = 4236032 - numeric_value_qualifier_code_sequence = 4236033 - current_observer__trial_ = 4236039 - numeric_value = 4236042 - referenced_accession_sequence__trial_ = 4236051 - report_status_comment__trial_ = 4236090 - procedure_context_sequence__trial_ = 4236096 - verbal_source__trial_ = 4236114 - address__trial_ = 4236115 - telephone_number__trial_ = 4236116 - verbal_source_identifier_code_sequence__trial_ = 4236120 - predecessor_documents_sequence = 4236128 - referenced_request_sequence = 4236144 - performed_procedure_code_sequence = 4236146 - current_requested_procedure_evidence_sequence = 4236149 - report_detail_sequence__trial_ = 4236160 - pertinent_other_evidence_sequence = 4236165 - hl7_structured_document_reference_sequence = 4236176 - observation_subject_uid__trial_ = 4236290 - observation_subject_class__trial_ = 4236291 - observation_subject_type_code_sequence__trial_ = 4236292 - completion_flag = 4236433 - completion_flag_description = 4236434 - verification_flag = 4236435 - archive_requested = 4236436 - preliminary_flag = 4236438 - content_template_sequence = 4236548 - identical_documents_sequence = 4236581 - observation_subject_context_flag__trial_ = 4236800 - observer_context_flag__trial_ = 4236801 - procedure_context_flag__trial_ = 4236803 - content_sequence = 4237104 - relationship_sequence__trial_ = 4237105 - relationship_type_code_sequence__trial_ = 4237106 - language_code_sequence__trial_ = 4237124 - uniform_resource_locator__trial_ = 4237714 - waveform_annotation_sequence = 4239392 - template_identifier = 4250368 - template_version = 4250374 - template_local_version = 4250375 - template_extension_flag = 4250379 - template_extension_organization_uid = 4250380 - template_extension_creator_uid = 4250381 - referenced_content_item_identifier = 4250483 - hl7_instance_identifier = 4251649 - hl7_document_effective_time = 4251652 - hl7_document_type_code_sequence = 4251654 - document_class_code_sequence = 4251656 - retrieve_uri = 4251664 - retrieve_location_uid = 4251665 - type_of_instances = 4251680 - dicom_retrieval_sequence = 4251681 - dicom_media_retrieval_sequence = 4251682 - wado_retrieval_sequence = 4251683 - xds_retrieval_sequence = 4251684 - wado_rs_retrieval_sequence = 4251685 - repository_unique_id = 4251696 - home_community_id = 4251697 - document_title = 4325392 - encapsulated_document = 4325393 - mime_type_of_encapsulated_document = 4325394 - source_instance_sequence = 4325395 - list_of_mime_types = 4325396 - product_package_identifier = 4456449 - substance_administration_approval = 4456450 - approval_status_further_description = 4456451 - approval_status_datetime = 4456452 - product_type_code_sequence = 4456455 - product_name = 4456456 - product_description = 4456457 - product_lot_identifier = 4456458 - product_expiration_datetime = 4456459 - substance_administration_datetime = 4456464 - substance_administration_notes = 4456465 - substance_administration_device_id = 4456466 - product_parameter_sequence = 4456467 - substance_administration_parameter_sequence = 4456473 - lens_description = 4587538 - right_lens_sequence = 4587540 - left_lens_sequence = 4587541 - unspecified_laterality_lens_sequence = 4587542 - cylinder_sequence = 4587544 - prism_sequence = 4587560 - horizontal_prism_power = 4587568 - horizontal_prism_base = 4587570 - vertical_prism_power = 4587572 - vertical_prism_base = 4587574 - lens_segment_type = 4587576 - optical_transmittance = 4587584 - channel_width = 4587586 - pupil_size = 4587588 - corneal_size = 4587590 - autorefraction_right_eye_sequence = 4587600 - autorefraction_left_eye_sequence = 4587602 - distance_pupillary_distance = 4587616 - near_pupillary_distance = 4587618 - intermediate_pupillary_distance = 4587619 - other_pupillary_distance = 4587620 - keratometry_right_eye_sequence = 4587632 - keratometry_left_eye_sequence = 4587633 - steep_keratometric_axis_sequence = 4587636 - radius_of_curvature = 4587637 - keratometric_power = 4587638 - keratometric_axis = 4587639 - flat_keratometric_axis_sequence = 4587648 - background_color = 4587666 - optotype = 4587668 - optotype_presentation = 4587669 - subjective_refraction_right_eye_sequence = 4587671 - subjective_refraction_left_eye_sequence = 4587672 - add_near_sequence = 4587776 - add_intermediate_sequence = 4587777 - add_other_sequence = 4587778 - add_power = 4587780 - viewing_distance = 4587782 - visual_acuity_type_code_sequence = 4587809 - visual_acuity_right_eye_sequence = 4587810 - visual_acuity_left_eye_sequence = 4587811 - visual_acuity_both_eyes_open_sequence = 4587812 - viewing_distance_type = 4587813 - visual_acuity_modifiers = 4587829 - decimal_visual_acuity = 4587831 - optotype_detailed_definition = 4587833 - referenced_refractive_measurements_sequence = 4587845 - sphere_power = 4587846 - cylinder_power = 4587847 - corneal_topography_surface = 4588033 - corneal_vertex_location = 4588034 - pupil_centroid_x_coordinate = 4588035 - pupil_centroid_y_coordinate = 4588036 - equivalent_pupil_radius = 4588037 - corneal_topography_map_type_code_sequence = 4588039 - vertices_of_the_outline_of_pupil = 4588040 - corneal_topography_mapping_normals_sequence = 4588048 - maximum_corneal_curvature_sequence = 4588049 - maximum_corneal_curvature = 4588050 - maximum_corneal_curvature_location = 4588051 - minimum_keratometric_sequence = 4588053 - simulated_keratometric_cylinder_sequence = 4588056 - average_corneal_power = 4588064 - corneal_i_s_value = 4588068 - analyzed_area = 4588071 - surface_regularity_index = 4588080 - surface_asymmetry_index = 4588082 - corneal_eccentricity_index = 4588084 - keratoconus_prediction_index = 4588086 - decimal_potential_visual_acuity = 4588088 - corneal_topography_map_quality_evaluation = 4588098 - source_image_corneal_processed_data_sequence = 4588100 - corneal_point_location = 4588103 - corneal_point_estimated = 4588104 - axial_power = 4588105 - tangential_power = 4588112 - refractive_power = 4588113 - relative_elevation = 4588114 - corneal_wavefront = 4588115 - imaged_volume_width = 4718593 - imaged_volume_height = 4718594 - imaged_volume_depth = 4718595 - total_pixel_matrix_columns = 4718598 - total_pixel_matrix_rows = 4718599 - total_pixel_matrix_origin_sequence = 4718600 - specimen_label_in_image = 4718608 - focus_method = 4718609 - extended_depth_of_field = 4718610 - number_of_focal_planes = 4718611 - distance_between_focal_planes = 4718612 - recommended_absent_pixel_cielab_value = 4718613 - illuminator_type_code_sequence = 4718848 - image_orientation__slide_ = 4718850 - optical_path_sequence = 4718853 - optical_path_identifier = 4718854 - optical_path_description = 4718855 - illumination_color_code_sequence = 4718856 - specimen_reference_sequence = 4718864 - condenser_lens_power = 4718865 - objective_lens_power = 4718866 - objective_lens_numerical_aperture = 4718867 - palette_color_lookup_table_sequence = 4718880 - referenced_image_navigation_sequence = 4719104 - top_left_hand_corner_of_localizer_area = 4719105 - bottom_right_hand_corner_of_localizer_area = 4719106 - optical_path_identification_sequence = 4719111 - plane_position__slide__sequence = 4719130 - column_position_in_total_image_pixel_matrix = 4719134 - row_position_in_total_image_pixel_matrix = 4719135 - pixel_origin_interpretation = 4719361 - calibration_image = 5242884 - device_sequence = 5242896 - container_component_type_code_sequence = 5242898 - container_component_thickness = 5242899 - device_length = 5242900 - container_component_width = 5242901 - device_diameter = 5242902 - device_diameter_units = 5242903 - device_volume = 5242904 - inter_marker_distance = 5242905 - container_component_material = 5242906 - container_component_id = 5242907 - container_component_length = 5242908 - container_component_diameter = 5242909 - container_component_description = 5242910 - device_description = 5242912 - contrast_bolus_ingredient_percent_by_volume = 5373953 - oct_focal_distance = 5373954 - beam_spot_size = 5373955 - effective_refractive_index = 5373956 - oct_acquisition_domain = 5373958 - oct_optical_center_wavelength = 5373959 - axial_resolution = 5373960 - ranging_depth = 5373961 - a_line_rate = 5373969 - a_lines_per_frame = 5373970 - catheter_rotational_rate = 5373971 - a_line_pixel_spacing = 5373972 - mode_of_percutaneous_access_sequence = 5373974 - intravascular_oct_frame_type_sequence = 5373989 - oct_z_offset_applied = 5373990 - intravascular_frame_content_sequence = 5373991 - intravascular_longitudinal_distance = 5373992 - intravascular_oct_frame_content_sequence = 5373993 - oct_z_offset_correction = 5374000 - catheter_direction_of_rotation = 5374001 - seam_line_location = 5374003 - first_a_line_location = 5374004 - seam_line_index = 5374006 - number_of_padded_a_lines = 5374008 - interpolation_type = 5374009 - refractive_index_applied = 5374010 - energy_window_vector = 5505040 - number_of_energy_windows = 5505041 - energy_window_information_sequence = 5505042 - energy_window_range_sequence = 5505043 - energy_window_lower_limit = 5505044 - energy_window_upper_limit = 5505045 - radiopharmaceutical_information_sequence = 5505046 - residual_syringe_counts = 5505047 - energy_window_name = 5505048 - detector_vector = 5505056 - number_of_detectors = 5505057 - detector_information_sequence = 5505058 - phase_vector = 5505072 - number_of_phases = 5505073 - phase_information_sequence = 5505074 - number_of_frames_in_phase = 5505075 - phase_delay = 5505078 - pause_between_frames = 5505080 - phase_description = 5505081 - rotation_vector = 5505104 - number_of_rotations = 5505105 - rotation_information_sequence = 5505106 - number_of_frames_in_rotation = 5505107 - r_r_interval_vector = 5505120 - number_of_r_r_intervals = 5505121 - gated_information_sequence = 5505122 - data_information_sequence = 5505123 - time_slot_vector = 5505136 - number_of_time_slots = 5505137 - time_slot_information_sequence = 5505138 - time_slot_time = 5505139 - slice_vector = 5505152 - number_of_slices = 5505153 - angular_view_vector = 5505168 - time_slice_vector = 5505280 - number_of_time_slices = 5505281 - start_angle = 5505536 - type_of_detector_motion = 5505538 - trigger_vector = 5505552 - number_of_triggers_in_phase = 5505553 - view_code_sequence = 5505568 - view_modifier_code_sequence = 5505570 - radionuclide_code_sequence = 5505792 - administration_route_code_sequence = 5505794 - radiopharmaceutical_code_sequence = 5505796 - calibration_data_sequence = 5505798 - energy_window_number = 5505800 - image_id = 5506048 - patient_orientation_code_sequence = 5506064 - patient_orientation_modifier_code_sequence = 5506066 - patient_gantry_relationship_code_sequence = 5506068 - slice_progression_direction = 5506304 - scan_progression_direction = 5506305 - series_type = 5509120 - units = 5509121 - counts_source = 5509122 - reprojection_method = 5509124 - suv_type = 5509126 - randoms_correction_method = 5509376 - attenuation_correction_method = 5509377 - decay_correction = 5509378 - reconstruction_method = 5509379 - detector_lines_of_response_used = 5509380 - scatter_correction_method = 5509381 - axial_acceptance = 5509632 - axial_mash = 5509633 - transverse_mash = 5509634 - detector_element_size = 5509635 - coincidence_window_width = 5509648 - secondary_counts_type = 5509664 - frame_reference_time = 5509888 - primary__prompts__counts_accumulated = 5509904 - secondary_counts_accumulated = 5509905 - slice_sensitivity_factor = 5509920 - decay_factor = 5509921 - dose_calibration_factor = 5509922 - scatter_fraction_factor = 5509923 - dead_time_factor = 5509924 - image_index = 5509936 - counts_included = 5510144 - dead_time_correction_flag = 5510145 - histogram_sequence = 6303744 - histogram_number_of_bins = 6303746 - histogram_first_bin_value = 6303748 - histogram_last_bin_value = 6303750 - histogram_bin_width = 6303752 - histogram_explanation = 6303760 - histogram_data = 6303776 - segmentation_type = 6422529 - segment_sequence = 6422530 - segmented_property_category_code_sequence = 6422531 - segment_number = 6422532 - segment_label = 6422533 - segment_description = 6422534 - segment_algorithm_type = 6422536 - segment_algorithm_name = 6422537 - segment_identification_sequence = 6422538 - referenced_segment_number = 6422539 - recommended_display_grayscale_value = 6422540 - recommended_display_cielab_value = 6422541 - maximum_fractional_value = 6422542 - segmented_property_type_code_sequence = 6422543 - segmentation_fractional_type = 6422544 - segmented_property_type_modifier_code_sequence = 6422545 - used_segments_sequence = 6422546 - tracking_id = 6422560 - tracking_uid = 6422561 - deformable_registration_sequence = 6553602 - source_frame_of_reference_uid = 6553603 - deformable_registration_grid_sequence = 6553605 - grid_dimensions = 6553607 - grid_resolution = 6553608 - vector_grid_data = 6553609 - pre_deformation_matrix_registration_sequence = 6553615 - post_deformation_matrix_registration_sequence = 6553616 - number_of_surfaces = 6684673 - surface_sequence = 6684674 - surface_number = 6684675 - surface_comments = 6684676 - surface_processing = 6684681 - surface_processing_ratio = 6684682 - surface_processing_description = 6684683 - recommended_presentation_opacity = 6684684 - recommended_presentation_type = 6684685 - finite_volume = 6684686 - manifold = 6684688 - surface_points_sequence = 6684689 - surface_points_normals_sequence = 6684690 - surface_mesh_primitives_sequence = 6684691 - number_of_surface_points = 6684693 - point_coordinates_data = 6684694 - point_position_accuracy = 6684695 - mean_point_distance = 6684696 - maximum_point_distance = 6684697 - points_bounding_box_coordinates = 6684698 - axis_of_rotation = 6684699 - center_of_rotation = 6684700 - number_of_vectors = 6684702 - vector_dimensionality = 6684703 - vector_accuracy = 6684704 - vector_coordinate_data = 6684705 - triangle_point_index_list = 6684707 - edge_point_index_list = 6684708 - vertex_point_index_list = 6684709 - triangle_strip_sequence = 6684710 - triangle_fan_sequence = 6684711 - line_sequence = 6684712 - primitive_point_index_list = 6684713 - surface_count = 6684714 - referenced_surface_sequence = 6684715 - referenced_surface_number = 6684716 - segment_surface_generation_algorithm_identification_sequence = 6684717 - segment_surface_source_instance_sequence = 6684718 - algorithm_family_code_sequence = 6684719 - algorithm_name_code_sequence = 6684720 - algorithm_version = 6684721 - algorithm_parameters = 6684722 - facet_sequence = 6684724 - surface_processing_algorithm_identification_sequence = 6684725 - algorithm_name = 6684726 - recommended_point_radius = 6684727 - recommended_line_thickness = 6684728 - long_primitive_point_index_list = 6684736 - long_triangle_point_index_list = 6684737 - long_edge_point_index_list = 6684738 - long_vertex_point_index_list = 6684739 - track_set_sequence = 6684929 - track_sequence = 6684930 - recommended_display_cielab_value_list = 6684931 - tracking_algorithm_identification_sequence = 6684932 - track_set_number = 6684933 - track_set_label = 6684934 - track_set_description = 6684935 - track_set_anatomical_type_code_sequence = 6684936 - measurements_sequence = 6684961 - track_set_statistics_sequence = 6684964 - floating_point_values = 6684965 - track_point_index_list = 6684969 - track_statistics_sequence = 6684976 - measurement_values_sequence = 6684978 - diffusion_acquisition_code_sequence = 6684979 - diffusion_model_code_sequence = 6684980 - implant_size = 6840848 - implant_template_version = 6840865 - replaced_implant_template_sequence = 6840866 - implant_type = 6840867 - derivation_implant_template_sequence = 6840868 - original_implant_template_sequence = 6840869 - effective_datetime = 6840870 - implant_target_anatomy_sequence = 6840880 - information_from_manufacturer_sequence = 6840928 - notification_from_manufacturer_sequence = 6840933 - information_issue_datetime = 6840944 - information_summary = 6840960 - implant_regulatory_disapproval_code_sequence = 6840992 - overall_template_spatial_tolerance = 6840997 - hpgl_document_sequence = 6841024 - hpgl_document_id = 6841040 - hpgl_document_label = 6841045 - view_orientation_code_sequence = 6841056 - view_orientation_modifier = 6841072 - hpgl_document_scaling = 6841074 - hpgl_document = 6841088 - hpgl_contour_pen_number = 6841104 - hpgl_pen_sequence = 6841120 - hpgl_pen_number = 6841136 - hpgl_pen_label = 6841152 - hpgl_pen_description = 6841157 - recommended_rotation_point = 6841158 - bounding_rectangle = 6841159 - implant_template_3d_model_surface_number = 6841168 - surface_model_description_sequence = 6841184 - surface_model_label = 6841216 - surface_model_scaling_factor = 6841232 - materials_code_sequence = 6841248 - coating_materials_code_sequence = 6841252 - implant_type_code_sequence = 6841256 - fixation_method_code_sequence = 6841260 - mating_feature_sets_sequence = 6841264 - mating_feature_set_id = 6841280 - mating_feature_set_label = 6841296 - mating_feature_sequence = 6841312 - mating_feature_id = 6841328 - mating_feature_degree_of_freedom_sequence = 6841344 - degree_of_freedom_id = 6841360 - degree_of_freedom_type = 6841376 - tag_2d_mating_feature_coordinates_sequence = 6841392 - referenced_hpgl_document_id = 6841408 - tag_2d_mating_point = 6841424 - tag_2d_mating_axes = 6841440 - tag_2d_degree_of_freedom_sequence = 6841456 - tag_3d_degree_of_freedom_axis = 6841488 - range_of_freedom = 6841504 - tag_3d_mating_point = 6841536 - tag_3d_mating_axes = 6841552 - tag_2d_degree_of_freedom_axis = 6841584 - planning_landmark_point_sequence = 6841600 - planning_landmark_line_sequence = 6841616 - planning_landmark_plane_sequence = 6841632 - planning_landmark_id = 6841648 - planning_landmark_description = 6841664 - planning_landmark_identification_code_sequence = 6841669 - tag_2d_point_coordinates_sequence = 6841680 - tag_2d_point_coordinates = 6841696 - tag_3d_point_coordinates = 6841744 - tag_2d_line_coordinates_sequence = 6841760 - tag_2d_line_coordinates = 6841776 - tag_3d_line_coordinates = 6841808 - tag_2d_plane_coordinates_sequence = 6841824 - tag_2d_plane_intersection = 6841840 - tag_3d_plane_origin = 6841872 - tag_3d_plane_normal = 6841888 - graphic_annotation_sequence = 7340033 - graphic_layer = 7340034 - bounding_box_annotation_units = 7340035 - anchor_point_annotation_units = 7340036 - graphic_annotation_units = 7340037 - unformatted_text_value = 7340038 - text_object_sequence = 7340040 - graphic_object_sequence = 7340041 - bounding_box_top_left_hand_corner = 7340048 - bounding_box_bottom_right_hand_corner = 7340049 - bounding_box_text_horizontal_justification = 7340050 - anchor_point = 7340052 - anchor_point_visibility = 7340053 - graphic_dimensions = 7340064 - number_of_graphic_points = 7340065 - graphic_data = 7340066 - graphic_type = 7340067 - graphic_filled = 7340068 - image_rotation__retired_ = 7340096 - image_horizontal_flip = 7340097 - image_rotation = 7340098 - displayed_area_top_left_hand_corner__trial_ = 7340112 - displayed_area_bottom_right_hand_corner__trial_ = 7340113 - displayed_area_top_left_hand_corner = 7340114 - displayed_area_bottom_right_hand_corner = 7340115 - displayed_area_selection_sequence = 7340122 - graphic_layer_sequence = 7340128 - graphic_layer_order = 7340130 - graphic_layer_recommended_display_grayscale_value = 7340134 - graphic_layer_recommended_display_rgb_value = 7340135 - graphic_layer_description = 7340136 - content_label = 7340160 - content_description = 7340161 - presentation_creation_date = 7340162 - presentation_creation_time = 7340163 - content_creator_s_name = 7340164 - content_creator_s_identification_code_sequence = 7340166 - alternate_content_description_sequence = 7340167 - presentation_size_mode = 7340288 - presentation_pixel_spacing = 7340289 - presentation_pixel_aspect_ratio = 7340290 - presentation_pixel_magnification_ratio = 7340291 - graphic_group_label = 7340551 - graphic_group_description = 7340552 - compound_graphic_sequence = 7340553 - compound_graphic_instance_id = 7340582 - font_name = 7340583 - font_name_type = 7340584 - css_font_name = 7340585 - rotation_angle = 7340592 - text_style_sequence = 7340593 - line_style_sequence = 7340594 - fill_style_sequence = 7340595 - graphic_group_sequence = 7340596 - text_color_cielab_value = 7340609 - horizontal_alignment = 7340610 - vertical_alignment = 7340611 - shadow_style = 7340612 - shadow_offset_x = 7340613 - shadow_offset_y = 7340614 - shadow_color_cielab_value = 7340615 - underlined = 7340616 - bold = 7340617 - italic = 7340624 - pattern_on_color_cielab_value = 7340625 - pattern_off_color_cielab_value = 7340626 - line_thickness = 7340627 - line_dashing_style = 7340628 - line_pattern = 7340629 - fill_pattern = 7340630 - fill_mode = 7340631 - shadow_opacity = 7340632 - gap_length = 7340641 - diameter_of_visibility = 7340642 - rotation_point = 7340659 - tick_alignment = 7340660 - show_tick_label = 7340664 - tick_label_alignment = 7340665 - compound_graphic_units = 7340674 - pattern_on_opacity = 7340676 - pattern_off_opacity = 7340677 - major_ticks_sequence = 7340679 - tick_position = 7340680 - tick_label = 7340681 - compound_graphic_type = 7340692 - graphic_group_id = 7340693 - shape_type = 7340806 - registration_sequence = 7340808 - matrix_registration_sequence = 7340809 - matrix_sequence = 7340810 - frame_of_reference_to_displayed_coordinate_system_transformation_matrix = 7340811 - frame_of_reference_transformation_matrix_type = 7340812 - registration_type_code_sequence = 7340813 - fiducial_description = 7340815 - fiducial_identifier = 7340816 - fiducial_identifier_code_sequence = 7340817 - contour_uncertainty_radius = 7340818 - used_fiducials_sequence = 7340820 - graphic_coordinates_data_sequence = 7340824 - fiducial_uid = 7340826 - fiducial_set_sequence = 7340828 - fiducial_sequence = 7340830 - graphic_layer_recommended_display_cielab_value = 7341057 - blending_sequence = 7341058 - relative_opacity = 7341059 - referenced_spatial_registration_sequence = 7341060 - blending_position = 7341061 - presentation_display_collection_uid = 7344385 - presentation_sequence_collection_uid = 7344386 - presentation_sequence_position_index = 7344387 - rendered_image_reference_sequence = 7344388 - volumetric_presentation_state_input_sequence = 7344641 - presentation_input_type = 7344642 - input_sequence_position_index = 7344643 - crop = 7344644 - cropping_specification_index = 7344645 - compositing_method = 7344646 - volumetric_presentation_input_number = 7344647 - image_volume_geometry = 7344648 - volume_cropping_sequence = 7344897 - volume_cropping_method = 7344898 - bounding_box_crop = 7344899 - oblique_cropping_plane_sequence = 7344900 - plane = 7344901 - plane_normal = 7344902 - cropping_specification_number = 7344905 - multi_planar_reconstruction_style = 7345409 - mpr_thickness_type = 7345410 - mpr_slab_thickness = 7345411 - mpr_top_left_hand_corner = 7345413 - mpr_view_width_direction = 7345415 - mpr_view_width = 7345416 - number_of_volumetric_curve_points = 7345420 - volumetric_curve_points = 7345421 - mpr_view_height_direction = 7345425 - mpr_view_height = 7345426 - presentation_state_classification_component_sequence = 7346177 - component_type = 7346178 - component_input_sequence = 7346179 - volumetric_presentation_input_index = 7346180 - presentation_state_compositor_component_sequence = 7346181 - weighting_transfer_function_sequence = 7346182 - weighting_lookup_table_descriptor = 7346183 - weighting_lookup_table_data = 7346184 - volumetric_annotation_sequence = 7346433 - referenced_structured_context_sequence = 7346435 - referenced_content_item = 7346436 - volumetric_presentation_input_annotation_sequence = 7346437 - annotation_clipping = 7346439 - presentation_animation_style = 7346689 - recommended_animation_rate = 7346691 - animation_curve_sequence = 7346692 - animation_step_size = 7346693 - hanging_protocol_name = 7471106 - hanging_protocol_description = 7471108 - hanging_protocol_level = 7471110 - hanging_protocol_creator = 7471112 - hanging_protocol_creation_datetime = 7471114 - hanging_protocol_definition_sequence = 7471116 - hanging_protocol_user_identification_code_sequence = 7471118 - hanging_protocol_user_group_name = 7471120 - source_hanging_protocol_sequence = 7471122 - number_of_priors_referenced = 7471124 - image_sets_sequence = 7471136 - image_set_selector_sequence = 7471138 - image_set_selector_usage_flag = 7471140 - selector_attribute = 7471142 - selector_value_number = 7471144 - time_based_image_sets_sequence = 7471152 - image_set_number = 7471154 - image_set_selector_category = 7471156 - relative_time = 7471160 - relative_time_units = 7471162 - abstract_prior_value = 7471164 - abstract_prior_code_sequence = 7471166 - image_set_label = 7471168 - selector_attribute_vr = 7471184 - selector_sequence_pointer = 7471186 - selector_sequence_pointer_private_creator = 7471188 - selector_attribute_private_creator = 7471190 - selector_ae_value = 7471198 - selector_as_value = 7471199 - selector_at_value = 7471200 - selector_da_value = 7471201 - selector_cs_value = 7471202 - selector_dt_value = 7471203 - selector_is_value = 7471204 - selector_ob_value = 7471205 - selector_lo_value = 7471206 - selector_of_value = 7471207 - selector_lt_value = 7471208 - selector_ow_value = 7471209 - selector_pn_value = 7471210 - selector_tm_value = 7471211 - selector_sh_value = 7471212 - selector_un_value = 7471213 - selector_st_value = 7471214 - selector_uc_value = 7471215 - selector_ut_value = 7471216 - selector_ur_value = 7471217 - selector_ds_value = 7471218 - selector_od_value = 7471219 - selector_fd_value = 7471220 - selector_ol_value = 7471221 - selector_fl_value = 7471222 - selector_ul_value = 7471224 - selector_us_value = 7471226 - selector_sl_value = 7471228 - selector_ss_value = 7471230 - selector_ui_value = 7471231 - selector_code_sequence_value = 7471232 - number_of_screens = 7471360 - nominal_screen_definition_sequence = 7471362 - number_of_vertical_pixels = 7471364 - number_of_horizontal_pixels = 7471366 - display_environment_spatial_position = 7471368 - screen_minimum_grayscale_bit_depth = 7471370 - screen_minimum_color_bit_depth = 7471372 - application_maximum_repaint_time = 7471374 - display_sets_sequence = 7471616 - display_set_number = 7471618 - display_set_label = 7471619 - display_set_presentation_group = 7471620 - display_set_presentation_group_description = 7471622 - partial_data_display_handling = 7471624 - synchronized_scrolling_sequence = 7471632 - display_set_scrolling_group = 7471634 - navigation_indicator_sequence = 7471636 - navigation_display_set = 7471638 - reference_display_sets = 7471640 - image_boxes_sequence = 7471872 - image_box_number = 7471874 - image_box_layout_type = 7471876 - image_box_tile_horizontal_dimension = 7471878 - image_box_tile_vertical_dimension = 7471880 - image_box_scroll_direction = 7471888 - image_box_small_scroll_type = 7471890 - image_box_small_scroll_amount = 7471892 - image_box_large_scroll_type = 7471894 - image_box_large_scroll_amount = 7471896 - image_box_overlap_priority = 7471904 - cine_relative_to_real_time = 7471920 - filter_operations_sequence = 7472128 - filter_by_category = 7472130 - filter_by_attribute_presence = 7472132 - filter_by_operator = 7472134 - structured_display_background_cielab_value = 7472160 - empty_image_box_cielab_value = 7472161 - structured_display_image_box_sequence = 7472162 - structured_display_text_box_sequence = 7472164 - referenced_first_frame_sequence = 7472167 - image_box_synchronization_sequence = 7472176 - synchronized_image_box_list = 7472178 - type_of_synchronization = 7472180 - blending_operation_type = 7472384 - reformatting_operation_type = 7472400 - reformatting_thickness = 7472402 - reformatting_interval = 7472404 - reformatting_operation_initial_view_direction = 7472406 - tag_3d_rendering_type = 7472416 - sorting_operations_sequence = 7472640 - sort_by_category = 7472642 - sorting_direction = 7472644 - display_set_patient_orientation = 7472896 - voi_type = 7472898 - pseudo_color_type = 7472900 - pseudo_color_palette_instance_reference_sequence = 7472901 - show_grayscale_inverted = 7472902 - show_image_true_size_flag = 7472912 - show_graphic_annotation_flag = 7472914 - show_patient_demographics_flag = 7472916 - show_acquisition_techniques_flag = 7472918 - display_set_horizontal_justification = 7472919 - display_set_vertical_justification = 7472920 - continuation_start_meterset = 7602464 - continuation_end_meterset = 7602465 - procedure_step_state = 7606272 - procedure_step_progress_information_sequence = 7606274 - procedure_step_progress = 7606276 - procedure_step_progress_description = 7606278 - procedure_step_communications_uri_sequence = 7606280 - contact_uri = 7606282 - contact_display_name = 7606284 - procedure_step_discontinuation_reason_code_sequence = 7606286 - beam_task_sequence = 7606304 - beam_task_type = 7606306 - beam_order_index__trial_ = 7606308 - autosequence_flag = 7606309 - table_top_vertical_adjusted_position = 7606310 - table_top_longitudinal_adjusted_position = 7606311 - table_top_lateral_adjusted_position = 7606312 - patient_support_adjusted_angle = 7606314 - table_top_eccentric_adjusted_angle = 7606315 - table_top_pitch_adjusted_angle = 7606316 - table_top_roll_adjusted_angle = 7606317 - delivery_verification_image_sequence = 7606320 - verification_image_timing = 7606322 - double_exposure_flag = 7606324 - double_exposure_ordering = 7606326 - double_exposure_meterset__trial_ = 7606328 - double_exposure_field_delta__trial_ = 7606330 - related_reference_rt_image_sequence = 7606336 - general_machine_verification_sequence = 7606338 - conventional_machine_verification_sequence = 7606340 - ion_machine_verification_sequence = 7606342 - failed_attributes_sequence = 7606344 - overridden_attributes_sequence = 7606346 - conventional_control_point_verification_sequence = 7606348 - ion_control_point_verification_sequence = 7606350 - attribute_occurrence_sequence = 7606352 - attribute_occurrence_pointer = 7606354 - attribute_item_selector = 7606356 - attribute_occurrence_private_creator = 7606358 - selector_sequence_pointer_items = 7606359 - scheduled_procedure_step_priority = 7606784 - worklist_label = 7606786 - procedure_step_label = 7606788 - scheduled_processing_parameters_sequence = 7606800 - performed_processing_parameters_sequence = 7606802 - unified_procedure_step_performed_procedure_sequence = 7606806 - related_procedure_step_sequence = 7606816 - procedure_step_relationship_type = 7606818 - replaced_procedure_step_sequence = 7606820 - deletion_lock = 7606832 - receiving_ae = 7606836 - requesting_ae = 7606838 - reason_for_cancellation = 7606840 - scp_status = 7606850 - subscription_list_status = 7606852 - unified_procedure_step_list_status = 7606854 - beam_order_index = 7607076 - double_exposure_meterset = 7607096 - double_exposure_field_delta = 7607098 - brachy_task_sequence = 7607297 - continuation_start_total_reference_air_kerma = 7607298 - continuation_end_total_reference_air_kerma = 7607299 - continuation_pulse_number = 7607300 - channel_delivery_order_sequence = 7607301 - referenced_channel_number = 7607302 - start_cumulative_time_weight = 7607303 - end_cumulative_time_weight = 7607304 - omitted_channel_sequence = 7607305 - reason_for_channel_omission = 7607306 - reason_for_channel_omission_description = 7607307 - channel_delivery_order_index = 7607308 - channel_delivery_continuation_sequence = 7607309 - omitted_application_setup_sequence = 7607310 - implant_assembly_template_name = 7733249 - implant_assembly_template_issuer = 7733251 - implant_assembly_template_version = 7733254 - replaced_implant_assembly_template_sequence = 7733256 - implant_assembly_template_type = 7733258 - original_implant_assembly_template_sequence = 7733260 - derivation_implant_assembly_template_sequence = 7733262 - implant_assembly_template_target_anatomy_sequence = 7733264 - procedure_type_code_sequence = 7733280 - surgical_technique = 7733296 - component_types_sequence = 7733298 - component_type_code_sequence = 7733300 - exclusive_component_type = 7733302 - mandatory_component_type = 7733304 - component_sequence = 7733312 - component_id = 7733333 - component_assembly_sequence = 7733344 - component_1_referenced_id = 7733360 - component_1_referenced_mating_feature_set_id = 7733376 - component_1_referenced_mating_feature_id = 7733392 - component_2_referenced_id = 7733408 - component_2_referenced_mating_feature_set_id = 7733424 - component_2_referenced_mating_feature_id = 7733440 - implant_template_group_name = 7864321 - implant_template_group_description = 7864336 - implant_template_group_issuer = 7864352 - implant_template_group_version = 7864356 - replaced_implant_template_group_sequence = 7864358 - implant_template_group_target_anatomy_sequence = 7864360 - implant_template_group_members_sequence = 7864362 - implant_template_group_member_id = 7864366 - tag_3d_implant_template_group_member_matching_point = 7864400 - tag_3d_implant_template_group_member_matching_axes = 7864416 - implant_template_group_member_matching_2d_coordinates_sequence = 7864432 - tag_2d_implant_template_group_member_matching_point = 7864464 - tag_2d_implant_template_group_member_matching_axes = 7864480 - implant_template_group_variation_dimension_sequence = 7864496 - implant_template_group_variation_dimension_name = 7864498 - implant_template_group_variation_dimension_rank_sequence = 7864500 - referenced_implant_template_group_member_id = 7864502 - implant_template_group_variation_dimension_rank = 7864504 - surface_scan_acquisition_type_code_sequence = 8388609 - surface_scan_mode_code_sequence = 8388610 - registration_method_code_sequence = 8388611 - shot_duration_time = 8388612 - shot_offset_time = 8388613 - surface_point_presentation_value_data = 8388614 - surface_point_color_cielab_value_data = 8388615 - uv_mapping_sequence = 8388616 - texture_label = 8388617 - u_value_data = 8388624 - v_value_data = 8388625 - referenced_texture_sequence = 8388626 - referenced_surface_data_sequence = 8388627 - assessment_summary = 8519681 - assessment_summary_description = 8519683 - assessed_sop_instance_sequence = 8519684 - referenced_comparison_sop_instance_sequence = 8519685 - number_of_assessment_observations = 8519686 - assessment_observations_sequence = 8519687 - observation_significance = 8519688 - observation_description = 8519690 - structured_constraint_observation_sequence = 8519692 - assessed_attribute_value_sequence = 8519696 - assessment_set_id = 8519702 - assessment_requester_sequence = 8519703 - selector_attribute_name = 8519704 - selector_attribute_keyword = 8519705 - assessment_type_code_sequence = 8519713 - observation_basis_code_sequence = 8519714 - assessment_label = 8519715 - constraint_type = 8519730 - specification_selection_guidance = 8519731 - constraint_value_sequence = 8519732 - recommended_default_value_sequence = 8519733 - constraint_violation_significance = 8519734 - constraint_violation_condition = 8519735 - storage_media_file_set_id = 8913200 - storage_media_file_set_uid = 8913216 - icon_image_sequence = 8913408 - topic_title = 8915204 - topic_subject = 8915206 - topic_author = 8915216 - topic_keywords = 8915218 - sop_instance_status = 16778256 - sop_authorization_datetime = 16778272 - sop_authorization_comment = 16778276 - authorization_equipment_certification_number = 16778278 - mac_id_number = 67108869 - mac_calculation_transfer_syntax_uid = 67108880 - mac_algorithm = 67108885 - data_elements_signed = 67108896 - digital_signature_uid = 67109120 - digital_signature_datetime = 67109125 - certificate_type = 67109136 - certificate_of_signer = 67109141 - signature = 67109152 - certified_timestamp_type = 67109637 - certified_timestamp = 67109648 - digital_signature_purpose_code_sequence = 67109889 - referenced_digital_signature_sequence = 67109890 - referenced_sop_instance_mac_sequence = 67109891 - mac = 67109892 - encrypted_attributes_sequence = 67110144 - encrypted_content_transfer_syntax_uid = 67110160 - encrypted_content = 67110176 - modified_attributes_sequence = 67110224 - original_attributes_sequence = 67110241 - attribute_modification_datetime = 67110242 - modifying_system = 67110243 - source_of_previous_values = 67110244 - reason_for_the_attribute_modification = 67110245 - number_of_copies = 536870928 - printer_configuration_sequence = 536870942 - print_priority = 536870944 - medium_type = 536870960 - film_destination = 536870976 - film_session_label = 536870992 - memory_allocation = 536871008 - maximum_memory_allocation = 536871009 - color_image_printing_flag = 536871010 - collation_flag = 536871011 - annotation_flag = 536871013 - image_overlay_flag = 536871015 - presentation_lut_flag = 536871017 - image_box_presentation_lut_flag = 536871018 - memory_bit_depth = 536871072 - printing_bit_depth = 536871073 - media_installed_sequence = 536871074 - other_media_available_sequence = 536871076 - supported_image_display_formats_sequence = 536871080 - referenced_film_box_sequence = 536872192 - referenced_stored_print_sequence = 536872208 - image_display_format = 537919504 - annotation_display_format_id = 537919536 - film_orientation = 537919552 - film_size_id = 537919568 - printer_resolution_id = 537919570 - default_printer_resolution_id = 537919572 - magnification_type = 537919584 - smoothing_type = 537919616 - default_magnification_type = 537919654 - other_magnification_types_available = 537919655 - default_smoothing_type = 537919656 - other_smoothing_types_available = 537919657 - border_density = 537919744 - empty_image_density = 537919760 - min_density = 537919776 - max_density = 537919792 - trim = 537919808 - configuration_information = 537919824 - configuration_information_description = 537919826 - maximum_collated_films = 537919828 - illumination = 537919838 - reflected_ambient_light = 537919840 - printer_pixel_spacing = 537920374 - referenced_film_session_sequence = 537920768 - referenced_image_box_sequence = 537920784 - referenced_basic_annotation_box_sequence = 537920800 - image_box_position = 538968080 - polarity = 538968096 - requested_image_size = 538968112 - requested_decimate_crop_behavior = 538968128 - requested_resolution_id = 538968144 - requested_image_size_flag = 538968224 - decimate_crop_result = 538968226 - basic_grayscale_image_sequence = 538968336 - basic_color_image_sequence = 538968337 - referenced_image_overlay_box_sequence = 538968368 - referenced_voi_lut_box_sequence = 538968384 - annotation_position = 540016656 - text_string = 540016672 - referenced_overlay_plane_sequence = 541065232 - referenced_overlay_plane_groups = 541065233 - overlay_pixel_data_sequence = 541065248 - overlay_magnification_type = 541065312 - overlay_smoothing_type = 541065328 - overlay_or_image_magnification = 541065330 - magnify_to_number_of_columns = 541065332 - overlay_foreground_density = 541065344 - overlay_background_density = 541065346 - overlay_mode = 541065360 - threshold_density = 541065472 - referenced_image_box_sequence__retired_ = 541066496 - presentation_lut_sequence = 542113808 - presentation_lut_shape = 542113824 - referenced_presentation_lut_sequence = 542115072 - print_job_id = 553648144 - execution_status = 553648160 - execution_status_info = 553648176 - creation_date = 553648192 - creation_time = 553648208 - originator = 553648240 - destination_ae = 553648448 - owner_id = 553648480 - number_of_films = 553648496 - referenced_print_job_sequence__pull_stored_print_ = 553649408 - printer_status = 554696720 - printer_status_info = 554696736 - printer_name = 554696752 - print_queue_id = 554696857 - queue_status = 555745296 - print_job_description_sequence = 555745360 - referenced_print_job_sequence = 555745392 - print_management_capabilities_sequence = 556793872 - printer_characteristics_sequence = 556793877 - film_box_content_sequence = 556793904 - image_box_content_sequence = 556793920 - annotation_content_sequence = 556793936 - image_overlay_box_content_sequence = 556793952 - presentation_lut_content_sequence = 556793984 - proposed_study_sequence = 556794016 - original_image_sequence = 556794048 - label_using_information_extracted_from_instances = 570425345 - label_text = 570425346 - label_style_selection = 570425347 - media_disposition = 570425348 - barcode_value = 570425349 - barcode_symbology = 570425350 - allow_media_splitting = 570425351 - include_non_dicom_objects = 570425352 - include_display_application = 570425353 - preserve_composite_instances_after_media_creation = 570425354 - total_number_of_pieces_of_media_created = 570425355 - requested_media_application_profile = 570425356 - referenced_storage_media_sequence = 570425357 - failure_attributes = 570425358 - allow_lossy_compression = 570425359 - request_priority = 570425376 - rt_image_label = 805437442 - rt_image_name = 805437443 - rt_image_description = 805437444 - reported_values_origin = 805437450 - rt_image_plane = 805437452 - x_ray_image_receptor_translation = 805437453 - x_ray_image_receptor_angle = 805437454 - rt_image_orientation = 805437456 - image_plane_pixel_spacing = 805437457 - rt_image_position = 805437458 - radiation_machine_name = 805437472 - radiation_machine_sad = 805437474 - radiation_machine_ssd = 805437476 - rt_image_sid = 805437478 - source_to_reference_object_distance = 805437480 - fraction_number = 805437481 - exposure_sequence = 805437488 - meterset_exposure = 805437490 - diaphragm_position = 805437492 - fluence_map_sequence = 805437504 - fluence_data_source = 805437505 - fluence_data_scale = 805437506 - primary_fluence_mode_sequence = 805437520 - fluence_mode = 805437521 - fluence_mode_id = 805437522 - dvh_type = 805568513 - dose_units = 805568514 - dose_type = 805568516 - spatial_transform_of_dose = 805568517 - dose_comment = 805568518 - normalization_point = 805568520 - dose_summation_type = 805568522 - grid_frame_offset_vector = 805568524 - dose_grid_scaling = 805568526 - rt_dose_roi_sequence = 805568528 - dose_value = 805568530 - tissue_heterogeneity_correction = 805568532 - dvh_normalization_point = 805568576 - dvh_normalization_dose_value = 805568578 - dvh_sequence = 805568592 - dvh_dose_scaling = 805568594 - dvh_volume_units = 805568596 - dvh_number_of_bins = 805568598 - dvh_data = 805568600 - dvh_referenced_roi_sequence = 805568608 - dvh_roi_contribution_type = 805568610 - dvh_minimum_dose = 805568624 - dvh_maximum_dose = 805568626 - dvh_mean_dose = 805568628 - structure_set_label = 805699586 - structure_set_name = 805699588 - structure_set_description = 805699590 - structure_set_date = 805699592 - structure_set_time = 805699593 - referenced_frame_of_reference_sequence = 805699600 - rt_referenced_study_sequence = 805699602 - rt_referenced_series_sequence = 805699604 - contour_image_sequence = 805699606 - predecessor_structure_set_sequence = 805699608 - structure_set_roi_sequence = 805699616 - roi_number = 805699618 - referenced_frame_of_reference_uid = 805699620 - roi_name = 805699622 - roi_description = 805699624 - roi_display_color = 805699626 - roi_volume = 805699628 - rt_related_roi_sequence = 805699632 - rt_roi_relationship = 805699635 - roi_generation_algorithm = 805699638 - roi_generation_description = 805699640 - roi_contour_sequence = 805699641 - contour_sequence = 805699648 - contour_geometric_type = 805699650 - contour_slab_thickness = 805699652 - contour_offset_vector = 805699653 - number_of_contour_points = 805699654 - contour_number = 805699656 - attached_contours = 805699657 - contour_data = 805699664 - rt_roi_observations_sequence = 805699712 - observation_number = 805699714 - referenced_roi_number = 805699716 - roi_observation_label = 805699717 - rt_roi_identification_code_sequence = 805699718 - roi_observation_description = 805699720 - related_rt_roi_observations_sequence = 805699744 - rt_roi_interpreted_type = 805699748 - roi_interpreter = 805699750 - roi_physical_properties_sequence = 805699760 - roi_physical_property = 805699762 - roi_physical_property_value = 805699764 - roi_elemental_composition_sequence = 805699766 - roi_elemental_composition_atomic_number = 805699767 - roi_elemental_composition_atomic_mass_fraction = 805699768 - additional_rt_roi_identification_code_sequence = 805699769 - frame_of_reference_relationship_sequence = 805699776 - related_frame_of_reference_uid = 805699778 - frame_of_reference_transformation_type = 805699780 - frame_of_reference_transformation_matrix = 805699782 - frame_of_reference_transformation_comment = 805699784 - measured_dose_reference_sequence = 805830672 - measured_dose_description = 805830674 - measured_dose_type = 805830676 - measured_dose_value = 805830678 - treatment_session_beam_sequence = 805830688 - treatment_session_ion_beam_sequence = 805830689 - current_fraction_number = 805830690 - treatment_control_point_date = 805830692 - treatment_control_point_time = 805830693 - treatment_termination_status = 805830698 - treatment_termination_code = 805830699 - treatment_verification_status = 805830700 - referenced_treatment_record_sequence = 805830704 - specified_primary_meterset = 805830706 - specified_secondary_meterset = 805830707 - delivered_primary_meterset = 805830710 - delivered_secondary_meterset = 805830711 - specified_treatment_time = 805830714 - delivered_treatment_time = 805830715 - control_point_delivery_sequence = 805830720 - ion_control_point_delivery_sequence = 805830721 - specified_meterset = 805830722 - delivered_meterset = 805830724 - meterset_rate_set = 805830725 - meterset_rate_delivered = 805830726 - scan_spot_metersets_delivered = 805830727 - dose_rate_delivered = 805830728 - treatment_summary_calculated_dose_reference_sequence = 805830736 - cumulative_dose_to_dose_reference = 805830738 - first_treatment_date = 805830740 - most_recent_treatment_date = 805830742 - number_of_fractions_delivered = 805830746 - override_sequence = 805830752 - parameter_sequence_pointer = 805830753 - override_parameter_pointer = 805830754 - parameter_item_index = 805830755 - measured_dose_reference_number = 805830756 - parameter_pointer = 805830757 - override_reason = 805830758 - corrected_parameter_sequence = 805830760 - correction_value = 805830762 - calculated_dose_reference_sequence = 805830768 - calculated_dose_reference_number = 805830770 - calculated_dose_reference_description = 805830772 - calculated_dose_reference_dose_value = 805830774 - start_meterset = 805830776 - end_meterset = 805830778 - referenced_measured_dose_reference_sequence = 805830784 - referenced_measured_dose_reference_number = 805830786 - referenced_calculated_dose_reference_sequence = 805830800 - referenced_calculated_dose_reference_number = 805830802 - beam_limiting_device_leaf_pairs_sequence = 805830816 - recorded_wedge_sequence = 805830832 - recorded_compensator_sequence = 805830848 - recorded_block_sequence = 805830864 - treatment_summary_measured_dose_reference_sequence = 805830880 - recorded_snout_sequence = 805830896 - recorded_range_shifter_sequence = 805830898 - recorded_lateral_spreading_device_sequence = 805830900 - recorded_range_modulator_sequence = 805830902 - recorded_source_sequence = 805830912 - source_serial_number = 805830917 - treatment_session_application_setup_sequence = 805830928 - application_setup_check = 805830934 - recorded_brachy_accessory_device_sequence = 805830944 - referenced_brachy_accessory_device_number = 805830946 - recorded_channel_sequence = 805830960 - specified_channel_total_time = 805830962 - delivered_channel_total_time = 805830964 - specified_number_of_pulses = 805830966 - delivered_number_of_pulses = 805830968 - specified_pulse_repetition_interval = 805830970 - delivered_pulse_repetition_interval = 805830972 - recorded_source_applicator_sequence = 805830976 - referenced_source_applicator_number = 805830978 - recorded_channel_shield_sequence = 805830992 - referenced_channel_shield_number = 805830994 - brachy_control_point_delivered_sequence = 805831008 - safe_position_exit_date = 805831010 - safe_position_exit_time = 805831012 - safe_position_return_date = 805831014 - safe_position_return_time = 805831016 - pulse_specific_brachy_control_point_delivered_sequence = 805831025 - pulse_number = 805831026 - brachy_pulse_control_point_delivered_sequence = 805831027 - current_treatment_status = 805831168 - treatment_status_comment = 805831170 - fraction_group_summary_sequence = 805831200 - referenced_fraction_number = 805831203 - fraction_group_type = 805831204 - beam_stopper_position = 805831216 - fraction_status_summary_sequence = 805831232 - treatment_date = 805831248 - treatment_time = 805831249 - rt_plan_label = 805961730 - rt_plan_name = 805961731 - rt_plan_description = 805961732 - rt_plan_date = 805961734 - rt_plan_time = 805961735 - treatment_protocols = 805961737 - plan_intent = 805961738 - treatment_sites = 805961739 - rt_plan_geometry = 805961740 - prescription_description = 805961742 - dose_reference_sequence = 805961744 - dose_reference_number = 805961746 - dose_reference_uid = 805961747 - dose_reference_structure_type = 805961748 - nominal_beam_energy_unit = 805961749 - dose_reference_description = 805961750 - dose_reference_point_coordinates = 805961752 - nominal_prior_dose = 805961754 - dose_reference_type = 805961760 - constraint_weight = 805961761 - delivery_warning_dose = 805961762 - delivery_maximum_dose = 805961763 - target_minimum_dose = 805961765 - target_prescription_dose = 805961766 - target_maximum_dose = 805961767 - target_underdose_volume_fraction = 805961768 - organ_at_risk_full_volume_dose = 805961770 - organ_at_risk_limit_dose = 805961771 - organ_at_risk_maximum_dose = 805961772 - organ_at_risk_overdose_volume_fraction = 805961773 - tolerance_table_sequence = 805961792 - tolerance_table_number = 805961794 - tolerance_table_label = 805961795 - gantry_angle_tolerance = 805961796 - beam_limiting_device_angle_tolerance = 805961798 - beam_limiting_device_tolerance_sequence = 805961800 - beam_limiting_device_position_tolerance = 805961802 - snout_position_tolerance = 805961803 - patient_support_angle_tolerance = 805961804 - table_top_eccentric_angle_tolerance = 805961806 - table_top_pitch_angle_tolerance = 805961807 - table_top_roll_angle_tolerance = 805961808 - table_top_vertical_position_tolerance = 805961809 - table_top_longitudinal_position_tolerance = 805961810 - table_top_lateral_position_tolerance = 805961811 - rt_plan_relationship = 805961813 - fraction_group_sequence = 805961840 - fraction_group_number = 805961841 - fraction_group_description = 805961842 - number_of_fractions_planned = 805961848 - number_of_fraction_pattern_digits_per_day = 805961849 - repeat_fraction_cycle_length = 805961850 - fraction_pattern = 805961851 - number_of_beams = 805961856 - beam_dose_specification_point = 805961858 - beam_dose = 805961860 - beam_meterset = 805961862 - beam_dose_point_depth = 805961864 - beam_dose_point_equivalent_depth = 805961865 - beam_dose_point_ssd = 805961866 - beam_dose_meaning = 805961867 - beam_dose_verification_control_point_sequence = 805961868 - average_beam_dose_point_depth = 805961869 - average_beam_dose_point_equivalent_depth = 805961870 - average_beam_dose_point_ssd = 805961871 - beam_dose_type = 805961872 - alternate_beam_dose = 805961873 - alternate_beam_dose_type = 805961874 - number_of_brachy_application_setups = 805961888 - brachy_application_setup_dose_specification_point = 805961890 - brachy_application_setup_dose = 805961892 - beam_sequence = 805961904 - treatment_machine_name = 805961906 - primary_dosimeter_unit = 805961907 - source_axis_distance = 805961908 - beam_limiting_device_sequence = 805961910 - rt_beam_limiting_device_type = 805961912 - source_to_beam_limiting_device_distance = 805961914 - isocenter_to_beam_limiting_device_distance = 805961915 - number_of_leaf_jaw_pairs = 805961916 - leaf_position_boundaries = 805961918 - beam_number = 805961920 - beam_name = 805961922 - beam_description = 805961923 - beam_type = 805961924 - beam_delivery_duration_limit = 805961925 - radiation_type = 805961926 - high_dose_technique_type = 805961927 - reference_image_number = 805961928 - planned_verification_image_sequence = 805961930 - imaging_device_specific_acquisition_parameters = 805961932 - treatment_delivery_type = 805961934 - number_of_wedges = 805961936 - wedge_sequence = 805961937 - wedge_number = 805961938 - wedge_type = 805961939 - wedge_id = 805961940 - wedge_angle = 805961941 - wedge_factor = 805961942 - total_wedge_tray_water_equivalent_thickness = 805961943 - wedge_orientation = 805961944 - isocenter_to_wedge_tray_distance = 805961945 - source_to_wedge_tray_distance = 805961946 - wedge_thin_edge_position = 805961947 - bolus_id = 805961948 - bolus_description = 805961949 - effective_wedge_angle = 805961950 - number_of_compensators = 805961952 - material_id = 805961953 - total_compensator_tray_factor = 805961954 - compensator_sequence = 805961955 - compensator_number = 805961956 - compensator_id = 805961957 - source_to_compensator_tray_distance = 805961958 - compensator_rows = 805961959 - compensator_columns = 805961960 - compensator_pixel_spacing = 805961961 - compensator_position = 805961962 - compensator_transmission_data = 805961963 - compensator_thickness_data = 805961964 - number_of_boli = 805961965 - compensator_type = 805961966 - compensator_tray_id = 805961967 - number_of_blocks = 805961968 - total_block_tray_factor = 805961970 - total_block_tray_water_equivalent_thickness = 805961971 - block_sequence = 805961972 - block_tray_id = 805961973 - source_to_block_tray_distance = 805961974 - isocenter_to_block_tray_distance = 805961975 - block_type = 805961976 - accessory_code = 805961977 - block_divergence = 805961978 - block_mounting_position = 805961979 - block_number = 805961980 - block_name = 805961982 - block_thickness = 805961984 - block_transmission = 805961986 - block_number_of_points = 805961988 - block_data = 805961990 - applicator_sequence = 805961991 - applicator_id = 805961992 - applicator_type = 805961993 - applicator_description = 805961994 - cumulative_dose_reference_coefficient = 805961996 - final_cumulative_meterset_weight = 805961998 - number_of_control_points = 805962000 - control_point_sequence = 805962001 - control_point_index = 805962002 - nominal_beam_energy = 805962004 - dose_rate_set = 805962005 - wedge_position_sequence = 805962006 - wedge_position = 805962008 - beam_limiting_device_position_sequence = 805962010 - leaf_jaw_positions = 805962012 - gantry_angle = 805962014 - gantry_rotation_direction = 805962015 - beam_limiting_device_angle = 805962016 - beam_limiting_device_rotation_direction = 805962017 - patient_support_angle = 805962018 - patient_support_rotation_direction = 805962019 - table_top_eccentric_axis_distance = 805962020 - table_top_eccentric_angle = 805962021 - table_top_eccentric_rotation_direction = 805962022 - table_top_vertical_position = 805962024 - table_top_longitudinal_position = 805962025 - table_top_lateral_position = 805962026 - isocenter_position = 805962028 - surface_entry_point = 805962030 - source_to_surface_distance = 805962032 - average_beam_dose_point_source_to_external_contour_distance = 805962033 - source_to_external_contour_distance = 805962034 - external_contour_entry_point = 805962035 - cumulative_meterset_weight = 805962036 - table_top_pitch_angle = 805962048 - table_top_pitch_rotation_direction = 805962050 - table_top_roll_angle = 805962052 - table_top_roll_rotation_direction = 805962054 - head_fixation_angle = 805962056 - gantry_pitch_angle = 805962058 - gantry_pitch_rotation_direction = 805962060 - gantry_pitch_angle_tolerance = 805962062 - fixation_eye = 805962064 - chair_head_frame_position = 805962065 - head_fixation_angle_tolerance = 805962066 - chair_head_frame_position_tolerance = 805962067 - fixation_light_azimuthal_angle_tolerance = 805962068 - fixation_light_polar_angle_tolerance = 805962069 - patient_setup_sequence = 805962112 - patient_setup_number = 805962114 - patient_setup_label = 805962115 - patient_additional_position = 805962116 - fixation_device_sequence = 805962128 - fixation_device_type = 805962130 - fixation_device_label = 805962132 - fixation_device_description = 805962134 - fixation_device_position = 805962136 - fixation_device_pitch_angle = 805962137 - fixation_device_roll_angle = 805962138 - shielding_device_sequence = 805962144 - shielding_device_type = 805962146 - shielding_device_label = 805962148 - shielding_device_description = 805962150 - shielding_device_position = 805962152 - setup_technique = 805962160 - setup_technique_description = 805962162 - setup_device_sequence = 805962164 - setup_device_type = 805962166 - setup_device_label = 805962168 - setup_device_description = 805962170 - setup_device_parameter = 805962172 - setup_reference_description = 805962192 - table_top_vertical_setup_displacement = 805962194 - table_top_longitudinal_setup_displacement = 805962196 - table_top_lateral_setup_displacement = 805962198 - brachy_treatment_technique = 805962240 - brachy_treatment_type = 805962242 - treatment_machine_sequence = 805962246 - source_sequence = 805962256 - source_number = 805962258 - source_type = 805962260 - source_manufacturer = 805962262 - active_source_diameter = 805962264 - active_source_length = 805962266 - source_model_id = 805962267 - source_description = 805962268 - source_encapsulation_nominal_thickness = 805962274 - source_encapsulation_nominal_transmission = 805962276 - source_isotope_name = 805962278 - source_isotope_half_life = 805962280 - source_strength_units = 805962281 - reference_air_kerma_rate = 805962282 - source_strength = 805962283 - source_strength_reference_date = 805962284 - source_strength_reference_time = 805962286 - application_setup_sequence = 805962288 - application_setup_type = 805962290 - application_setup_number = 805962292 - application_setup_name = 805962294 - application_setup_manufacturer = 805962296 - template_number = 805962304 - template_type = 805962306 - template_name = 805962308 - total_reference_air_kerma = 805962320 - brachy_accessory_device_sequence = 805962336 - brachy_accessory_device_number = 805962338 - brachy_accessory_device_id = 805962339 - brachy_accessory_device_type = 805962340 - brachy_accessory_device_name = 805962342 - brachy_accessory_device_nominal_thickness = 805962346 - brachy_accessory_device_nominal_transmission = 805962348 - channel_sequence = 805962368 - channel_number = 805962370 - channel_length = 805962372 - channel_total_time = 805962374 - source_movement_type = 805962376 - number_of_pulses = 805962378 - pulse_repetition_interval = 805962380 - source_applicator_number = 805962384 - source_applicator_id = 805962385 - source_applicator_type = 805962386 - source_applicator_name = 805962388 - source_applicator_length = 805962390 - source_applicator_manufacturer = 805962392 - source_applicator_wall_nominal_thickness = 805962396 - source_applicator_wall_nominal_transmission = 805962398 - source_applicator_step_size = 805962400 - transfer_tube_number = 805962402 - transfer_tube_length = 805962404 - channel_shield_sequence = 805962416 - channel_shield_number = 805962418 - channel_shield_id = 805962419 - channel_shield_name = 805962420 - channel_shield_nominal_thickness = 805962424 - channel_shield_nominal_transmission = 805962426 - final_cumulative_time_weight = 805962440 - brachy_control_point_sequence = 805962448 - control_point_relative_position = 805962450 - control_point_3d_position = 805962452 - cumulative_time_weight = 805962454 - compensator_divergence = 805962464 - compensator_mounting_position = 805962465 - source_to_compensator_distance = 805962466 - total_compensator_tray_water_equivalent_thickness = 805962467 - isocenter_to_compensator_tray_distance = 805962468 - compensator_column_offset = 805962469 - isocenter_to_compensator_distances = 805962470 - compensator_relative_stopping_power_ratio = 805962471 - compensator_milling_tool_diameter = 805962472 - ion_range_compensator_sequence = 805962474 - compensator_description = 805962475 - radiation_mass_number = 805962498 - radiation_atomic_number = 805962500 - radiation_charge_state = 805962502 - scan_mode = 805962504 - modulated_scan_mode_type = 805962505 - virtual_source_axis_distances = 805962506 - snout_sequence = 805962508 - snout_position = 805962509 - snout_id = 805962511 - number_of_range_shifters = 805962514 - range_shifter_sequence = 805962516 - range_shifter_number = 805962518 - range_shifter_id = 805962520 - range_shifter_type = 805962528 - range_shifter_description = 805962530 - number_of_lateral_spreading_devices = 805962544 - lateral_spreading_device_sequence = 805962546 - lateral_spreading_device_number = 805962548 - lateral_spreading_device_id = 805962550 - lateral_spreading_device_type = 805962552 - lateral_spreading_device_description = 805962554 - lateral_spreading_device_water_equivalent_thickness = 805962556 - number_of_range_modulators = 805962560 - range_modulator_sequence = 805962562 - range_modulator_number = 805962564 - range_modulator_id = 805962566 - range_modulator_type = 805962568 - range_modulator_description = 805962570 - beam_current_modulation_id = 805962572 - patient_support_type = 805962576 - patient_support_id = 805962578 - patient_support_accessory_code = 805962580 - tray_accessory_code = 805962581 - fixation_light_azimuthal_angle = 805962582 - fixation_light_polar_angle = 805962584 - meterset_rate = 805962586 - range_shifter_settings_sequence = 805962592 - range_shifter_setting = 805962594 - isocenter_to_range_shifter_distance = 805962596 - range_shifter_water_equivalent_thickness = 805962598 - lateral_spreading_device_settings_sequence = 805962608 - lateral_spreading_device_setting = 805962610 - isocenter_to_lateral_spreading_device_distance = 805962612 - range_modulator_settings_sequence = 805962624 - range_modulator_gating_start_value = 805962626 - range_modulator_gating_stop_value = 805962628 - range_modulator_gating_start_water_equivalent_thickness = 805962630 - range_modulator_gating_stop_water_equivalent_thickness = 805962632 - isocenter_to_range_modulator_distance = 805962634 - scan_spot_tune_id = 805962640 - scan_spot_prescribed_indices = 805962641 - number_of_scan_spot_positions = 805962642 - scan_spot_reordered = 805962643 - scan_spot_position_map = 805962644 - scan_spot_reordering_allowed = 805962645 - scan_spot_meterset_weights = 805962646 - scanning_spot_size = 805962648 - number_of_paintings = 805962650 - ion_tolerance_table_sequence = 805962656 - ion_beam_sequence = 805962658 - ion_beam_limiting_device_sequence = 805962660 - ion_block_sequence = 805962662 - ion_control_point_sequence = 805962664 - ion_wedge_sequence = 805962666 - ion_wedge_position_sequence = 805962668 - referenced_setup_image_sequence = 805962753 - setup_image_comment = 805962754 - motion_synchronization_sequence = 805962768 - control_point_orientation = 805962770 - general_accessory_sequence = 805962784 - general_accessory_id = 805962785 - general_accessory_description = 805962786 - general_accessory_type = 805962787 - general_accessory_number = 805962788 - source_to_general_accessory_distance = 805962789 - applicator_geometry_sequence = 805962801 - applicator_aperture_shape = 805962802 - applicator_opening = 805962803 - applicator_opening_x = 805962804 - applicator_opening_y = 805962805 - source_to_applicator_mounting_position_distance = 805962806 - number_of_block_slab_items = 805962816 - block_slab_sequence = 805962817 - block_slab_thickness = 805962818 - block_slab_number = 805962819 - device_motion_control_sequence = 805962832 - device_motion_execution_mode = 805962833 - device_motion_observation_mode = 805962834 - device_motion_parameter_code_sequence = 805962835 - distal_depth_fraction = 805963009 - distal_depth = 805963010 - nominal_range_modulation_fractions = 805963011 - nominal_range_modulated_region_depths = 805963012 - depth_dose_parameters_sequence = 805963013 - delivered_depth_dose_parameters_sequence = 805963014 - delivered_distal_depth_fraction = 805963015 - delivered_distal_depth = 805963016 - delivered_nominal_range_modulation_fractions = 805963017 - delivered_nominal_range_modulated_region_depths = 805963024 - delivered_reference_dose_definition = 805963025 - reference_dose_definition = 805963026 - referenced_rt_plan_sequence = 806092802 - referenced_beam_sequence = 806092804 - referenced_beam_number = 806092806 - referenced_reference_image_number = 806092807 - start_cumulative_meterset_weight = 806092808 - end_cumulative_meterset_weight = 806092809 - referenced_brachy_application_setup_sequence = 806092810 - referenced_brachy_application_setup_number = 806092812 - referenced_source_number = 806092814 - referenced_fraction_group_sequence = 806092832 - referenced_fraction_group_number = 806092834 - referenced_verification_image_sequence = 806092864 - referenced_reference_image_sequence = 806092866 - referenced_dose_reference_sequence = 806092880 - referenced_dose_reference_number = 806092881 - brachy_referenced_dose_reference_sequence = 806092885 - referenced_structure_set_sequence = 806092896 - referenced_patient_setup_number = 806092906 - referenced_dose_sequence = 806092928 - referenced_tolerance_table_number = 806092960 - referenced_bolus_sequence = 806092976 - referenced_wedge_number = 806092992 - referenced_compensator_number = 806093008 - referenced_block_number = 806093024 - referenced_control_point_index = 806093040 - referenced_control_point_sequence = 806093042 - referenced_start_control_point_index = 806093044 - referenced_stop_control_point_index = 806093046 - referenced_range_shifter_number = 806093056 - referenced_lateral_spreading_device_number = 806093058 - referenced_range_modulator_number = 806093060 - omitted_beam_task_sequence = 806093073 - reason_for_omission = 806093074 - reason_for_omission_description = 806093075 - approval_status = 806223874 - review_date = 806223876 - review_time = 806223877 - reviewer_name = 806223880 - arbitrary = 1073741840 - text_comments = 1073758208 - results_id = 1074266176 - results_id_issuer = 1074266178 - referenced_interpretation_sequence = 1074266192 - report_production_status__trial_ = 1074266367 - interpretation_recorded_date = 1074266368 - interpretation_recorded_time = 1074266369 - interpretation_recorder = 1074266370 - reference_to_recorded_sound = 1074266371 - interpretation_transcription_date = 1074266376 - interpretation_transcription_time = 1074266377 - interpretation_transcriber = 1074266378 - interpretation_text = 1074266379 - interpretation_author = 1074266380 - interpretation_approver_sequence = 1074266385 - interpretation_approval_date = 1074266386 - interpretation_approval_time = 1074266387 - physician_approving_interpretation = 1074266388 - interpretation_diagnosis_description = 1074266389 - interpretation_diagnosis_code_sequence = 1074266391 - results_distribution_list_sequence = 1074266392 - distribution_name = 1074266393 - distribution_address = 1074266394 - interpretation_id = 1074266624 - interpretation_id_issuer = 1074266626 - interpretation_type_id = 1074266640 - interpretation_status_id = 1074266642 - impressions = 1074266880 - results_comments = 1074282496 - low_energy_detectors = 1074790401 - high_energy_detectors = 1074790402 - detector_geometry_sequence = 1074790404 - threat_roi_voxel_sequence = 1074794497 - threat_roi_base = 1074794500 - threat_roi_extents = 1074794501 - threat_roi_bitmap = 1074794502 - route_segment_id = 1074794503 - gantry_type = 1074794504 - ooi_owner_type = 1074794505 - route_segment_sequence = 1074794506 - potential_threat_object_id = 1074794512 - threat_sequence = 1074794513 - threat_category = 1074794514 - threat_category_description = 1074794515 - atd_ability_assessment = 1074794516 - atd_assessment_flag = 1074794517 - atd_assessment_probability = 1074794518 - mass = 1074794519 - density = 1074794520 - z_effective = 1074794521 - boarding_pass_id = 1074794522 - center_of_mass = 1074794523 - center_of_pto = 1074794524 - bounding_polygon = 1074794525 - route_segment_start_location_id = 1074794526 - route_segment_end_location_id = 1074794527 - route_segment_location_id_type = 1074794528 - abort_reason = 1074794529 - volume_of_pto = 1074794531 - abort_flag = 1074794532 - route_segment_start_time = 1074794533 - route_segment_end_time = 1074794534 - tdr_type = 1074794535 - international_route_segment = 1074794536 - threat_detection_algorithm_and_version = 1074794537 - assigned_location = 1074794538 - alarm_decision_time = 1074794539 - alarm_decision = 1074794545 - number_of_total_objects = 1074794547 - number_of_alarm_objects = 1074794548 - pto_representation_sequence = 1074794551 - atd_assessment_sequence = 1074794552 - tip_type = 1074794553 - version = 1074794554 - ooi_owner_creation_time = 1074794561 - ooi_type = 1074794562 - ooi_size = 1074794563 - acquisition_status = 1074794564 - basis_materials_code_sequence = 1074794565 - phantom_type = 1074794566 - ooi_owner_sequence = 1074794567 - scan_type = 1074794568 - itinerary_id = 1074794577 - itinerary_id_type = 1074794578 - itinerary_id_assigning_authority = 1074794579 - route_id = 1074794580 - route_id_assigning_authority = 1074794581 - inbound_arrival_type = 1074794582 - carrier_id = 1074794584 - carrier_id_assigning_authority = 1074794585 - source_orientation = 1074794592 - source_position = 1074794593 - belt_height = 1074794594 - algorithm_routing_code_sequence = 1074794596 - transport_classification = 1074794599 - ooi_type_descriptor = 1074794600 - total_processing_time = 1074794601 - detector_calibration_data = 1074794604 - additional_screening_performed = 1074794605 - additional_inspection_selection_criteria = 1074794606 - additional_inspection_method_sequence = 1074794607 - ait_device_type = 1074794608 - qr_measurements_sequence = 1074794609 - target_material_sequence = 1074794610 - snr_threshold = 1074794611 - image_scale_representation = 1074794613 - referenced_pto_sequence = 1074794614 - referenced_tdr_instance_sequence = 1074794615 - pto_location_description = 1074794616 - anomaly_locator_indicator_sequence = 1074794617 - anomaly_locator_indicator = 1074794618 - pto_region_sequence = 1074794619 - inspection_selection_criteria = 1074794620 - secondary_inspection_method_sequence = 1074794621 - prcs_to_rcs_orientation = 1074794622 - mac_parameters_sequence = 1342046209 - shared_functional_groups_sequence = 1375769129 - per_frame_functional_groups_sequence = 1375769136 - waveform_sequence = 1409286400 - channel_minimum_value = 1409286416 - channel_maximum_value = 1409286418 - waveform_bits_allocated = 1409290244 - waveform_sample_interpretation = 1409290246 - waveform_padding_value = 1409290250 - waveform_data = 1409290256 - first_order_phase_correction_angle = 1442840592 - spectroscopy_data = 1442840608 - float_pixel_data = 2145386504 - double_float_pixel_data = 2145386505 - pixel_data = 2145386512 - coefficients_sdvn = 2145386528 - coefficients_sdhn = 2145386544 - coefficients_sddn = 2145386560 - digital_signatures_sequence = 4294639610 - data_set_trailing_padding = 4294770684 - item = 4294893568 - item_delimitation_item = 4294893581 - sequence_delimitation_item = 4294893789 - SEQ_FIELDS = ["file_header", "elements"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_header']['start'] = self._io.pos() - self.file_header = self._root.TFileHeader(self._io, self, self._root) - self.file_header._read() - self._debug['file_header']['end'] = self._io.pos() - self._debug['elements']['start'] = self._io.pos() - self.elements = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['elements']: - self._debug['elements']['arr'] = [] - self._debug['elements']['arr'].append({'start': self._io.pos()}) - _t_elements = self._root.TDataElementImplicit(self._io, self, self._root) - _t_elements._read() - self.elements.append(_t_elements) - self._debug['elements']['arr'][len(self.elements) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['elements']['end'] = self._io.pos() - - class TFileHeader(KaitaiStruct): - SEQ_FIELDS = ["preamble", "magic"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['preamble']['start'] = self._io.pos() - self.preamble = self._io.read_bytes(128) - self._debug['preamble']['end'] = self._io.pos() - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x44\x49\x43\x4D") - self._debug['magic']['end'] = self._io.pos() - - - class TDataElementExplicit(KaitaiStruct): - """ - .. seealso:: - Source - http://dicom.nema.org/medical/dicom/current/output/html/part05.html#sect_7.1.2 - """ - SEQ_FIELDS = ["tag_group", "tag_elem", "vr", "reserved", "value_len", "value", "items", "elements_implicit"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_group']['start'] = self._io.pos() - self.tag_group = self._io.read_u2le() - self._debug['tag_group']['end'] = self._io.pos() - self._debug['tag_elem']['start'] = self._io.pos() - self.tag_elem = self._io.read_u2le() - self._debug['tag_elem']['end'] = self._io.pos() - if not (self.is_forced_implicit): - self._debug['vr']['start'] = self._io.pos() - self.vr = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['vr']['end'] = self._io.pos() - - if ((self.is_long_len) and (not (self.is_forced_implicit))) : - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u2le() - self._debug['reserved']['end'] = self._io.pos() - - self._debug['value_len']['start'] = self._io.pos() - _on = self.is_long_len - if _on == False: - self.value_len = self._io.read_u2le() - elif _on == True: - self.value_len = self._io.read_u4le() - self._debug['value_len']['end'] = self._io.pos() - if self.value_len != 4294967295: - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.value_len) - self._debug['value']['end'] = self._io.pos() - - if ((self.vr == u"SQ") and (self.value_len == 4294967295)) : - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.SeqItem(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _.tag_elem == 57565: - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - if self.is_transfer_syntax_change_implicit: - self._debug['elements_implicit']['start'] = self._io.pos() - self.elements_implicit = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['elements_implicit']: - self._debug['elements_implicit']['arr'] = [] - self._debug['elements_implicit']['arr'].append({'start': self._io.pos()}) - _t_elements_implicit = self._root.TDataElementImplicit(self._io, self, self._root) - _t_elements_implicit._read() - self.elements_implicit.append(_t_elements_implicit) - self._debug['elements_implicit']['arr'][len(self.elements_implicit) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['elements_implicit']['end'] = self._io.pos() - - - @property - def is_forced_implicit(self): - if hasattr(self, '_m_is_forced_implicit'): - return self._m_is_forced_implicit if hasattr(self, '_m_is_forced_implicit') else None - - self._m_is_forced_implicit = self.tag_group == 65534 - return self._m_is_forced_implicit if hasattr(self, '_m_is_forced_implicit') else None - - @property - def is_long_len(self): - if hasattr(self, '_m_is_long_len'): - return self._m_is_long_len if hasattr(self, '_m_is_long_len') else None - - self._m_is_long_len = ((self.is_forced_implicit) or (self.vr == u"OB") or (self.vr == u"OD") or (self.vr == u"OF") or (self.vr == u"OL") or (self.vr == u"OW") or (self.vr == u"SQ") or (self.vr == u"UC") or (self.vr == u"UR") or (self.vr == u"UT") or (self.vr == u"UN")) - return self._m_is_long_len if hasattr(self, '_m_is_long_len') else None - - @property - def is_transfer_syntax_change_implicit(self): - if hasattr(self, '_m_is_transfer_syntax_change_implicit'): - return self._m_is_transfer_syntax_change_implicit if hasattr(self, '_m_is_transfer_syntax_change_implicit') else None - - self._m_is_transfer_syntax_change_implicit = False - return self._m_is_transfer_syntax_change_implicit if hasattr(self, '_m_is_transfer_syntax_change_implicit') else None - - @property - def tag(self): - if hasattr(self, '_m_tag'): - return self._m_tag if hasattr(self, '_m_tag') else None - - self._m_tag = KaitaiStream.resolve_enum(self._root.Tags, ((self.tag_group << 16) | self.tag_elem)) - return self._m_tag if hasattr(self, '_m_tag') else None - - - class TDataElementImplicit(KaitaiStruct): - """ - .. seealso:: - Source - http://dicom.nema.org/medical/dicom/current/output/html/part05.html#sect_7.1.2 - """ - SEQ_FIELDS = ["tag_group", "tag_elem", "vr", "reserved", "value_len", "value", "items", "elements"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_group']['start'] = self._io.pos() - self.tag_group = self._io.read_u2le() - self._debug['tag_group']['end'] = self._io.pos() - self._debug['tag_elem']['start'] = self._io.pos() - self.tag_elem = self._io.read_u2le() - self._debug['tag_elem']['end'] = self._io.pos() - if self.is_forced_explicit: - self._debug['vr']['start'] = self._io.pos() - self.vr = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['vr']['end'] = self._io.pos() - - if ((self.is_long_len) and (self.is_forced_explicit)) : - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u2le() - self._debug['reserved']['end'] = self._io.pos() - - self._debug['value_len']['start'] = self._io.pos() - _on = (self.is_long_len if self.is_forced_explicit else True) - if _on == False: - self.value_len = self._io.read_u2le() - elif _on == True: - self.value_len = self._io.read_u4le() - self._debug['value_len']['end'] = self._io.pos() - if self.value_len != 4294967295: - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.value_len) - self._debug['value']['end'] = self._io.pos() - - if ((self.vr == u"SQ") and (self.value_len == 4294967295)) : - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.SeqItem(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _.tag_elem == 57565: - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - if self.is_transfer_syntax_change_explicit: - self._debug['elements']['start'] = self._io.pos() - self.elements = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['elements']: - self._debug['elements']['arr'] = [] - self._debug['elements']['arr'].append({'start': self._io.pos()}) - _t_elements = self._root.TDataElementExplicit(self._io, self, self._root) - _t_elements._read() - self.elements.append(_t_elements) - self._debug['elements']['arr'][len(self.elements) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['elements']['end'] = self._io.pos() - - - @property - def tag(self): - if hasattr(self, '_m_tag'): - return self._m_tag if hasattr(self, '_m_tag') else None - - self._m_tag = KaitaiStream.resolve_enum(self._root.Tags, ((self.tag_group << 16) | self.tag_elem)) - return self._m_tag if hasattr(self, '_m_tag') else None - - @property - def is_transfer_syntax_change_explicit(self): - if hasattr(self, '_m_is_transfer_syntax_change_explicit'): - return self._m_is_transfer_syntax_change_explicit if hasattr(self, '_m_is_transfer_syntax_change_explicit') else None - - self._m_is_transfer_syntax_change_explicit = self.p_is_transfer_syntax_change_explicit - return self._m_is_transfer_syntax_change_explicit if hasattr(self, '_m_is_transfer_syntax_change_explicit') else None - - @property - def is_long_len(self): - if hasattr(self, '_m_is_long_len'): - return self._m_is_long_len if hasattr(self, '_m_is_long_len') else None - - self._m_is_long_len = ((self.is_forced_explicit) and ( ((self.vr == u"OB") or (self.vr == u"OD") or (self.vr == u"OF") or (self.vr == u"OL") or (self.vr == u"OW") or (self.vr == u"SQ") or (self.vr == u"UC") or (self.vr == u"UR") or (self.vr == u"UT") or (self.vr == u"UN")) )) - return self._m_is_long_len if hasattr(self, '_m_is_long_len') else None - - @property - def p_is_transfer_syntax_change_explicit(self): - if hasattr(self, '_m_p_is_transfer_syntax_change_explicit'): - return self._m_p_is_transfer_syntax_change_explicit if hasattr(self, '_m_p_is_transfer_syntax_change_explicit') else None - - self._m_p_is_transfer_syntax_change_explicit = self.value == b"\x31\x2E\x32\x2E\x38\x34\x30\x2E\x31\x30\x30\x30\x38\x2E\x31\x2E\x32\x2E\x31\x00" - return self._m_p_is_transfer_syntax_change_explicit if hasattr(self, '_m_p_is_transfer_syntax_change_explicit') else None - - @property - def is_forced_explicit(self): - if hasattr(self, '_m_is_forced_explicit'): - return self._m_is_forced_explicit if hasattr(self, '_m_is_forced_explicit') else None - - self._m_is_forced_explicit = self.tag_group == 2 - return self._m_is_forced_explicit if hasattr(self, '_m_is_forced_explicit') else None - - - class SeqItem(KaitaiStruct): - SEQ_FIELDS = ["tag_group", "tag_elem", "value_len", "value", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_group']['start'] = self._io.pos() - self.tag_group = self._io.ensure_fixed_contents(b"\xFE\xFF") - self._debug['tag_group']['end'] = self._io.pos() - self._debug['tag_elem']['start'] = self._io.pos() - self.tag_elem = self._io.read_u2le() - self._debug['tag_elem']['end'] = self._io.pos() - self._debug['value_len']['start'] = self._io.pos() - self.value_len = self._io.read_u4le() - self._debug['value_len']['end'] = self._io.pos() - if self.value_len != 4294967295: - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.value_len) - self._debug['value']['end'] = self._io.pos() - - if self.value_len == 4294967295: - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.TDataElementExplicit(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if ((_.tag_group == 65534) and (_.tag_elem == 57357)) : - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/dns_packet.py b/python/examples/kaitai/dns_packet.py deleted file mode 100644 index 159b6746..00000000 --- a/python/examples/kaitai/dns_packet.py +++ /dev/null @@ -1,355 +0,0 @@ -# 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 -import collections - - -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 DnsPacket(KaitaiStruct): - """(No support for Auth-Name + Add-Name for simplicity) - """ - - class ClassType(Enum): - in_class = 1 - cs = 2 - ch = 3 - hs = 4 - - class TypeType(Enum): - a = 1 - ns = 2 - md = 3 - mf = 4 - cname = 5 - soe = 6 - mb = 7 - mg = 8 - mr = 9 - null = 10 - wks = 11 - ptr = 12 - hinfo = 13 - minfo = 14 - mx = 15 - txt = 16 - SEQ_FIELDS = ["transaction_id", "flags", "qdcount", "ancount", "nscount", "arcount", "queries", "answers"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['transaction_id']['start'] = self._io.pos() - self.transaction_id = self._io.read_u2be() - self._debug['transaction_id']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.PacketFlags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['qdcount']['start'] = self._io.pos() - self.qdcount = self._io.read_u2be() - self._debug['qdcount']['end'] = self._io.pos() - self._debug['ancount']['start'] = self._io.pos() - self.ancount = self._io.read_u2be() - self._debug['ancount']['end'] = self._io.pos() - self._debug['nscount']['start'] = self._io.pos() - self.nscount = self._io.read_u2be() - self._debug['nscount']['end'] = self._io.pos() - self._debug['arcount']['start'] = self._io.pos() - self.arcount = self._io.read_u2be() - self._debug['arcount']['end'] = self._io.pos() - self._debug['queries']['start'] = self._io.pos() - self.queries = [None] * (self.qdcount) - for i in range(self.qdcount): - if not 'arr' in self._debug['queries']: - self._debug['queries']['arr'] = [] - self._debug['queries']['arr'].append({'start': self._io.pos()}) - _t_queries = self._root.Query(self._io, self, self._root) - _t_queries._read() - self.queries[i] = _t_queries - self._debug['queries']['arr'][i]['end'] = self._io.pos() - - self._debug['queries']['end'] = self._io.pos() - self._debug['answers']['start'] = self._io.pos() - self.answers = [None] * (self.ancount) - for i in range(self.ancount): - if not 'arr' in self._debug['answers']: - self._debug['answers']['arr'] = [] - self._debug['answers']['arr'].append({'start': self._io.pos()}) - _t_answers = self._root.Answer(self._io, self, self._root) - _t_answers._read() - self.answers[i] = _t_answers - self._debug['answers']['arr'][i]['end'] = self._io.pos() - - self._debug['answers']['end'] = self._io.pos() - - class PointerStruct(KaitaiStruct): - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u1() - self._debug['value']['end'] = self._io.pos() - - @property - 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.value) - self._debug['_m_contents']['start'] = io.pos() - self._m_contents = self._root.DomainName(io, self, self._root) - self._m_contents._read() - self._debug['_m_contents']['end'] = io.pos() - io.seek(_pos) - return self._m_contents if hasattr(self, '_m_contents') else None - - - class Label(KaitaiStruct): - SEQ_FIELDS = ["length", "pointer", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u1() - self._debug['length']['end'] = self._io.pos() - if self.is_pointer: - self._debug['pointer']['start'] = self._io.pos() - self.pointer = self._root.PointerStruct(self._io, self, self._root) - self.pointer._read() - self._debug['pointer']['end'] = self._io.pos() - - if not (self.is_pointer): - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.length)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - - - @property - def is_pointer(self): - if hasattr(self, '_m_is_pointer'): - return self._m_is_pointer if hasattr(self, '_m_is_pointer') else None - - self._m_is_pointer = self.length == 192 - return self._m_is_pointer if hasattr(self, '_m_is_pointer') else None - - - class Query(KaitaiStruct): - SEQ_FIELDS = ["name", "type", "query_class"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.DomainName(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.TypeType, self._io.read_u2be()) - self._debug['type']['end'] = self._io.pos() - self._debug['query_class']['start'] = self._io.pos() - self.query_class = KaitaiStream.resolve_enum(self._root.ClassType, self._io.read_u2be()) - self._debug['query_class']['end'] = self._io.pos() - - - class DomainName(KaitaiStruct): - SEQ_FIELDS = ["name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = [] - i = 0 - while True: - if not 'arr' in self._debug['name']: - self._debug['name']['arr'] = [] - self._debug['name']['arr'].append({'start': self._io.pos()}) - _t_name = self._root.Label(self._io, self, self._root) - _t_name._read() - _ = _t_name - self.name.append(_) - self._debug['name']['arr'][len(self.name) - 1]['end'] = self._io.pos() - if ((_.length == 0) or (_.length == 192)) : - break - i += 1 - self._debug['name']['end'] = self._io.pos() - - - class Address(KaitaiStruct): - SEQ_FIELDS = ["ip"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ip']['start'] = self._io.pos() - self.ip = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['ip']: - self._debug['ip']['arr'] = [] - self._debug['ip']['arr'].append({'start': self._io.pos()}) - self.ip[i] = self._io.read_u1() - self._debug['ip']['arr'][i]['end'] = self._io.pos() - - self._debug['ip']['end'] = self._io.pos() - - - class Answer(KaitaiStruct): - SEQ_FIELDS = ["name", "type", "answer_class", "ttl", "rdlength", "ptrdname", "address"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.DomainName(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.TypeType, self._io.read_u2be()) - self._debug['type']['end'] = self._io.pos() - self._debug['answer_class']['start'] = self._io.pos() - self.answer_class = KaitaiStream.resolve_enum(self._root.ClassType, self._io.read_u2be()) - self._debug['answer_class']['end'] = self._io.pos() - self._debug['ttl']['start'] = self._io.pos() - self.ttl = self._io.read_s4be() - self._debug['ttl']['end'] = self._io.pos() - self._debug['rdlength']['start'] = self._io.pos() - self.rdlength = self._io.read_u2be() - self._debug['rdlength']['end'] = self._io.pos() - if self.type == self._root.TypeType.ptr: - self._debug['ptrdname']['start'] = self._io.pos() - self.ptrdname = self._root.DomainName(self._io, self, self._root) - self.ptrdname._read() - self._debug['ptrdname']['end'] = self._io.pos() - - if self.type == self._root.TypeType.a: - self._debug['address']['start'] = self._io.pos() - self.address = self._root.Address(self._io, self, self._root) - self.address._read() - self._debug['address']['end'] = self._io.pos() - - - - class PacketFlags(KaitaiStruct): - SEQ_FIELDS = ["flag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag']['start'] = self._io.pos() - self.flag = self._io.read_u2be() - self._debug['flag']['end'] = self._io.pos() - - @property - def qr(self): - if hasattr(self, '_m_qr'): - return self._m_qr if hasattr(self, '_m_qr') else None - - self._m_qr = ((self.flag & 32768) >> 15) - return self._m_qr if hasattr(self, '_m_qr') else None - - @property - def ra(self): - if hasattr(self, '_m_ra'): - return self._m_ra if hasattr(self, '_m_ra') else None - - self._m_ra = ((self.flag & 128) >> 7) - return self._m_ra if hasattr(self, '_m_ra') else None - - @property - def tc(self): - if hasattr(self, '_m_tc'): - return self._m_tc if hasattr(self, '_m_tc') else None - - self._m_tc = ((self.flag & 512) >> 9) - return self._m_tc if hasattr(self, '_m_tc') else None - - @property - def rcode(self): - if hasattr(self, '_m_rcode'): - return self._m_rcode if hasattr(self, '_m_rcode') else None - - self._m_rcode = ((self.flag & 15) >> 0) - return self._m_rcode if hasattr(self, '_m_rcode') else None - - @property - def opcode(self): - if hasattr(self, '_m_opcode'): - return self._m_opcode if hasattr(self, '_m_opcode') else None - - self._m_opcode = ((self.flag & 30720) >> 11) - return self._m_opcode if hasattr(self, '_m_opcode') else None - - @property - def aa(self): - if hasattr(self, '_m_aa'): - return self._m_aa if hasattr(self, '_m_aa') else None - - self._m_aa = ((self.flag & 1024) >> 10) - return self._m_aa if hasattr(self, '_m_aa') else None - - @property - def z(self): - if hasattr(self, '_m_z'): - return self._m_z if hasattr(self, '_m_z') else None - - self._m_z = ((self.flag & 64) >> 6) - return self._m_z if hasattr(self, '_m_z') else None - - @property - def rd(self): - if hasattr(self, '_m_rd'): - return self._m_rd if hasattr(self, '_m_rd') else None - - self._m_rd = ((self.flag & 256) >> 8) - return self._m_rd if hasattr(self, '_m_rd') else None - - @property - def cd(self): - if hasattr(self, '_m_cd'): - return self._m_cd if hasattr(self, '_m_cd') else None - - self._m_cd = ((self.flag & 16) >> 4) - return self._m_cd if hasattr(self, '_m_cd') else None - - @property - def ad(self): - if hasattr(self, '_m_ad'): - return self._m_ad if hasattr(self, '_m_ad') else None - - self._m_ad = ((self.flag & 32) >> 5) - return self._m_ad if hasattr(self, '_m_ad') else None - - - diff --git a/python/examples/kaitai/doom_wad.py b/python/examples/kaitai/doom_wad.py deleted file mode 100644 index b0de10a6..00000000 --- a/python/examples/kaitai/doom_wad.py +++ /dev/null @@ -1,653 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 DoomWad(KaitaiStruct): - SEQ_FIELDS = ["magic", "num_index_entries", "index_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['magic']['end'] = self._io.pos() - self._debug['num_index_entries']['start'] = self._io.pos() - self.num_index_entries = self._io.read_s4le() - self._debug['num_index_entries']['end'] = self._io.pos() - self._debug['index_offset']['start'] = self._io.pos() - self.index_offset = self._io.read_s4le() - self._debug['index_offset']['end'] = self._io.pos() - - class Sectors(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Sector(self._io, self, self._root) - _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() - - - class Vertex(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - - - class Texture12(KaitaiStruct): - """Used for TEXTURE1 and TEXTURE2 lumps, which designate how to - combine wall patches to make wall textures. This essentially - provides a very simple form of image compression, allowing - certain elements ("patches") to be reused / recombined on - different textures for more variety in the game. - - .. seealso:: - Source - http://doom.wikia.com/wiki/TEXTURE1 - """ - SEQ_FIELDS = ["num_textures", "textures"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_textures']['start'] = self._io.pos() - self.num_textures = self._io.read_s4le() - self._debug['num_textures']['end'] = self._io.pos() - self._debug['textures']['start'] = self._io.pos() - self.textures = [None] * (self.num_textures) - for i in range(self.num_textures): - if not 'arr' in self._debug['textures']: - self._debug['textures']['arr'] = [] - self._debug['textures']['arr'].append({'start': self._io.pos()}) - _t_textures = self._root.Texture12.TextureIndex(self._io, self, self._root) - _t_textures._read() - self.textures[i] = _t_textures - self._debug['textures']['arr'][i]['end'] = self._io.pos() - - self._debug['textures']['end'] = self._io.pos() - - class TextureIndex(KaitaiStruct): - SEQ_FIELDS = ["offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_s4le() - self._debug['offset']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek(self.offset) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._root.Texture12.TextureBody(self._io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class TextureBody(KaitaiStruct): - SEQ_FIELDS = ["name", "masked", "width", "height", "column_directory", "num_patches", "patches"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 0)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - self._debug['masked']['start'] = self._io.pos() - self.masked = self._io.read_u4le() - self._debug['masked']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['column_directory']['start'] = self._io.pos() - self.column_directory = self._io.read_u4le() - self._debug['column_directory']['end'] = self._io.pos() - self._debug['num_patches']['start'] = self._io.pos() - self.num_patches = self._io.read_u2le() - self._debug['num_patches']['end'] = self._io.pos() - self._debug['patches']['start'] = self._io.pos() - self.patches = [None] * (self.num_patches) - for i in range(self.num_patches): - if not 'arr' in self._debug['patches']: - self._debug['patches']['arr'] = [] - self._debug['patches']['arr'].append({'start': self._io.pos()}) - _t_patches = self._root.Texture12.Patch(self._io, self, self._root) - _t_patches._read() - self.patches[i] = _t_patches - self._debug['patches']['arr'][i]['end'] = self._io.pos() - - self._debug['patches']['end'] = self._io.pos() - - - class Patch(KaitaiStruct): - SEQ_FIELDS = ["origin_x", "origin_y", "patch_id", "step_dir", "colormap"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['origin_x']['start'] = self._io.pos() - self.origin_x = self._io.read_s2le() - self._debug['origin_x']['end'] = self._io.pos() - self._debug['origin_y']['start'] = self._io.pos() - self.origin_y = self._io.read_s2le() - self._debug['origin_y']['end'] = self._io.pos() - self._debug['patch_id']['start'] = self._io.pos() - self.patch_id = self._io.read_u2le() - self._debug['patch_id']['end'] = self._io.pos() - self._debug['step_dir']['start'] = self._io.pos() - self.step_dir = self._io.read_u2le() - self._debug['step_dir']['end'] = self._io.pos() - self._debug['colormap']['start'] = self._io.pos() - self.colormap = self._io.read_u2le() - self._debug['colormap']['end'] = self._io.pos() - - - - class Linedef(KaitaiStruct): - SEQ_FIELDS = ["vertex_start_idx", "vertex_end_idx", "flags", "line_type", "sector_tag", "sidedef_right_idx", "sidedef_left_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['vertex_start_idx']['start'] = self._io.pos() - self.vertex_start_idx = self._io.read_u2le() - self._debug['vertex_start_idx']['end'] = self._io.pos() - self._debug['vertex_end_idx']['start'] = self._io.pos() - self.vertex_end_idx = self._io.read_u2le() - self._debug['vertex_end_idx']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['line_type']['start'] = self._io.pos() - self.line_type = self._io.read_u2le() - self._debug['line_type']['end'] = self._io.pos() - self._debug['sector_tag']['start'] = self._io.pos() - self.sector_tag = self._io.read_u2le() - self._debug['sector_tag']['end'] = self._io.pos() - self._debug['sidedef_right_idx']['start'] = self._io.pos() - self.sidedef_right_idx = self._io.read_u2le() - self._debug['sidedef_right_idx']['end'] = self._io.pos() - self._debug['sidedef_left_idx']['start'] = self._io.pos() - self.sidedef_left_idx = self._io.read_u2le() - self._debug['sidedef_left_idx']['end'] = self._io.pos() - - - class Pnames(KaitaiStruct): - """ - .. seealso:: - Source - http://doom.wikia.com/wiki/PNAMES - """ - SEQ_FIELDS = ["num_patches", "names"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_patches']['start'] = self._io.pos() - self.num_patches = self._io.read_u4le() - self._debug['num_patches']['end'] = self._io.pos() - self._debug['names']['start'] = self._io.pos() - self.names = [None] * (self.num_patches) - for i in range(self.num_patches): - if not 'arr' in self._debug['names']: - self._debug['names']['arr'] = [] - self._debug['names']['arr'].append({'start': self._io.pos()}) - self.names[i] = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 0)).decode(u"ASCII") - self._debug['names']['arr'][i]['end'] = self._io.pos() - - self._debug['names']['end'] = self._io.pos() - - - class Thing(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "angle", "type", "flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - self._debug['angle']['start'] = self._io.pos() - self.angle = self._io.read_u2le() - self._debug['angle']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u2le() - self._debug['type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - - - class Sector(KaitaiStruct): - - class SpecialSector(Enum): - normal = 0 - d_light_flicker = 1 - d_light_strobe_fast = 2 - d_light_strobe_slow = 3 - d_light_strobe_hurt = 4 - d_damage_hellslime = 5 - d_damage_nukage = 7 - d_light_glow = 8 - secret = 9 - d_sector_door_close_in_30 = 10 - d_damage_end = 11 - d_light_strobe_slow_sync = 12 - d_light_strobe_fast_sync = 13 - d_sector_door_raise_in_5_mins = 14 - d_friction_low = 15 - d_damage_super_hellslime = 16 - d_light_fire_flicker = 17 - d_damage_lava_wimpy = 18 - d_damage_lava_hefty = 19 - d_scroll_east_lava_damage = 20 - light_phased = 21 - light_sequence_start = 22 - light_sequence_special1 = 23 - light_sequence_special2 = 24 - SEQ_FIELDS = ["floor_z", "ceil_z", "floor_flat", "ceil_flat", "light", "special_type", "tag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['floor_z']['start'] = self._io.pos() - self.floor_z = self._io.read_s2le() - self._debug['floor_z']['end'] = self._io.pos() - self._debug['ceil_z']['start'] = self._io.pos() - self.ceil_z = self._io.read_s2le() - self._debug['ceil_z']['end'] = self._io.pos() - self._debug['floor_flat']['start'] = self._io.pos() - self.floor_flat = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['floor_flat']['end'] = self._io.pos() - self._debug['ceil_flat']['start'] = self._io.pos() - self.ceil_flat = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['ceil_flat']['end'] = self._io.pos() - self._debug['light']['start'] = self._io.pos() - self.light = self._io.read_s2le() - self._debug['light']['end'] = self._io.pos() - self._debug['special_type']['start'] = self._io.pos() - self.special_type = KaitaiStream.resolve_enum(self._root.Sector.SpecialSector, self._io.read_u2le()) - self._debug['special_type']['end'] = self._io.pos() - self._debug['tag']['start'] = self._io.pos() - self.tag = self._io.read_u2le() - self._debug['tag']['end'] = self._io.pos() - - - class Vertexes(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Vertex(self._io, self, self._root) - _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() - - - class Sidedef(KaitaiStruct): - SEQ_FIELDS = ["offset_x", "offset_y", "upper_texture_name", "lower_texture_name", "normal_texture_name", "sector_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset_x']['start'] = self._io.pos() - self.offset_x = self._io.read_s2le() - self._debug['offset_x']['end'] = self._io.pos() - self._debug['offset_y']['start'] = self._io.pos() - self.offset_y = self._io.read_s2le() - self._debug['offset_y']['end'] = self._io.pos() - self._debug['upper_texture_name']['start'] = self._io.pos() - self.upper_texture_name = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['upper_texture_name']['end'] = self._io.pos() - self._debug['lower_texture_name']['start'] = self._io.pos() - self.lower_texture_name = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['lower_texture_name']['end'] = self._io.pos() - self._debug['normal_texture_name']['start'] = self._io.pos() - self.normal_texture_name = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['normal_texture_name']['end'] = self._io.pos() - self._debug['sector_id']['start'] = self._io.pos() - self.sector_id = self._io.read_s2le() - self._debug['sector_id']['end'] = self._io.pos() - - - class Things(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Thing(self._io, self, self._root) - _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() - - - class Linedefs(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Linedef(self._io, self, self._root) - _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() - - - class IndexEntry(KaitaiStruct): - SEQ_FIELDS = ["offset", "size", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_s4le() - self._debug['offset']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_s4le() - self._debug['size']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 0)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - - @property - 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 = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Sectors(io, self, self._root) - self._m_contents._read() - elif _on == u"TEXTURE1": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Texture12(io, self, self._root) - self._m_contents._read() - elif _on == u"VERTEXES": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Vertexes(io, self, self._root) - self._m_contents._read() - elif _on == u"BLOCKMAP": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Blockmap(io, self, self._root) - self._m_contents._read() - elif _on == u"PNAMES": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Pnames(io, self, self._root) - self._m_contents._read() - elif _on == u"TEXTURE2": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Texture12(io, self, self._root) - self._m_contents._read() - elif _on == u"THINGS": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Things(io, self, self._root) - self._m_contents._read() - elif _on == u"LINEDEFS": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Linedefs(io, self, self._root) - self._m_contents._read() - elif _on == u"SIDEDEFS": - self._raw__m_contents = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_contents)) - self._m_contents = self._root.Sidedefs(io, 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 - - - class Sidedefs(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Sidedef(self._io, self, self._root) - _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() - - - class Blockmap(KaitaiStruct): - SEQ_FIELDS = ["origin_x", "origin_y", "num_cols", "num_rows", "linedefs_in_block"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['origin_x']['start'] = self._io.pos() - self.origin_x = self._io.read_s2le() - self._debug['origin_x']['end'] = self._io.pos() - self._debug['origin_y']['start'] = self._io.pos() - self.origin_y = self._io.read_s2le() - self._debug['origin_y']['end'] = self._io.pos() - self._debug['num_cols']['start'] = self._io.pos() - self.num_cols = self._io.read_s2le() - self._debug['num_cols']['end'] = self._io.pos() - self._debug['num_rows']['start'] = self._io.pos() - self.num_rows = self._io.read_s2le() - self._debug['num_rows']['end'] = self._io.pos() - self._debug['linedefs_in_block']['start'] = self._io.pos() - self.linedefs_in_block = [None] * ((self.num_cols * self.num_rows)) - for i in range((self.num_cols * self.num_rows)): - if not 'arr' in self._debug['linedefs_in_block']: - self._debug['linedefs_in_block']['arr'] = [] - self._debug['linedefs_in_block']['arr'].append({'start': self._io.pos()}) - _t_linedefs_in_block = self._root.Blockmap.Blocklist(self._io, self, self._root) - _t_linedefs_in_block._read() - self.linedefs_in_block[i] = _t_linedefs_in_block - self._debug['linedefs_in_block']['arr'][i]['end'] = self._io.pos() - - self._debug['linedefs_in_block']['end'] = self._io.pos() - - class Blocklist(KaitaiStruct): - SEQ_FIELDS = ["offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u2le() - self._debug['offset']['end'] = self._io.pos() - - @property - def linedefs(self): - """List of linedefs found in this block.""" - if hasattr(self, '_m_linedefs'): - return self._m_linedefs if hasattr(self, '_m_linedefs') else None - - _pos = self._io.pos() - self._io.seek((self.offset * 2)) - self._debug['_m_linedefs']['start'] = self._io.pos() - self._m_linedefs = [] - i = 0 - while True: - if not 'arr' in self._debug['_m_linedefs']: - self._debug['_m_linedefs']['arr'] = [] - self._debug['_m_linedefs']['arr'].append({'start': self._io.pos()}) - _ = self._io.read_s2le() - self._m_linedefs.append(_) - self._debug['_m_linedefs']['arr'][len(self._m_linedefs) - 1]['end'] = self._io.pos() - if _ == -1: - break - i += 1 - self._debug['_m_linedefs']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_linedefs if hasattr(self, '_m_linedefs') else None - - - - @property - def index(self): - if hasattr(self, '_m_index'): - return self._m_index if hasattr(self, '_m_index') else None - - _pos = self._io.pos() - self._io.seek(self.index_offset) - self._debug['_m_index']['start'] = self._io.pos() - self._m_index = [None] * (self.num_index_entries) - for i in range(self.num_index_entries): - if not 'arr' in self._debug['_m_index']: - self._debug['_m_index']['arr'] = [] - self._debug['_m_index']['arr'].append({'start': self._io.pos()}) - _t__m_index = self._root.IndexEntry(self._io, self, self._root) - _t__m_index._read() - self._m_index[i] = _t__m_index - self._debug['_m_index']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_index']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_index if hasattr(self, '_m_index') else None - - diff --git a/python/examples/kaitai/dos_mz.py b/python/examples/kaitai/dos_mz.py deleted file mode 100644 index 8ad248e7..00000000 --- a/python/examples/kaitai/dos_mz.py +++ /dev/null @@ -1,122 +0,0 @@ -# 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 -import collections - - -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 DosMz(KaitaiStruct): - """DOS MZ file format is a traditional format for executables in MS-DOS - environment. Many modern formats (i.e. Windows PE) still maintain - compatibility stub with this format. - - As opposed to .com file format (which basically sports one 64K code - segment of raw CPU instructions), DOS MZ .exe file format allowed - more flexible memory management, loading of larger programs and - added support for relocations. - """ - SEQ_FIELDS = ["hdr", "mz_header2", "relocations", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hdr']['start'] = self._io.pos() - self.hdr = self._root.MzHeader(self._io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - self._debug['mz_header2']['start'] = self._io.pos() - self.mz_header2 = self._io.read_bytes((self.hdr.ofs_relocations - 28)) - self._debug['mz_header2']['end'] = self._io.pos() - self._debug['relocations']['start'] = self._io.pos() - self.relocations = [None] * (self.hdr.num_relocations) - for i in range(self.hdr.num_relocations): - if not 'arr' in self._debug['relocations']: - self._debug['relocations']['arr'] = [] - self._debug['relocations']['arr'].append({'start': self._io.pos()}) - _t_relocations = self._root.Relocation(self._io, self, self._root) - _t_relocations._read() - self.relocations[i] = _t_relocations - self._debug['relocations']['arr'][i]['end'] = self._io.pos() - - self._debug['relocations']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes_full() - self._debug['body']['end'] = self._io.pos() - - class MzHeader(KaitaiStruct): - SEQ_FIELDS = ["magic", "last_page_extra_bytes", "num_pages", "num_relocations", "header_size", "min_allocation", "max_allocation", "initial_ss", "initial_sp", "checksum", "initial_ip", "initial_cs", "ofs_relocations", "overlay_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.read_bytes(2) - self._debug['magic']['end'] = self._io.pos() - self._debug['last_page_extra_bytes']['start'] = self._io.pos() - self.last_page_extra_bytes = self._io.read_u2le() - self._debug['last_page_extra_bytes']['end'] = self._io.pos() - self._debug['num_pages']['start'] = self._io.pos() - self.num_pages = self._io.read_u2le() - self._debug['num_pages']['end'] = self._io.pos() - self._debug['num_relocations']['start'] = self._io.pos() - self.num_relocations = self._io.read_u2le() - self._debug['num_relocations']['end'] = self._io.pos() - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_u2le() - self._debug['header_size']['end'] = self._io.pos() - self._debug['min_allocation']['start'] = self._io.pos() - self.min_allocation = self._io.read_u2le() - self._debug['min_allocation']['end'] = self._io.pos() - self._debug['max_allocation']['start'] = self._io.pos() - self.max_allocation = self._io.read_u2le() - self._debug['max_allocation']['end'] = self._io.pos() - self._debug['initial_ss']['start'] = self._io.pos() - self.initial_ss = self._io.read_u2le() - self._debug['initial_ss']['end'] = self._io.pos() - self._debug['initial_sp']['start'] = self._io.pos() - self.initial_sp = self._io.read_u2le() - self._debug['initial_sp']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2le() - self._debug['checksum']['end'] = self._io.pos() - self._debug['initial_ip']['start'] = self._io.pos() - self.initial_ip = self._io.read_u2le() - self._debug['initial_ip']['end'] = self._io.pos() - self._debug['initial_cs']['start'] = self._io.pos() - self.initial_cs = self._io.read_u2le() - self._debug['initial_cs']['end'] = self._io.pos() - self._debug['ofs_relocations']['start'] = self._io.pos() - self.ofs_relocations = self._io.read_u2le() - self._debug['ofs_relocations']['end'] = self._io.pos() - self._debug['overlay_id']['start'] = self._io.pos() - self.overlay_id = self._io.read_u2le() - self._debug['overlay_id']['end'] = self._io.pos() - - - class Relocation(KaitaiStruct): - SEQ_FIELDS = ["ofs", "seg"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs']['start'] = self._io.pos() - self.ofs = self._io.read_u2le() - self._debug['ofs']['end'] = self._io.pos() - self._debug['seg']['start'] = self._io.pos() - self.seg = self._io.read_u2le() - self._debug['seg']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/dune_2_pak.py b/python/examples/kaitai/dune_2_pak.py deleted file mode 100644 index bd56f1a5..00000000 --- a/python/examples/kaitai/dune_2_pak.py +++ /dev/null @@ -1,121 +0,0 @@ -# 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 -import collections - - -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 Dune2Pak(KaitaiStruct): - SEQ_FIELDS = ["dir"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dir']['start'] = self._io.pos() - self._raw_dir = self._io.read_bytes(self.dir_size) - io = KaitaiStream(BytesIO(self._raw_dir)) - self.dir = self._root.Files(io, self, self._root) - self.dir._read() - self._debug['dir']['end'] = self._io.pos() - - class Files(KaitaiStruct): - SEQ_FIELDS = ["files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['files']['start'] = self._io.pos() - self.files = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.File(i, self._io, self, self._root) - _t_files._read() - self.files.append(_t_files) - self._debug['files']['arr'][len(self.files) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['files']['end'] = self._io.pos() - - - class File(KaitaiStruct): - SEQ_FIELDS = ["ofs", "file_name"] - def __init__(self, idx, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.idx = idx - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs']['start'] = self._io.pos() - self.ofs = self._io.read_u4le() - self._debug['ofs']['end'] = self._io.pos() - if self.ofs != 0: - self._debug['file_name']['start'] = self._io.pos() - self.file_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['file_name']['end'] = self._io.pos() - - - @property - def next_ofs0(self): - if hasattr(self, '_m_next_ofs0'): - return self._m_next_ofs0 if hasattr(self, '_m_next_ofs0') else None - - if self.ofs != 0: - self._m_next_ofs0 = self._root.dir.files[(self.idx + 1)].ofs - - return self._m_next_ofs0 if hasattr(self, '_m_next_ofs0') else None - - @property - def next_ofs(self): - if hasattr(self, '_m_next_ofs'): - return self._m_next_ofs if hasattr(self, '_m_next_ofs') else None - - if self.ofs != 0: - self._m_next_ofs = (self._root._io.size() if self.next_ofs0 == 0 else self.next_ofs0) - - return self._m_next_ofs if hasattr(self, '_m_next_ofs') else None - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - if self.ofs != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs) - self._debug['_m_body']['start'] = io.pos() - self._m_body = io.read_bytes((self.next_ofs - self.ofs)) - self._debug['_m_body']['end'] = io.pos() - io.seek(_pos) - - return self._m_body if hasattr(self, '_m_body') else None - - - @property - def dir_size(self): - if hasattr(self, '_m_dir_size'): - return self._m_dir_size if hasattr(self, '_m_dir_size') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_dir_size']['start'] = self._io.pos() - self._m_dir_size = self._io.read_u4le() - self._debug['_m_dir_size']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_dir_size if hasattr(self, '_m_dir_size') else None - - diff --git a/python/examples/kaitai/edid.py b/python/examples/kaitai/edid.py deleted file mode 100644 index 9ece78a4..00000000 --- a/python/examples/kaitai/edid.py +++ /dev/null @@ -1,432 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Edid(KaitaiStruct): - SEQ_FIELDS = ["magic", "mfg_bytes", "product_code", "serial", "mfg_week", "mfg_year_mod", "edid_version_major", "edid_version_minor", "input_flags", "screen_size_h", "screen_size_v", "gamma_mod", "features_flags", "chromacity", "est_timings", "std_timings"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['mfg_bytes']['start'] = self._io.pos() - self.mfg_bytes = self._io.read_u2le() - self._debug['mfg_bytes']['end'] = self._io.pos() - self._debug['product_code']['start'] = self._io.pos() - self.product_code = self._io.read_u2le() - self._debug['product_code']['end'] = self._io.pos() - self._debug['serial']['start'] = self._io.pos() - self.serial = self._io.read_u4le() - self._debug['serial']['end'] = self._io.pos() - self._debug['mfg_week']['start'] = self._io.pos() - self.mfg_week = self._io.read_u1() - self._debug['mfg_week']['end'] = self._io.pos() - self._debug['mfg_year_mod']['start'] = self._io.pos() - self.mfg_year_mod = self._io.read_u1() - self._debug['mfg_year_mod']['end'] = self._io.pos() - self._debug['edid_version_major']['start'] = self._io.pos() - self.edid_version_major = self._io.read_u1() - self._debug['edid_version_major']['end'] = self._io.pos() - self._debug['edid_version_minor']['start'] = self._io.pos() - self.edid_version_minor = self._io.read_u1() - self._debug['edid_version_minor']['end'] = self._io.pos() - self._debug['input_flags']['start'] = self._io.pos() - self.input_flags = self._io.read_u1() - self._debug['input_flags']['end'] = self._io.pos() - self._debug['screen_size_h']['start'] = self._io.pos() - self.screen_size_h = self._io.read_u1() - self._debug['screen_size_h']['end'] = self._io.pos() - self._debug['screen_size_v']['start'] = self._io.pos() - self.screen_size_v = self._io.read_u1() - self._debug['screen_size_v']['end'] = self._io.pos() - self._debug['gamma_mod']['start'] = self._io.pos() - self.gamma_mod = self._io.read_u1() - self._debug['gamma_mod']['end'] = self._io.pos() - self._debug['features_flags']['start'] = self._io.pos() - self.features_flags = self._io.read_u1() - self._debug['features_flags']['end'] = self._io.pos() - self._debug['chromacity']['start'] = self._io.pos() - self.chromacity = self._root.ChromacityInfo(self._io, self, self._root) - self.chromacity._read() - self._debug['chromacity']['end'] = self._io.pos() - self._debug['est_timings']['start'] = self._io.pos() - self.est_timings = self._root.EstTimingsInfo(self._io, self, self._root) - self.est_timings._read() - self._debug['est_timings']['end'] = self._io.pos() - self._debug['std_timings']['start'] = self._io.pos() - self.std_timings = [None] * (8) - for i in range(8): - if not 'arr' in self._debug['std_timings']: - self._debug['std_timings']['arr'] = [] - self._debug['std_timings']['arr'].append({'start': self._io.pos()}) - _t_std_timings = self._root.StdTiming(self._io, self, self._root) - _t_std_timings._read() - self.std_timings[i] = _t_std_timings - self._debug['std_timings']['arr'][i]['end'] = self._io.pos() - - self._debug['std_timings']['end'] = self._io.pos() - - class ChromacityInfo(KaitaiStruct): - """Chromaticity information: colorimetry and white point - coordinates. All coordinates are stored as fixed precision - 10-bit numbers, bits are shuffled for compactness. - """ - SEQ_FIELDS = ["red_x_1_0", "red_y_1_0", "green_x_1_0", "green_y_1_0", "blue_x_1_0", "blue_y_1_0", "white_x_1_0", "white_y_1_0", "red_x_9_2", "red_y_9_2", "green_x_9_2", "green_y_9_2", "blue_x_9_2", "blue_y_9_2", "white_x_9_2", "white_y_9_2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['red_x_1_0']['start'] = self._io.pos() - self.red_x_1_0 = self._io.read_bits_int(2) - self._debug['red_x_1_0']['end'] = self._io.pos() - self._debug['red_y_1_0']['start'] = self._io.pos() - self.red_y_1_0 = self._io.read_bits_int(2) - self._debug['red_y_1_0']['end'] = self._io.pos() - self._debug['green_x_1_0']['start'] = self._io.pos() - self.green_x_1_0 = self._io.read_bits_int(2) - self._debug['green_x_1_0']['end'] = self._io.pos() - self._debug['green_y_1_0']['start'] = self._io.pos() - self.green_y_1_0 = self._io.read_bits_int(2) - self._debug['green_y_1_0']['end'] = self._io.pos() - self._debug['blue_x_1_0']['start'] = self._io.pos() - self.blue_x_1_0 = self._io.read_bits_int(2) - self._debug['blue_x_1_0']['end'] = self._io.pos() - self._debug['blue_y_1_0']['start'] = self._io.pos() - self.blue_y_1_0 = self._io.read_bits_int(2) - self._debug['blue_y_1_0']['end'] = self._io.pos() - self._debug['white_x_1_0']['start'] = self._io.pos() - self.white_x_1_0 = self._io.read_bits_int(2) - self._debug['white_x_1_0']['end'] = self._io.pos() - self._debug['white_y_1_0']['start'] = self._io.pos() - self.white_y_1_0 = self._io.read_bits_int(2) - self._debug['white_y_1_0']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['red_x_9_2']['start'] = self._io.pos() - self.red_x_9_2 = self._io.read_u1() - self._debug['red_x_9_2']['end'] = self._io.pos() - self._debug['red_y_9_2']['start'] = self._io.pos() - self.red_y_9_2 = self._io.read_u1() - self._debug['red_y_9_2']['end'] = self._io.pos() - self._debug['green_x_9_2']['start'] = self._io.pos() - self.green_x_9_2 = self._io.read_u1() - self._debug['green_x_9_2']['end'] = self._io.pos() - self._debug['green_y_9_2']['start'] = self._io.pos() - self.green_y_9_2 = self._io.read_u1() - self._debug['green_y_9_2']['end'] = self._io.pos() - self._debug['blue_x_9_2']['start'] = self._io.pos() - self.blue_x_9_2 = self._io.read_u1() - self._debug['blue_x_9_2']['end'] = self._io.pos() - self._debug['blue_y_9_2']['start'] = self._io.pos() - self.blue_y_9_2 = self._io.read_u1() - self._debug['blue_y_9_2']['end'] = self._io.pos() - self._debug['white_x_9_2']['start'] = self._io.pos() - self.white_x_9_2 = self._io.read_u1() - self._debug['white_x_9_2']['end'] = self._io.pos() - self._debug['white_y_9_2']['start'] = self._io.pos() - self.white_y_9_2 = self._io.read_u1() - self._debug['white_y_9_2']['end'] = self._io.pos() - - @property - def green_x_int(self): - if hasattr(self, '_m_green_x_int'): - return self._m_green_x_int if hasattr(self, '_m_green_x_int') else None - - self._m_green_x_int = ((self.green_x_9_2 << 2) | self.green_x_1_0) - return self._m_green_x_int if hasattr(self, '_m_green_x_int') else None - - @property - def red_y(self): - """Red Y coordinate.""" - if hasattr(self, '_m_red_y'): - return self._m_red_y if hasattr(self, '_m_red_y') else None - - self._m_red_y = (self.red_y_int / 1024.0) - return self._m_red_y if hasattr(self, '_m_red_y') else None - - @property - def green_y_int(self): - if hasattr(self, '_m_green_y_int'): - return self._m_green_y_int if hasattr(self, '_m_green_y_int') else None - - self._m_green_y_int = ((self.green_y_9_2 << 2) | self.green_y_1_0) - return self._m_green_y_int if hasattr(self, '_m_green_y_int') else None - - @property - def white_y(self): - """White Y coordinate.""" - if hasattr(self, '_m_white_y'): - return self._m_white_y if hasattr(self, '_m_white_y') else None - - self._m_white_y = (self.white_y_int / 1024.0) - return self._m_white_y if hasattr(self, '_m_white_y') else None - - @property - def red_x(self): - """Red X coordinate.""" - if hasattr(self, '_m_red_x'): - return self._m_red_x if hasattr(self, '_m_red_x') else None - - self._m_red_x = (self.red_x_int / 1024.0) - return self._m_red_x if hasattr(self, '_m_red_x') else None - - @property - def white_x(self): - """White X coordinate.""" - if hasattr(self, '_m_white_x'): - return self._m_white_x if hasattr(self, '_m_white_x') else None - - self._m_white_x = (self.white_x_int / 1024.0) - return self._m_white_x if hasattr(self, '_m_white_x') else None - - @property - def blue_x(self): - """Blue X coordinate.""" - if hasattr(self, '_m_blue_x'): - return self._m_blue_x if hasattr(self, '_m_blue_x') else None - - self._m_blue_x = (self.blue_x_int / 1024.0) - return self._m_blue_x if hasattr(self, '_m_blue_x') else None - - @property - def white_x_int(self): - if hasattr(self, '_m_white_x_int'): - return self._m_white_x_int if hasattr(self, '_m_white_x_int') else None - - self._m_white_x_int = ((self.white_x_9_2 << 2) | self.white_x_1_0) - return self._m_white_x_int if hasattr(self, '_m_white_x_int') else None - - @property - def white_y_int(self): - if hasattr(self, '_m_white_y_int'): - return self._m_white_y_int if hasattr(self, '_m_white_y_int') else None - - self._m_white_y_int = ((self.white_y_9_2 << 2) | self.white_y_1_0) - return self._m_white_y_int if hasattr(self, '_m_white_y_int') else None - - @property - def green_x(self): - """Green X coordinate.""" - if hasattr(self, '_m_green_x'): - return self._m_green_x if hasattr(self, '_m_green_x') else None - - self._m_green_x = (self.green_x_int / 1024.0) - return self._m_green_x if hasattr(self, '_m_green_x') else None - - @property - def red_x_int(self): - if hasattr(self, '_m_red_x_int'): - return self._m_red_x_int if hasattr(self, '_m_red_x_int') else None - - self._m_red_x_int = ((self.red_x_9_2 << 2) | self.red_x_1_0) - return self._m_red_x_int if hasattr(self, '_m_red_x_int') else None - - @property - def red_y_int(self): - if hasattr(self, '_m_red_y_int'): - return self._m_red_y_int if hasattr(self, '_m_red_y_int') else None - - self._m_red_y_int = ((self.red_y_9_2 << 2) | self.red_y_1_0) - return self._m_red_y_int if hasattr(self, '_m_red_y_int') else None - - @property - def blue_x_int(self): - if hasattr(self, '_m_blue_x_int'): - return self._m_blue_x_int if hasattr(self, '_m_blue_x_int') else None - - self._m_blue_x_int = ((self.blue_x_9_2 << 2) | self.blue_x_1_0) - return self._m_blue_x_int if hasattr(self, '_m_blue_x_int') else None - - @property - def blue_y(self): - """Blue Y coordinate.""" - if hasattr(self, '_m_blue_y'): - return self._m_blue_y if hasattr(self, '_m_blue_y') else None - - self._m_blue_y = (self.blue_y_int / 1024.0) - return self._m_blue_y if hasattr(self, '_m_blue_y') else None - - @property - def green_y(self): - """Green Y coordinate.""" - if hasattr(self, '_m_green_y'): - return self._m_green_y if hasattr(self, '_m_green_y') else None - - self._m_green_y = (self.green_y_int / 1024.0) - return self._m_green_y if hasattr(self, '_m_green_y') else None - - @property - def blue_y_int(self): - if hasattr(self, '_m_blue_y_int'): - return self._m_blue_y_int if hasattr(self, '_m_blue_y_int') else None - - self._m_blue_y_int = ((self.blue_y_9_2 << 2) | self.blue_y_1_0) - return self._m_blue_y_int if hasattr(self, '_m_blue_y_int') else None - - - class EstTimingsInfo(KaitaiStruct): - SEQ_FIELDS = ["can_720_400_70", "can_720_400_88", "can_640_480_60", "can_640_480_67", "can_640_480_72", "can_640_480_75", "can_800_600_56", "can_800_600_60", "can_800_600_72", "can_800_600_75", "can_832_624_75", "can_1024_768_87_i", "can_1024_768_60", "can_1024_768_70", "can_1024_768_75", "can_1280_1024_75", "can_1152_870_75", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['can_720_400_70']['start'] = self._io.pos() - self.can_720_400_70 = self._io.read_bits_int(1) != 0 - self._debug['can_720_400_70']['end'] = self._io.pos() - self._debug['can_720_400_88']['start'] = self._io.pos() - self.can_720_400_88 = self._io.read_bits_int(1) != 0 - self._debug['can_720_400_88']['end'] = self._io.pos() - self._debug['can_640_480_60']['start'] = self._io.pos() - self.can_640_480_60 = self._io.read_bits_int(1) != 0 - self._debug['can_640_480_60']['end'] = self._io.pos() - self._debug['can_640_480_67']['start'] = self._io.pos() - self.can_640_480_67 = self._io.read_bits_int(1) != 0 - self._debug['can_640_480_67']['end'] = self._io.pos() - self._debug['can_640_480_72']['start'] = self._io.pos() - self.can_640_480_72 = self._io.read_bits_int(1) != 0 - self._debug['can_640_480_72']['end'] = self._io.pos() - self._debug['can_640_480_75']['start'] = self._io.pos() - self.can_640_480_75 = self._io.read_bits_int(1) != 0 - self._debug['can_640_480_75']['end'] = self._io.pos() - self._debug['can_800_600_56']['start'] = self._io.pos() - self.can_800_600_56 = self._io.read_bits_int(1) != 0 - self._debug['can_800_600_56']['end'] = self._io.pos() - self._debug['can_800_600_60']['start'] = self._io.pos() - self.can_800_600_60 = self._io.read_bits_int(1) != 0 - self._debug['can_800_600_60']['end'] = self._io.pos() - self._debug['can_800_600_72']['start'] = self._io.pos() - self.can_800_600_72 = self._io.read_bits_int(1) != 0 - self._debug['can_800_600_72']['end'] = self._io.pos() - self._debug['can_800_600_75']['start'] = self._io.pos() - self.can_800_600_75 = self._io.read_bits_int(1) != 0 - self._debug['can_800_600_75']['end'] = self._io.pos() - self._debug['can_832_624_75']['start'] = self._io.pos() - self.can_832_624_75 = self._io.read_bits_int(1) != 0 - self._debug['can_832_624_75']['end'] = self._io.pos() - self._debug['can_1024_768_87_i']['start'] = self._io.pos() - self.can_1024_768_87_i = self._io.read_bits_int(1) != 0 - self._debug['can_1024_768_87_i']['end'] = self._io.pos() - self._debug['can_1024_768_60']['start'] = self._io.pos() - self.can_1024_768_60 = self._io.read_bits_int(1) != 0 - self._debug['can_1024_768_60']['end'] = self._io.pos() - self._debug['can_1024_768_70']['start'] = self._io.pos() - self.can_1024_768_70 = self._io.read_bits_int(1) != 0 - self._debug['can_1024_768_70']['end'] = self._io.pos() - self._debug['can_1024_768_75']['start'] = self._io.pos() - self.can_1024_768_75 = self._io.read_bits_int(1) != 0 - self._debug['can_1024_768_75']['end'] = self._io.pos() - self._debug['can_1280_1024_75']['start'] = self._io.pos() - self.can_1280_1024_75 = self._io.read_bits_int(1) != 0 - self._debug['can_1280_1024_75']['end'] = self._io.pos() - self._debug['can_1152_870_75']['start'] = self._io.pos() - self.can_1152_870_75 = self._io.read_bits_int(1) != 0 - self._debug['can_1152_870_75']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(7) - self._debug['reserved']['end'] = self._io.pos() - - - class StdTiming(KaitaiStruct): - - class AspectRatios(Enum): - ratio_16_10 = 0 - ratio_4_3 = 1 - ratio_5_4 = 2 - ratio_16_9 = 3 - SEQ_FIELDS = ["horiz_active_pixels_mod", "aspect_ratio", "refresh_rate_mod"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['horiz_active_pixels_mod']['start'] = self._io.pos() - self.horiz_active_pixels_mod = self._io.read_u1() - self._debug['horiz_active_pixels_mod']['end'] = self._io.pos() - self._debug['aspect_ratio']['start'] = self._io.pos() - self.aspect_ratio = KaitaiStream.resolve_enum(self._root.StdTiming.AspectRatios, self._io.read_bits_int(2)) - self._debug['aspect_ratio']['end'] = self._io.pos() - self._debug['refresh_rate_mod']['start'] = self._io.pos() - self.refresh_rate_mod = self._io.read_bits_int(5) - self._debug['refresh_rate_mod']['end'] = self._io.pos() - - @property - def horiz_active_pixels(self): - """Range of horizontal active pixels.""" - if hasattr(self, '_m_horiz_active_pixels'): - return self._m_horiz_active_pixels if hasattr(self, '_m_horiz_active_pixels') else None - - self._m_horiz_active_pixels = ((self.horiz_active_pixels_mod + 31) * 8) - return self._m_horiz_active_pixels if hasattr(self, '_m_horiz_active_pixels') else None - - @property - def refresh_rate(self): - """Vertical refresh rate, Hz.""" - if hasattr(self, '_m_refresh_rate'): - return self._m_refresh_rate if hasattr(self, '_m_refresh_rate') else None - - self._m_refresh_rate = (self.refresh_rate_mod + 60) - return self._m_refresh_rate if hasattr(self, '_m_refresh_rate') else None - - - @property - def mfg_year(self): - if hasattr(self, '_m_mfg_year'): - return self._m_mfg_year if hasattr(self, '_m_mfg_year') else None - - self._m_mfg_year = (self.mfg_year_mod + 1990) - return self._m_mfg_year if hasattr(self, '_m_mfg_year') else None - - @property - def mfg_id_ch1(self): - if hasattr(self, '_m_mfg_id_ch1'): - return self._m_mfg_id_ch1 if hasattr(self, '_m_mfg_id_ch1') else None - - self._m_mfg_id_ch1 = ((self.mfg_bytes & 31744) >> 10) - return self._m_mfg_id_ch1 if hasattr(self, '_m_mfg_id_ch1') else None - - @property - def mfg_id_ch3(self): - if hasattr(self, '_m_mfg_id_ch3'): - return self._m_mfg_id_ch3 if hasattr(self, '_m_mfg_id_ch3') else None - - self._m_mfg_id_ch3 = (self.mfg_bytes & 31) - return self._m_mfg_id_ch3 if hasattr(self, '_m_mfg_id_ch3') else None - - @property - def gamma(self): - if hasattr(self, '_m_gamma'): - return self._m_gamma if hasattr(self, '_m_gamma') else None - - if self.gamma_mod != 255: - self._m_gamma = ((self.gamma_mod + 100) / 100.0) - - return self._m_gamma if hasattr(self, '_m_gamma') else None - - @property - def mfg_id_ch2(self): - if hasattr(self, '_m_mfg_id_ch2'): - return self._m_mfg_id_ch2 if hasattr(self, '_m_mfg_id_ch2') else None - - self._m_mfg_id_ch2 = ((self.mfg_bytes & 992) >> 5) - return self._m_mfg_id_ch2 if hasattr(self, '_m_mfg_id_ch2') else None - - diff --git a/python/examples/kaitai/elf.py b/python/examples/kaitai/elf.py deleted file mode 100644 index 6f5eb252..00000000 --- a/python/examples/kaitai/elf.py +++ /dev/null @@ -1,1685 +0,0 @@ -# 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 -import collections - - -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 Elf(KaitaiStruct): - """ - .. seealso:: - Source - https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/elf.h;hb=HEAD - """ - - class Endian(Enum): - le = 1 - be = 2 - - class ShType(Enum): - null_type = 0 - progbits = 1 - symtab = 2 - strtab = 3 - rela = 4 - hash = 5 - dynamic = 6 - note = 7 - nobits = 8 - rel = 9 - shlib = 10 - dynsym = 11 - init_array = 14 - fini_array = 15 - preinit_array = 16 - group = 17 - symtab_shndx = 18 - sunw_capchain = 1879048175 - sunw_capinfo = 1879048176 - sunw_symsort = 1879048177 - sunw_tlssort = 1879048178 - sunw_ldynsym = 1879048179 - sunw_dof = 1879048180 - sunw_cap = 1879048181 - sunw_signature = 1879048182 - sunw_annotate = 1879048183 - sunw_debugstr = 1879048184 - sunw_debug = 1879048185 - sunw_move = 1879048186 - sunw_comdat = 1879048187 - sunw_syminfo = 1879048188 - sunw_verdef = 1879048189 - sunw_verneed = 1879048190 - sunw_versym = 1879048191 - sparc_gotdata = 1879048192 - arm_exidx = 1879048193 - arm_preemptmap = 1879048194 - arm_attributes = 1879048195 - - class OsAbi(Enum): - system_v = 0 - hp_ux = 1 - netbsd = 2 - gnu = 3 - solaris = 6 - aix = 7 - irix = 8 - freebsd = 9 - tru64 = 10 - modesto = 11 - openbsd = 12 - openvms = 13 - nsk = 14 - aros = 15 - fenixos = 16 - cloudabi = 17 - openvos = 18 - - class Machine(Enum): - not_set = 0 - sparc = 2 - x86 = 3 - mips = 8 - powerpc = 20 - arm = 40 - superh = 42 - ia_64 = 50 - x86_64 = 62 - aarch64 = 183 - riscv = 243 - bpf = 247 - - class DynamicArrayTags(Enum): - null = 0 - needed = 1 - pltrelsz = 2 - pltgot = 3 - hash = 4 - strtab = 5 - symtab = 6 - rela = 7 - relasz = 8 - relaent = 9 - strsz = 10 - syment = 11 - init = 12 - fini = 13 - soname = 14 - rpath = 15 - symbolic = 16 - rel = 17 - relsz = 18 - relent = 19 - pltrel = 20 - debug = 21 - textrel = 22 - jmprel = 23 - bind_now = 24 - init_array = 25 - fini_array = 26 - init_arraysz = 27 - fini_arraysz = 28 - runpath = 29 - flags = 30 - preinit_array = 32 - preinit_arraysz = 33 - maxpostags = 34 - sunw_auxiliary = 1610612749 - sunw_filter = 1610612750 - sunw_cap = 1610612752 - sunw_symtab = 1610612753 - sunw_symsz = 1610612754 - sunw_sortent = 1610612755 - sunw_symsort = 1610612756 - sunw_symsortsz = 1610612757 - sunw_tlssort = 1610612758 - sunw_tlssortsz = 1610612759 - sunw_capinfo = 1610612760 - sunw_strpad = 1610612761 - sunw_capchain = 1610612762 - sunw_ldmach = 1610612763 - sunw_capchainent = 1610612765 - sunw_capchainsz = 1610612767 - hios = 1879044096 - valrnglo = 1879047424 - gnu_prelinked = 1879047669 - gnu_conflictsz = 1879047670 - gnu_liblistsz = 1879047671 - checksum = 1879047672 - pltpadsz = 1879047673 - moveent = 1879047674 - movesz = 1879047675 - feature_1 = 1879047676 - posflag_1 = 1879047677 - syminsz = 1879047678 - valrnghi = 1879047679 - addrrnglo = 1879047680 - gnu_hash = 1879047925 - tlsdesc_plt = 1879047926 - tlsdesc_got = 1879047927 - gnu_conflict = 1879047928 - gnu_liblist = 1879047929 - config = 1879047930 - depaudit = 1879047931 - audit = 1879047932 - pltpad = 1879047933 - movetab = 1879047934 - addrrnghi = 1879047935 - versym = 1879048176 - relacount = 1879048185 - relcount = 1879048186 - flags_1 = 1879048187 - verdef = 1879048188 - verdefnum = 1879048189 - verneed = 1879048190 - verneednum = 1879048191 - loproc = 1879048192 - sparc_register = 1879048193 - auxiliary = 2147483645 - used = 2147483646 - hiproc = 2147483647 - - class Bits(Enum): - b32 = 1 - b64 = 2 - - class PhType(Enum): - null_type = 0 - load = 1 - dynamic = 2 - interp = 3 - note = 4 - shlib = 5 - phdr = 6 - tls = 7 - gnu_eh_frame = 1685382480 - gnu_stack = 1685382481 - gnu_relro = 1685382482 - pax_flags = 1694766464 - hios = 1879048191 - arm_exidx = 1879048193 - - class ObjType(Enum): - relocatable = 1 - executable = 2 - shared = 3 - core = 4 - SEQ_FIELDS = ["magic", "bits", "endian", "ei_version", "abi", "abi_version", "pad", "header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x7F\x45\x4C\x46") - self._debug['magic']['end'] = self._io.pos() - self._debug['bits']['start'] = self._io.pos() - self.bits = KaitaiStream.resolve_enum(self._root.Bits, self._io.read_u1()) - self._debug['bits']['end'] = self._io.pos() - self._debug['endian']['start'] = self._io.pos() - self.endian = KaitaiStream.resolve_enum(self._root.Endian, self._io.read_u1()) - self._debug['endian']['end'] = self._io.pos() - self._debug['ei_version']['start'] = self._io.pos() - self.ei_version = self._io.read_u1() - self._debug['ei_version']['end'] = self._io.pos() - self._debug['abi']['start'] = self._io.pos() - self.abi = KaitaiStream.resolve_enum(self._root.OsAbi, self._io.read_u1()) - self._debug['abi']['end'] = self._io.pos() - self._debug['abi_version']['start'] = self._io.pos() - self.abi_version = self._io.read_u1() - self._debug['abi_version']['end'] = self._io.pos() - self._debug['pad']['start'] = self._io.pos() - self.pad = self._io.read_bytes(7) - self._debug['pad']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self.header = self._root.EndianElf(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class PhdrTypeFlags(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, value, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.value = value - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def read(self): - if hasattr(self, '_m_read'): - return self._m_read if hasattr(self, '_m_read') else None - - self._m_read = (self.value & 4) != 0 - return self._m_read if hasattr(self, '_m_read') else None - - @property - def write(self): - if hasattr(self, '_m_write'): - return self._m_write if hasattr(self, '_m_write') else None - - self._m_write = (self.value & 2) != 0 - return self._m_write if hasattr(self, '_m_write') else None - - @property - def execute(self): - if hasattr(self, '_m_execute'): - return self._m_execute if hasattr(self, '_m_execute') else None - - self._m_execute = (self.value & 1) != 0 - return self._m_execute if hasattr(self, '_m_execute') else None - - @property - def mask_proc(self): - if hasattr(self, '_m_mask_proc'): - return self._m_mask_proc if hasattr(self, '_m_mask_proc') else None - - self._m_mask_proc = (self.value & 4026531840) != 0 - return self._m_mask_proc if hasattr(self, '_m_mask_proc') else None - - - class SectionHeaderFlags(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, value, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.value = value - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def merge(self): - """might be merged.""" - if hasattr(self, '_m_merge'): - return self._m_merge if hasattr(self, '_m_merge') else None - - self._m_merge = (self.value & 16) != 0 - return self._m_merge if hasattr(self, '_m_merge') else None - - @property - def mask_os(self): - """OS-specific.""" - if hasattr(self, '_m_mask_os'): - return self._m_mask_os if hasattr(self, '_m_mask_os') else None - - self._m_mask_os = (self.value & 267386880) != 0 - return self._m_mask_os if hasattr(self, '_m_mask_os') else None - - @property - def exclude(self): - """section is excluded unless referenced or allocated (Solaris).""" - if hasattr(self, '_m_exclude'): - return self._m_exclude if hasattr(self, '_m_exclude') else None - - self._m_exclude = (self.value & 134217728) != 0 - return self._m_exclude if hasattr(self, '_m_exclude') else None - - @property - def mask_proc(self): - """Processor-specific.""" - if hasattr(self, '_m_mask_proc'): - return self._m_mask_proc if hasattr(self, '_m_mask_proc') else None - - self._m_mask_proc = (self.value & 4026531840) != 0 - return self._m_mask_proc if hasattr(self, '_m_mask_proc') else None - - @property - def strings(self): - """contains nul-terminated strings.""" - if hasattr(self, '_m_strings'): - return self._m_strings if hasattr(self, '_m_strings') else None - - self._m_strings = (self.value & 32) != 0 - return self._m_strings if hasattr(self, '_m_strings') else None - - @property - def os_non_conforming(self): - """non-standard OS specific handling required.""" - if hasattr(self, '_m_os_non_conforming'): - return self._m_os_non_conforming if hasattr(self, '_m_os_non_conforming') else None - - self._m_os_non_conforming = (self.value & 256) != 0 - return self._m_os_non_conforming if hasattr(self, '_m_os_non_conforming') else None - - @property - def alloc(self): - """occupies memory during execution.""" - if hasattr(self, '_m_alloc'): - return self._m_alloc if hasattr(self, '_m_alloc') else None - - self._m_alloc = (self.value & 2) != 0 - return self._m_alloc if hasattr(self, '_m_alloc') else None - - @property - def exec_instr(self): - """executable.""" - if hasattr(self, '_m_exec_instr'): - return self._m_exec_instr if hasattr(self, '_m_exec_instr') else None - - self._m_exec_instr = (self.value & 4) != 0 - return self._m_exec_instr if hasattr(self, '_m_exec_instr') else None - - @property - def info_link(self): - """'sh_info' contains SHT index.""" - if hasattr(self, '_m_info_link'): - return self._m_info_link if hasattr(self, '_m_info_link') else None - - self._m_info_link = (self.value & 64) != 0 - return self._m_info_link if hasattr(self, '_m_info_link') else None - - @property - def write(self): - """writable.""" - if hasattr(self, '_m_write'): - return self._m_write if hasattr(self, '_m_write') else None - - self._m_write = (self.value & 1) != 0 - return self._m_write if hasattr(self, '_m_write') else None - - @property - def link_order(self): - """preserve order after combining.""" - if hasattr(self, '_m_link_order'): - return self._m_link_order if hasattr(self, '_m_link_order') else None - - self._m_link_order = (self.value & 128) != 0 - return self._m_link_order if hasattr(self, '_m_link_order') else None - - @property - def ordered(self): - """special ordering requirement (Solaris).""" - if hasattr(self, '_m_ordered'): - return self._m_ordered if hasattr(self, '_m_ordered') else None - - self._m_ordered = (self.value & 67108864) != 0 - return self._m_ordered if hasattr(self, '_m_ordered') else None - - @property - def tls(self): - """section hold thread-local data.""" - if hasattr(self, '_m_tls'): - return self._m_tls if hasattr(self, '_m_tls') else None - - self._m_tls = (self.value & 1024) != 0 - return self._m_tls if hasattr(self, '_m_tls') else None - - @property - def group(self): - """section is member of a group.""" - if hasattr(self, '_m_group'): - return self._m_group if hasattr(self, '_m_group') else None - - self._m_group = (self.value & 512) != 0 - return self._m_group if hasattr(self, '_m_group') else None - - - class DtFlag1Values(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, value, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.value = value - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def singleton(self): - """Singleton symbols are used.""" - if hasattr(self, '_m_singleton'): - return self._m_singleton if hasattr(self, '_m_singleton') else None - - self._m_singleton = (self.value & 33554432) != 0 - return self._m_singleton if hasattr(self, '_m_singleton') else None - - @property - def ignmuldef(self): - if hasattr(self, '_m_ignmuldef'): - return self._m_ignmuldef if hasattr(self, '_m_ignmuldef') else None - - self._m_ignmuldef = (self.value & 262144) != 0 - return self._m_ignmuldef if hasattr(self, '_m_ignmuldef') else None - - @property - def loadfltr(self): - """Trigger filtee loading at runtime.""" - if hasattr(self, '_m_loadfltr'): - return self._m_loadfltr if hasattr(self, '_m_loadfltr') else None - - self._m_loadfltr = (self.value & 16) != 0 - return self._m_loadfltr if hasattr(self, '_m_loadfltr') else None - - @property - def initfirst(self): - """Set RTLD_INITFIRST for this object.""" - if hasattr(self, '_m_initfirst'): - return self._m_initfirst if hasattr(self, '_m_initfirst') else None - - self._m_initfirst = (self.value & 32) != 0 - return self._m_initfirst if hasattr(self, '_m_initfirst') else None - - @property - def symintpose(self): - """Object has individual interposers.""" - if hasattr(self, '_m_symintpose'): - return self._m_symintpose if hasattr(self, '_m_symintpose') else None - - self._m_symintpose = (self.value & 8388608) != 0 - return self._m_symintpose if hasattr(self, '_m_symintpose') else None - - @property - def noreloc(self): - if hasattr(self, '_m_noreloc'): - return self._m_noreloc if hasattr(self, '_m_noreloc') else None - - self._m_noreloc = (self.value & 4194304) != 0 - return self._m_noreloc if hasattr(self, '_m_noreloc') else None - - @property - def confalt(self): - """Configuration alternative created.""" - if hasattr(self, '_m_confalt'): - return self._m_confalt if hasattr(self, '_m_confalt') else None - - self._m_confalt = (self.value & 8192) != 0 - return self._m_confalt if hasattr(self, '_m_confalt') else None - - @property - def dispreldne(self): - """Disp reloc applied at build time.""" - if hasattr(self, '_m_dispreldne'): - return self._m_dispreldne if hasattr(self, '_m_dispreldne') else None - - self._m_dispreldne = (self.value & 32768) != 0 - return self._m_dispreldne if hasattr(self, '_m_dispreldne') else None - - @property - def rtld_global(self): - """Set RTLD_GLOBAL for this object.""" - if hasattr(self, '_m_rtld_global'): - return self._m_rtld_global if hasattr(self, '_m_rtld_global') else None - - self._m_rtld_global = (self.value & 2) != 0 - return self._m_rtld_global if hasattr(self, '_m_rtld_global') else None - - @property - def nodelete(self): - """Set RTLD_NODELETE for this object.""" - if hasattr(self, '_m_nodelete'): - return self._m_nodelete if hasattr(self, '_m_nodelete') else None - - self._m_nodelete = (self.value & 8) != 0 - return self._m_nodelete if hasattr(self, '_m_nodelete') else None - - @property - def trans(self): - if hasattr(self, '_m_trans'): - return self._m_trans if hasattr(self, '_m_trans') else None - - self._m_trans = (self.value & 512) != 0 - return self._m_trans if hasattr(self, '_m_trans') else None - - @property - def origin(self): - """$ORIGIN must be handled.""" - if hasattr(self, '_m_origin'): - return self._m_origin if hasattr(self, '_m_origin') else None - - self._m_origin = (self.value & 128) != 0 - return self._m_origin if hasattr(self, '_m_origin') else None - - @property - def now(self): - """Set RTLD_NOW for this object.""" - if hasattr(self, '_m_now'): - return self._m_now if hasattr(self, '_m_now') else None - - self._m_now = (self.value & 1) != 0 - return self._m_now if hasattr(self, '_m_now') else None - - @property - def nohdr(self): - if hasattr(self, '_m_nohdr'): - return self._m_nohdr if hasattr(self, '_m_nohdr') else None - - self._m_nohdr = (self.value & 1048576) != 0 - return self._m_nohdr if hasattr(self, '_m_nohdr') else None - - @property - def endfiltee(self): - """Filtee terminates filters search.""" - if hasattr(self, '_m_endfiltee'): - return self._m_endfiltee if hasattr(self, '_m_endfiltee') else None - - self._m_endfiltee = (self.value & 16384) != 0 - return self._m_endfiltee if hasattr(self, '_m_endfiltee') else None - - @property - def nodirect(self): - """Object has no-direct binding.""" - if hasattr(self, '_m_nodirect'): - return self._m_nodirect if hasattr(self, '_m_nodirect') else None - - self._m_nodirect = (self.value & 131072) != 0 - return self._m_nodirect if hasattr(self, '_m_nodirect') else None - - @property - def globaudit(self): - """Global auditing required.""" - if hasattr(self, '_m_globaudit'): - return self._m_globaudit if hasattr(self, '_m_globaudit') else None - - self._m_globaudit = (self.value & 16777216) != 0 - return self._m_globaudit if hasattr(self, '_m_globaudit') else None - - @property - def noksyms(self): - if hasattr(self, '_m_noksyms'): - return self._m_noksyms if hasattr(self, '_m_noksyms') else None - - self._m_noksyms = (self.value & 524288) != 0 - return self._m_noksyms if hasattr(self, '_m_noksyms') else None - - @property - def interpose(self): - """Object is used to interpose.""" - if hasattr(self, '_m_interpose'): - return self._m_interpose if hasattr(self, '_m_interpose') else None - - self._m_interpose = (self.value & 1024) != 0 - return self._m_interpose if hasattr(self, '_m_interpose') else None - - @property - def nodump(self): - """Object can't be dldump'ed.""" - if hasattr(self, '_m_nodump'): - return self._m_nodump if hasattr(self, '_m_nodump') else None - - self._m_nodump = (self.value & 4096) != 0 - return self._m_nodump if hasattr(self, '_m_nodump') else None - - @property - def disprelpnd(self): - """Disp reloc applied at run-time.""" - if hasattr(self, '_m_disprelpnd'): - return self._m_disprelpnd if hasattr(self, '_m_disprelpnd') else None - - self._m_disprelpnd = (self.value & 65536) != 0 - return self._m_disprelpnd if hasattr(self, '_m_disprelpnd') else None - - @property - def noopen(self): - """Set RTLD_NOOPEN for this object.""" - if hasattr(self, '_m_noopen'): - return self._m_noopen if hasattr(self, '_m_noopen') else None - - self._m_noopen = (self.value & 64) != 0 - return self._m_noopen if hasattr(self, '_m_noopen') else None - - @property - def stub(self): - if hasattr(self, '_m_stub'): - return self._m_stub if hasattr(self, '_m_stub') else None - - self._m_stub = (self.value & 67108864) != 0 - return self._m_stub if hasattr(self, '_m_stub') else None - - @property - def direct(self): - """Direct binding enabled.""" - if hasattr(self, '_m_direct'): - return self._m_direct if hasattr(self, '_m_direct') else None - - self._m_direct = (self.value & 256) != 0 - return self._m_direct if hasattr(self, '_m_direct') else None - - @property - def edited(self): - """Object is modified after built.""" - if hasattr(self, '_m_edited'): - return self._m_edited if hasattr(self, '_m_edited') else None - - self._m_edited = (self.value & 2097152) != 0 - return self._m_edited if hasattr(self, '_m_edited') else None - - @property - def group(self): - """Set RTLD_GROUP for this object.""" - if hasattr(self, '_m_group'): - return self._m_group if hasattr(self, '_m_group') else None - - self._m_group = (self.value & 4) != 0 - return self._m_group if hasattr(self, '_m_group') else None - - @property - def pie(self): - if hasattr(self, '_m_pie'): - return self._m_pie if hasattr(self, '_m_pie') else None - - self._m_pie = (self.value & 134217728) != 0 - return self._m_pie if hasattr(self, '_m_pie') else None - - @property - def nodeflib(self): - """Ignore default lib search path.""" - if hasattr(self, '_m_nodeflib'): - return self._m_nodeflib if hasattr(self, '_m_nodeflib') else None - - self._m_nodeflib = (self.value & 2048) != 0 - return self._m_nodeflib if hasattr(self, '_m_nodeflib') else None - - - class EndianElf(KaitaiStruct): - SEQ_FIELDS = ["e_type", "machine", "e_version", "entry_point", "program_header_offset", "section_header_offset", "flags", "e_ehsize", "program_header_entry_size", "qty_program_header", "section_header_entry_size", "qty_section_header", "section_names_idx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - _on = self._root.endian - if _on == self._root.Endian.le: - self._is_le = True - elif _on == self._root.Endian.be: - self._is_le = False - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['e_type']['start'] = self._io.pos() - self.e_type = KaitaiStream.resolve_enum(self._root.ObjType, self._io.read_u2le()) - self._debug['e_type']['end'] = self._io.pos() - self._debug['machine']['start'] = self._io.pos() - self.machine = KaitaiStream.resolve_enum(self._root.Machine, self._io.read_u2le()) - self._debug['machine']['end'] = self._io.pos() - self._debug['e_version']['start'] = self._io.pos() - self.e_version = self._io.read_u4le() - self._debug['e_version']['end'] = self._io.pos() - self._debug['entry_point']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.entry_point = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.entry_point = self._io.read_u8le() - self._debug['entry_point']['end'] = self._io.pos() - self._debug['program_header_offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.program_header_offset = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.program_header_offset = self._io.read_u8le() - self._debug['program_header_offset']['end'] = self._io.pos() - self._debug['section_header_offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.section_header_offset = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.section_header_offset = self._io.read_u8le() - self._debug['section_header_offset']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes(4) - self._debug['flags']['end'] = self._io.pos() - self._debug['e_ehsize']['start'] = self._io.pos() - self.e_ehsize = self._io.read_u2le() - self._debug['e_ehsize']['end'] = self._io.pos() - self._debug['program_header_entry_size']['start'] = self._io.pos() - self.program_header_entry_size = self._io.read_u2le() - self._debug['program_header_entry_size']['end'] = self._io.pos() - self._debug['qty_program_header']['start'] = self._io.pos() - self.qty_program_header = self._io.read_u2le() - self._debug['qty_program_header']['end'] = self._io.pos() - self._debug['section_header_entry_size']['start'] = self._io.pos() - self.section_header_entry_size = self._io.read_u2le() - self._debug['section_header_entry_size']['end'] = self._io.pos() - self._debug['qty_section_header']['start'] = self._io.pos() - self.qty_section_header = self._io.read_u2le() - self._debug['qty_section_header']['end'] = self._io.pos() - self._debug['section_names_idx']['start'] = self._io.pos() - self.section_names_idx = self._io.read_u2le() - self._debug['section_names_idx']['end'] = self._io.pos() - - def _read_be(self): - self._debug['e_type']['start'] = self._io.pos() - self.e_type = KaitaiStream.resolve_enum(self._root.ObjType, self._io.read_u2be()) - self._debug['e_type']['end'] = self._io.pos() - self._debug['machine']['start'] = self._io.pos() - self.machine = KaitaiStream.resolve_enum(self._root.Machine, self._io.read_u2be()) - self._debug['machine']['end'] = self._io.pos() - self._debug['e_version']['start'] = self._io.pos() - self.e_version = self._io.read_u4be() - self._debug['e_version']['end'] = self._io.pos() - self._debug['entry_point']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.entry_point = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.entry_point = self._io.read_u8be() - self._debug['entry_point']['end'] = self._io.pos() - self._debug['program_header_offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.program_header_offset = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.program_header_offset = self._io.read_u8be() - self._debug['program_header_offset']['end'] = self._io.pos() - self._debug['section_header_offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.section_header_offset = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.section_header_offset = self._io.read_u8be() - self._debug['section_header_offset']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes(4) - self._debug['flags']['end'] = self._io.pos() - self._debug['e_ehsize']['start'] = self._io.pos() - self.e_ehsize = self._io.read_u2be() - self._debug['e_ehsize']['end'] = self._io.pos() - self._debug['program_header_entry_size']['start'] = self._io.pos() - self.program_header_entry_size = self._io.read_u2be() - self._debug['program_header_entry_size']['end'] = self._io.pos() - self._debug['qty_program_header']['start'] = self._io.pos() - self.qty_program_header = self._io.read_u2be() - self._debug['qty_program_header']['end'] = self._io.pos() - self._debug['section_header_entry_size']['start'] = self._io.pos() - self.section_header_entry_size = self._io.read_u2be() - self._debug['section_header_entry_size']['end'] = self._io.pos() - self._debug['qty_section_header']['start'] = self._io.pos() - self.qty_section_header = self._io.read_u2be() - self._debug['qty_section_header']['end'] = self._io.pos() - self._debug['section_names_idx']['start'] = self._io.pos() - self.section_names_idx = self._io.read_u2be() - self._debug['section_names_idx']['end'] = self._io.pos() - - class DynsymSectionEntry64(KaitaiStruct): - SEQ_FIELDS = ["name_offset", "info", "other", "shndx", "value", "size"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['name_offset']['start'] = self._io.pos() - self.name_offset = self._io.read_u4le() - self._debug['name_offset']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_u1() - self._debug['info']['end'] = self._io.pos() - self._debug['other']['start'] = self._io.pos() - self.other = self._io.read_u1() - self._debug['other']['end'] = self._io.pos() - self._debug['shndx']['start'] = self._io.pos() - self.shndx = self._io.read_u2le() - self._debug['shndx']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u8le() - self._debug['value']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u8le() - self._debug['size']['end'] = self._io.pos() - - def _read_be(self): - self._debug['name_offset']['start'] = self._io.pos() - self.name_offset = self._io.read_u4be() - self._debug['name_offset']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_u1() - self._debug['info']['end'] = self._io.pos() - self._debug['other']['start'] = self._io.pos() - self.other = self._io.read_u1() - self._debug['other']['end'] = self._io.pos() - self._debug['shndx']['start'] = self._io.pos() - self.shndx = self._io.read_u2be() - self._debug['shndx']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u8be() - self._debug['value']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u8be() - self._debug['size']['end'] = self._io.pos() - - - class ProgramHeader(KaitaiStruct): - SEQ_FIELDS = ["type", "flags64", "offset", "vaddr", "paddr", "filesz", "memsz", "flags32", "align"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.PhType, self._io.read_u4le()) - self._debug['type']['end'] = self._io.pos() - if self._root.bits == self._root.Bits.b64: - self._debug['flags64']['start'] = self._io.pos() - self.flags64 = self._io.read_u4le() - self._debug['flags64']['end'] = self._io.pos() - - self._debug['offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.offset = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.offset = self._io.read_u8le() - self._debug['offset']['end'] = self._io.pos() - self._debug['vaddr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.vaddr = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.vaddr = self._io.read_u8le() - self._debug['vaddr']['end'] = self._io.pos() - self._debug['paddr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.paddr = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.paddr = self._io.read_u8le() - self._debug['paddr']['end'] = self._io.pos() - self._debug['filesz']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.filesz = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.filesz = self._io.read_u8le() - self._debug['filesz']['end'] = self._io.pos() - self._debug['memsz']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.memsz = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.memsz = self._io.read_u8le() - self._debug['memsz']['end'] = self._io.pos() - if self._root.bits == self._root.Bits.b32: - self._debug['flags32']['start'] = self._io.pos() - self.flags32 = self._io.read_u4le() - self._debug['flags32']['end'] = self._io.pos() - - self._debug['align']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.align = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.align = self._io.read_u8le() - self._debug['align']['end'] = self._io.pos() - - def _read_be(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.PhType, self._io.read_u4be()) - self._debug['type']['end'] = self._io.pos() - if self._root.bits == self._root.Bits.b64: - self._debug['flags64']['start'] = self._io.pos() - self.flags64 = self._io.read_u4be() - self._debug['flags64']['end'] = self._io.pos() - - self._debug['offset']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.offset = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.offset = self._io.read_u8be() - self._debug['offset']['end'] = self._io.pos() - self._debug['vaddr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.vaddr = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.vaddr = self._io.read_u8be() - self._debug['vaddr']['end'] = self._io.pos() - self._debug['paddr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.paddr = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.paddr = self._io.read_u8be() - self._debug['paddr']['end'] = self._io.pos() - self._debug['filesz']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.filesz = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.filesz = self._io.read_u8be() - self._debug['filesz']['end'] = self._io.pos() - self._debug['memsz']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.memsz = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.memsz = self._io.read_u8be() - self._debug['memsz']['end'] = self._io.pos() - if self._root.bits == self._root.Bits.b32: - self._debug['flags32']['start'] = self._io.pos() - self.flags32 = self._io.read_u4be() - self._debug['flags32']['end'] = self._io.pos() - - self._debug['align']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.align = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.align = self._io.read_u8be() - self._debug['align']['end'] = self._io.pos() - - @property - def dynamic(self): - if hasattr(self, '_m_dynamic'): - return self._m_dynamic if hasattr(self, '_m_dynamic') else None - - if self.type == self._root.PhType.dynamic: - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_dynamic']['start'] = io.pos() - if self._is_le: - self._raw__m_dynamic = io.read_bytes(self.filesz) - io = KaitaiStream(BytesIO(self._raw__m_dynamic)) - self._m_dynamic = self._root.EndianElf.DynamicSection(io, self, self._root, self._is_le) - self._m_dynamic._read() - else: - self._raw__m_dynamic = io.read_bytes(self.filesz) - io = KaitaiStream(BytesIO(self._raw__m_dynamic)) - self._m_dynamic = self._root.EndianElf.DynamicSection(io, self, self._root, self._is_le) - self._m_dynamic._read() - self._debug['_m_dynamic']['end'] = io.pos() - io.seek(_pos) - - return self._m_dynamic if hasattr(self, '_m_dynamic') else None - - @property - def flags_obj(self): - if hasattr(self, '_m_flags_obj'): - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - self._debug['_m_flags_obj']['start'] = self._io.pos() - if self._is_le: - self._m_flags_obj = self._root.PhdrTypeFlags((self.flags64 | self.flags32), self._io, self, self._root) - self._m_flags_obj._read() - else: - self._m_flags_obj = self._root.PhdrTypeFlags((self.flags64 | self.flags32), self._io, self, self._root) - self._m_flags_obj._read() - self._debug['_m_flags_obj']['end'] = self._io.pos() - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - - class DynamicSectionEntry(KaitaiStruct): - SEQ_FIELDS = ["tag", "value_or_ptr"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['tag']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.tag = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.tag = self._io.read_u8le() - self._debug['tag']['end'] = self._io.pos() - self._debug['value_or_ptr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.value_or_ptr = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.value_or_ptr = self._io.read_u8le() - self._debug['value_or_ptr']['end'] = self._io.pos() - - def _read_be(self): - self._debug['tag']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.tag = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.tag = self._io.read_u8be() - self._debug['tag']['end'] = self._io.pos() - self._debug['value_or_ptr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.value_or_ptr = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.value_or_ptr = self._io.read_u8be() - self._debug['value_or_ptr']['end'] = self._io.pos() - - @property - def tag_enum(self): - if hasattr(self, '_m_tag_enum'): - return self._m_tag_enum if hasattr(self, '_m_tag_enum') else None - - self._m_tag_enum = KaitaiStream.resolve_enum(self._root.DynamicArrayTags, self.tag) - return self._m_tag_enum if hasattr(self, '_m_tag_enum') else None - - @property - def flag_1_values(self): - if hasattr(self, '_m_flag_1_values'): - return self._m_flag_1_values if hasattr(self, '_m_flag_1_values') else None - - if self.tag_enum == self._root.DynamicArrayTags.flags_1: - self._debug['_m_flag_1_values']['start'] = self._io.pos() - if self._is_le: - self._m_flag_1_values = self._root.DtFlag1Values(self.value_or_ptr, self._io, self, self._root) - self._m_flag_1_values._read() - else: - self._m_flag_1_values = self._root.DtFlag1Values(self.value_or_ptr, self._io, self, self._root) - self._m_flag_1_values._read() - self._debug['_m_flag_1_values']['end'] = self._io.pos() - - return self._m_flag_1_values if hasattr(self, '_m_flag_1_values') else None - - - class SectionHeader(KaitaiStruct): - SEQ_FIELDS = ["ofs_name", "type", "flags", "addr", "ofs_body", "len_body", "linked_section_idx", "info", "align", "entry_size"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['ofs_name']['start'] = self._io.pos() - self.ofs_name = self._io.read_u4le() - self._debug['ofs_name']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.ShType, self._io.read_u4le()) - self._debug['type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.flags = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.flags = self._io.read_u8le() - self._debug['flags']['end'] = self._io.pos() - self._debug['addr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.addr = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.addr = self._io.read_u8le() - self._debug['addr']['end'] = self._io.pos() - self._debug['ofs_body']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.ofs_body = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.ofs_body = self._io.read_u8le() - self._debug['ofs_body']['end'] = self._io.pos() - self._debug['len_body']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.len_body = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.len_body = self._io.read_u8le() - self._debug['len_body']['end'] = self._io.pos() - self._debug['linked_section_idx']['start'] = self._io.pos() - self.linked_section_idx = self._io.read_u4le() - self._debug['linked_section_idx']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_bytes(4) - self._debug['info']['end'] = self._io.pos() - self._debug['align']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.align = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.align = self._io.read_u8le() - self._debug['align']['end'] = self._io.pos() - self._debug['entry_size']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.entry_size = self._io.read_u4le() - elif _on == self._root.Bits.b64: - self.entry_size = self._io.read_u8le() - self._debug['entry_size']['end'] = self._io.pos() - - def _read_be(self): - self._debug['ofs_name']['start'] = self._io.pos() - self.ofs_name = self._io.read_u4be() - self._debug['ofs_name']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.ShType, self._io.read_u4be()) - self._debug['type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.flags = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.flags = self._io.read_u8be() - self._debug['flags']['end'] = self._io.pos() - self._debug['addr']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.addr = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.addr = self._io.read_u8be() - self._debug['addr']['end'] = self._io.pos() - self._debug['ofs_body']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.ofs_body = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.ofs_body = self._io.read_u8be() - self._debug['ofs_body']['end'] = self._io.pos() - self._debug['len_body']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.len_body = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.len_body = self._io.read_u8be() - self._debug['len_body']['end'] = self._io.pos() - self._debug['linked_section_idx']['start'] = self._io.pos() - self.linked_section_idx = self._io.read_u4be() - self._debug['linked_section_idx']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_bytes(4) - self._debug['info']['end'] = self._io.pos() - self._debug['align']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.align = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.align = self._io.read_u8be() - self._debug['align']['end'] = self._io.pos() - self._debug['entry_size']['start'] = self._io.pos() - _on = self._root.bits - if _on == self._root.Bits.b32: - self.entry_size = self._io.read_u4be() - elif _on == self._root.Bits.b64: - self.entry_size = self._io.read_u8be() - self._debug['entry_size']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_body) - self._debug['_m_body']['start'] = io.pos() - if self._is_le: - _on = self.type - if _on == self._root.ShType.strtab: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynamic: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.DynamicSection(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynsym: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.DynsymSection(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynstr: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_body._read() - else: - self._m_body = io.read_bytes(self.len_body) - else: - _on = self.type - if _on == self._root.ShType.strtab: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynamic: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.DynamicSection(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynsym: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.DynsymSection(io, self, self._root, self._is_le) - self._m_body._read() - elif _on == self._root.ShType.dynstr: - self._raw__m_body = io.read_bytes(self.len_body) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_body._read() - else: - self._m_body = io.read_bytes(self.len_body) - self._debug['_m_body']['end'] = io.pos() - io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - @property - def name(self): - if hasattr(self, '_m_name'): - return self._m_name if hasattr(self, '_m_name') else None - - io = self._root.header.strings._io - _pos = io.pos() - io.seek(self.ofs_name) - self._debug['_m_name']['start'] = io.pos() - if self._is_le: - self._m_name = (io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - else: - self._m_name = (io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['_m_name']['end'] = io.pos() - io.seek(_pos) - return self._m_name if hasattr(self, '_m_name') else None - - @property - def flags_obj(self): - if hasattr(self, '_m_flags_obj'): - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - self._debug['_m_flags_obj']['start'] = self._io.pos() - if self._is_le: - self._m_flags_obj = self._root.SectionHeaderFlags(self.flags, self._io, self, self._root) - self._m_flags_obj._read() - else: - self._m_flags_obj = self._root.SectionHeaderFlags(self.flags, self._io, self, self._root) - self._m_flags_obj._read() - self._debug['_m_flags_obj']['end'] = self._io.pos() - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - - class DynamicSection(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - 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 = self._root.EndianElf.DynamicSectionEntry(self._io, self, self._root, self._is_le) - _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_be(self): - 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 = self._root.EndianElf.DynamicSectionEntry(self._io, self, self._root, self._is_le) - _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() - - - class DynsymSection(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - 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()}) - _on = self._root.bits - if _on == self._root.Bits.b32: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.EndianElf.DynsymSectionEntry32(self._io, self, self._root, self._is_le) - _t_entries._read() - self.entries.append(_t_entries) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - elif _on == self._root.Bits.b64: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.EndianElf.DynsymSectionEntry64(self._io, self, self._root, self._is_le) - _t_entries._read() - self.entries.append(_t_entries) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - def _read_be(self): - 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()}) - _on = self._root.bits - if _on == self._root.Bits.b32: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.EndianElf.DynsymSectionEntry32(self._io, self, self._root, self._is_le) - _t_entries._read() - self.entries.append(_t_entries) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - elif _on == self._root.Bits.b64: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.EndianElf.DynsymSectionEntry64(self._io, self, self._root, self._is_le) - _t_entries._read() - self.entries.append(_t_entries) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - - class DynsymSectionEntry32(KaitaiStruct): - SEQ_FIELDS = ["name_offset", "value", "size", "info", "other", "shndx"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['name_offset']['start'] = self._io.pos() - self.name_offset = self._io.read_u4le() - self._debug['name_offset']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u4le() - self._debug['value']['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['info']['start'] = self._io.pos() - self.info = self._io.read_u1() - self._debug['info']['end'] = self._io.pos() - self._debug['other']['start'] = self._io.pos() - self.other = self._io.read_u1() - self._debug['other']['end'] = self._io.pos() - self._debug['shndx']['start'] = self._io.pos() - self.shndx = self._io.read_u2le() - self._debug['shndx']['end'] = self._io.pos() - - def _read_be(self): - self._debug['name_offset']['start'] = self._io.pos() - self.name_offset = self._io.read_u4be() - self._debug['name_offset']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u4be() - self._debug['value']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4be() - self._debug['size']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_u1() - self._debug['info']['end'] = self._io.pos() - self._debug['other']['start'] = self._io.pos() - self.other = self._io.read_u1() - self._debug['other']['end'] = self._io.pos() - self._debug['shndx']['start'] = self._io.pos() - self.shndx = self._io.read_u2be() - self._debug['shndx']['end'] = self._io.pos() - - - class StringsStruct(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - 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()}) - self.entries.append((self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII")) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - def _read_be(self): - 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()}) - self.entries.append((self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII")) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - - @property - def program_headers(self): - if hasattr(self, '_m_program_headers'): - return self._m_program_headers if hasattr(self, '_m_program_headers') else None - - _pos = self._io.pos() - self._io.seek(self.program_header_offset) - self._debug['_m_program_headers']['start'] = self._io.pos() - if self._is_le: - self._raw__m_program_headers = [None] * (self.qty_program_header) - self._m_program_headers = [None] * (self.qty_program_header) - for i in range(self.qty_program_header): - if not 'arr' in self._debug['_m_program_headers']: - self._debug['_m_program_headers']['arr'] = [] - self._debug['_m_program_headers']['arr'].append({'start': self._io.pos()}) - self._raw__m_program_headers[i] = self._io.read_bytes(self.program_header_entry_size) - io = KaitaiStream(BytesIO(self._raw__m_program_headers[i])) - _t__m_program_headers = self._root.EndianElf.ProgramHeader(io, self, self._root, self._is_le) - _t__m_program_headers._read() - self._m_program_headers[i] = _t__m_program_headers - self._debug['_m_program_headers']['arr'][i]['end'] = self._io.pos() - - else: - self._raw__m_program_headers = [None] * (self.qty_program_header) - self._m_program_headers = [None] * (self.qty_program_header) - for i in range(self.qty_program_header): - if not 'arr' in self._debug['_m_program_headers']: - self._debug['_m_program_headers']['arr'] = [] - self._debug['_m_program_headers']['arr'].append({'start': self._io.pos()}) - self._raw__m_program_headers[i] = self._io.read_bytes(self.program_header_entry_size) - io = KaitaiStream(BytesIO(self._raw__m_program_headers[i])) - _t__m_program_headers = self._root.EndianElf.ProgramHeader(io, self, self._root, self._is_le) - _t__m_program_headers._read() - self._m_program_headers[i] = _t__m_program_headers - self._debug['_m_program_headers']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_program_headers']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_program_headers if hasattr(self, '_m_program_headers') else None - - @property - def section_headers(self): - if hasattr(self, '_m_section_headers'): - return self._m_section_headers if hasattr(self, '_m_section_headers') else None - - _pos = self._io.pos() - self._io.seek(self.section_header_offset) - self._debug['_m_section_headers']['start'] = self._io.pos() - if self._is_le: - self._raw__m_section_headers = [None] * (self.qty_section_header) - self._m_section_headers = [None] * (self.qty_section_header) - for i in range(self.qty_section_header): - if not 'arr' in self._debug['_m_section_headers']: - self._debug['_m_section_headers']['arr'] = [] - self._debug['_m_section_headers']['arr'].append({'start': self._io.pos()}) - self._raw__m_section_headers[i] = self._io.read_bytes(self.section_header_entry_size) - io = KaitaiStream(BytesIO(self._raw__m_section_headers[i])) - _t__m_section_headers = self._root.EndianElf.SectionHeader(io, self, self._root, self._is_le) - _t__m_section_headers._read() - self._m_section_headers[i] = _t__m_section_headers - self._debug['_m_section_headers']['arr'][i]['end'] = self._io.pos() - - else: - self._raw__m_section_headers = [None] * (self.qty_section_header) - self._m_section_headers = [None] * (self.qty_section_header) - for i in range(self.qty_section_header): - if not 'arr' in self._debug['_m_section_headers']: - self._debug['_m_section_headers']['arr'] = [] - self._debug['_m_section_headers']['arr'].append({'start': self._io.pos()}) - self._raw__m_section_headers[i] = self._io.read_bytes(self.section_header_entry_size) - io = KaitaiStream(BytesIO(self._raw__m_section_headers[i])) - _t__m_section_headers = self._root.EndianElf.SectionHeader(io, self, self._root, self._is_le) - _t__m_section_headers._read() - self._m_section_headers[i] = _t__m_section_headers - self._debug['_m_section_headers']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_section_headers']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_section_headers if hasattr(self, '_m_section_headers') else None - - @property - def strings(self): - if hasattr(self, '_m_strings'): - return self._m_strings if hasattr(self, '_m_strings') else None - - _pos = self._io.pos() - self._io.seek(self.section_headers[self.section_names_idx].ofs_body) - self._debug['_m_strings']['start'] = self._io.pos() - if self._is_le: - self._raw__m_strings = self._io.read_bytes(self.section_headers[self.section_names_idx].len_body) - io = KaitaiStream(BytesIO(self._raw__m_strings)) - self._m_strings = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_strings._read() - else: - self._raw__m_strings = self._io.read_bytes(self.section_headers[self.section_names_idx].len_body) - io = KaitaiStream(BytesIO(self._raw__m_strings)) - self._m_strings = self._root.EndianElf.StringsStruct(io, self, self._root, self._is_le) - self._m_strings._read() - self._debug['_m_strings']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_strings if hasattr(self, '_m_strings') else None - - - diff --git a/python/examples/kaitai/ethernet_frame.py b/python/examples/kaitai/ethernet_frame.py deleted file mode 100644 index adbe60de..00000000 --- a/python/examples/kaitai/ethernet_frame.py +++ /dev/null @@ -1,65 +0,0 @@ -# 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 -import collections - - -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)) - -from . import ipv4_packet -from . import ipv6_packet -class EthernetFrame(KaitaiStruct): - """Ethernet frame is a OSI data link layer (layer 2) protocol data unit - for Ethernet networks. In practice, many other networks and/or - in-file dumps adopted the same format for encapsulation purposes. - - .. seealso:: - Source - https://ieeexplore.ieee.org/document/7428776 - """ - - class EtherTypeEnum(Enum): - ipv4 = 2048 - x_75_internet = 2049 - nbs_internet = 2050 - ecma_internet = 2051 - chaosnet = 2052 - x_25_level_3 = 2053 - arp = 2054 - ipv6 = 34525 - SEQ_FIELDS = ["dst_mac", "src_mac", "ether_type", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dst_mac']['start'] = self._io.pos() - self.dst_mac = self._io.read_bytes(6) - self._debug['dst_mac']['end'] = self._io.pos() - self._debug['src_mac']['start'] = self._io.pos() - self.src_mac = self._io.read_bytes(6) - self._debug['src_mac']['end'] = self._io.pos() - self._debug['ether_type']['start'] = self._io.pos() - self.ether_type = KaitaiStream.resolve_enum(self._root.EtherTypeEnum, self._io.read_u2be()) - self._debug['ether_type']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.ether_type - if _on == self._root.EtherTypeEnum.ipv4: - self._raw_body = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = ipv4_packet.Ipv4Packet(io) - self.body._read() - elif _on == self._root.EtherTypeEnum.ipv6: - self._raw_body = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = ipv6_packet.Ipv6Packet(io) - self.body._read() - else: - self.body = self._io.read_bytes_full() - self._debug['body']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/exif.py b/python/examples/kaitai/exif.py deleted file mode 100644 index 134ab3f6..00000000 --- a/python/examples/kaitai/exif.py +++ /dev/null @@ -1,35 +0,0 @@ -# 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 -import collections - - -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)) - -from .exif_le import ExifLe -from .exif_be import ExifBe -class Exif(KaitaiStruct): - SEQ_FIELDS = ["endianness", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['endianness']['start'] = self._io.pos() - self.endianness = self._io.read_u2le() - self._debug['endianness']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.endianness - if _on == 18761: - self.body = ExifLe(self._io) - self.body._read() - elif _on == 19789: - self.body = ExifBe(self._io) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/exif_be.py b/python/examples/kaitai/exif_be.py deleted file mode 100644 index d27ae9fd..00000000 --- a/python/examples/kaitai/exif_be.py +++ /dev/null @@ -1,620 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 ExifBe(KaitaiStruct): - SEQ_FIELDS = ["version", "ifd0_ofs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2be() - self._debug['version']['end'] = self._io.pos() - self._debug['ifd0_ofs']['start'] = self._io.pos() - self.ifd0_ofs = self._io.read_u4be() - self._debug['ifd0_ofs']['end'] = self._io.pos() - - class Ifd(KaitaiStruct): - SEQ_FIELDS = ["num_fields", "fields", "next_ifd_ofs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_fields']['start'] = self._io.pos() - self.num_fields = self._io.read_u2be() - self._debug['num_fields']['end'] = self._io.pos() - self._debug['fields']['start'] = self._io.pos() - self.fields = [None] * (self.num_fields) - for i in range(self.num_fields): - if not 'arr' in self._debug['fields']: - self._debug['fields']['arr'] = [] - self._debug['fields']['arr'].append({'start': self._io.pos()}) - _t_fields = self._root.IfdField(self._io, self, self._root) - _t_fields._read() - self.fields[i] = _t_fields - self._debug['fields']['arr'][i]['end'] = self._io.pos() - - self._debug['fields']['end'] = self._io.pos() - self._debug['next_ifd_ofs']['start'] = self._io.pos() - self.next_ifd_ofs = self._io.read_u4be() - self._debug['next_ifd_ofs']['end'] = self._io.pos() - - @property - def next_ifd(self): - if hasattr(self, '_m_next_ifd'): - return self._m_next_ifd if hasattr(self, '_m_next_ifd') else None - - if self.next_ifd_ofs != 0: - _pos = self._io.pos() - self._io.seek(self.next_ifd_ofs) - self._debug['_m_next_ifd']['start'] = self._io.pos() - self._m_next_ifd = self._root.Ifd(self._io, self, self._root) - self._m_next_ifd._read() - self._debug['_m_next_ifd']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_next_ifd if hasattr(self, '_m_next_ifd') else None - - - class IfdField(KaitaiStruct): - - class FieldTypeEnum(Enum): - byte = 1 - ascii_string = 2 - word = 3 - dword = 4 - rational = 5 - undefined = 7 - slong = 9 - srational = 10 - - class TagEnum(Enum): - image_width = 256 - image_height = 257 - bits_per_sample = 258 - compression = 259 - photometric_interpretation = 262 - thresholding = 263 - cell_width = 264 - cell_length = 265 - fill_order = 266 - document_name = 269 - image_description = 270 - make = 271 - model = 272 - strip_offsets = 273 - orientation = 274 - samples_per_pixel = 277 - rows_per_strip = 278 - strip_byte_counts = 279 - min_sample_value = 280 - max_sample_value = 281 - x_resolution = 282 - y_resolution = 283 - planar_configuration = 284 - page_name = 285 - x_position = 286 - y_position = 287 - free_offsets = 288 - free_byte_counts = 289 - gray_response_unit = 290 - gray_response_curve = 291 - t4_options = 292 - t6_options = 293 - resolution_unit = 296 - page_number = 297 - color_response_unit = 300 - transfer_function = 301 - software = 305 - modify_date = 306 - artist = 315 - host_computer = 316 - predictor = 317 - white_point = 318 - primary_chromaticities = 319 - color_map = 320 - halftone_hints = 321 - tile_width = 322 - tile_length = 323 - tile_offsets = 324 - tile_byte_counts = 325 - bad_fax_lines = 326 - clean_fax_data = 327 - consecutive_bad_fax_lines = 328 - sub_ifd = 330 - ink_set = 332 - ink_names = 333 - numberof_inks = 334 - dot_range = 336 - target_printer = 337 - extra_samples = 338 - sample_format = 339 - s_min_sample_value = 340 - s_max_sample_value = 341 - transfer_range = 342 - clip_path = 343 - x_clip_path_units = 344 - y_clip_path_units = 345 - indexed = 346 - jpeg_tables = 347 - opi_proxy = 351 - global_parameters_ifd = 400 - profile_type = 401 - fax_profile = 402 - coding_methods = 403 - version_year = 404 - mode_number = 405 - decode = 433 - default_image_color = 434 - t82_options = 435 - jpeg_tables2 = 437 - jpeg_proc = 512 - thumbnail_offset = 513 - thumbnail_length = 514 - jpeg_restart_interval = 515 - jpeg_lossless_predictors = 517 - jpeg_point_transforms = 518 - jpegq_tables = 519 - jpegdc_tables = 520 - jpegac_tables = 521 - y_cb_cr_coefficients = 529 - y_cb_cr_sub_sampling = 530 - y_cb_cr_positioning = 531 - reference_black_white = 532 - strip_row_counts = 559 - application_notes = 700 - uspto_miscellaneous = 999 - related_image_file_format = 4096 - related_image_width = 4097 - related_image_height = 4098 - rating = 18246 - xp_dip_xml = 18247 - stitch_info = 18248 - rating_percent = 18249 - sony_raw_file_type = 28672 - light_falloff_params = 28722 - chromatic_aberration_corr_params = 28725 - distortion_corr_params = 28727 - image_id = 32781 - wang_tag1 = 32931 - wang_annotation = 32932 - wang_tag3 = 32933 - wang_tag4 = 32934 - image_reference_points = 32953 - region_xform_tack_point = 32954 - warp_quadrilateral = 32955 - affine_transform_mat = 32956 - matteing = 32995 - data_type = 32996 - image_depth = 32997 - tile_depth = 32998 - image_full_width = 33300 - image_full_height = 33301 - texture_format = 33302 - wrap_modes = 33303 - fov_cot = 33304 - matrix_world_to_screen = 33305 - matrix_world_to_camera = 33306 - model2 = 33405 - cfa_repeat_pattern_dim = 33421 - cfa_pattern2 = 33422 - battery_level = 33423 - kodak_ifd = 33424 - copyright = 33432 - exposure_time = 33434 - f_number = 33437 - md_file_tag = 33445 - md_scale_pixel = 33446 - md_color_table = 33447 - md_lab_name = 33448 - md_sample_info = 33449 - md_prep_date = 33450 - md_prep_time = 33451 - md_file_units = 33452 - pixel_scale = 33550 - advent_scale = 33589 - advent_revision = 33590 - uic1_tag = 33628 - uic2_tag = 33629 - uic3_tag = 33630 - uic4_tag = 33631 - iptc_naa = 33723 - intergraph_packet_data = 33918 - intergraph_flag_registers = 33919 - intergraph_matrix = 33920 - ingr_reserved = 33921 - model_tie_point = 33922 - site = 34016 - color_sequence = 34017 - it8_header = 34018 - raster_padding = 34019 - bits_per_run_length = 34020 - bits_per_extended_run_length = 34021 - color_table = 34022 - image_color_indicator = 34023 - background_color_indicator = 34024 - image_color_value = 34025 - background_color_value = 34026 - pixel_intensity_range = 34027 - transparency_indicator = 34028 - color_characterization = 34029 - hc_usage = 34030 - trap_indicator = 34031 - cmyk_equivalent = 34032 - sem_info = 34118 - afcp_iptc = 34152 - pixel_magic_jbig_options = 34232 - jpl_carto_ifd = 34263 - model_transform = 34264 - wb_grgb_levels = 34306 - leaf_data = 34310 - photoshop_settings = 34377 - exif_offset = 34665 - icc_profile = 34675 - tiff_fx_extensions = 34687 - multi_profiles = 34688 - shared_data = 34689 - t88_options = 34690 - image_layer = 34732 - geo_tiff_directory = 34735 - geo_tiff_double_params = 34736 - geo_tiff_ascii_params = 34737 - jbig_options = 34750 - exposure_program = 34850 - spectral_sensitivity = 34852 - gps_info = 34853 - iso = 34855 - opto_electric_conv_factor = 34856 - interlace = 34857 - time_zone_offset = 34858 - self_timer_mode = 34859 - sensitivity_type = 34864 - standard_output_sensitivity = 34865 - recommended_exposure_index = 34866 - iso_speed = 34867 - iso_speed_latitudeyyy = 34868 - iso_speed_latitudezzz = 34869 - fax_recv_params = 34908 - fax_sub_address = 34909 - fax_recv_time = 34910 - fedex_edr = 34929 - leaf_sub_ifd = 34954 - exif_version = 36864 - date_time_original = 36867 - create_date = 36868 - google_plus_upload_code = 36873 - offset_time = 36880 - offset_time_original = 36881 - offset_time_digitized = 36882 - components_configuration = 37121 - compressed_bits_per_pixel = 37122 - shutter_speed_value = 37377 - aperture_value = 37378 - brightness_value = 37379 - exposure_compensation = 37380 - max_aperture_value = 37381 - subject_distance = 37382 - metering_mode = 37383 - light_source = 37384 - flash = 37385 - focal_length = 37386 - flash_energy = 37387 - spatial_frequency_response = 37388 - noise = 37389 - focal_plane_x_resolution = 37390 - focal_plane_y_resolution = 37391 - focal_plane_resolution_unit = 37392 - image_number = 37393 - security_classification = 37394 - image_history = 37395 - subject_area = 37396 - exposure_index = 37397 - tiff_ep_standard_id = 37398 - sensing_method = 37399 - cip3_data_file = 37434 - cip3_sheet = 37435 - cip3_side = 37436 - sto_nits = 37439 - maker_note = 37500 - user_comment = 37510 - sub_sec_time = 37520 - sub_sec_time_original = 37521 - sub_sec_time_digitized = 37522 - ms_document_text = 37679 - ms_property_set_storage = 37680 - ms_document_text_position = 37681 - image_source_data = 37724 - ambient_temperature = 37888 - humidity = 37889 - pressure = 37890 - water_depth = 37891 - acceleration = 37892 - camera_elevation_angle = 37893 - xp_title = 40091 - xp_comment = 40092 - xp_author = 40093 - xp_keywords = 40094 - xp_subject = 40095 - flashpix_version = 40960 - color_space = 40961 - exif_image_width = 40962 - exif_image_height = 40963 - related_sound_file = 40964 - interop_offset = 40965 - samsung_raw_pointers_offset = 40976 - samsung_raw_pointers_length = 40977 - samsung_raw_byte_order = 41217 - samsung_raw_unknown = 41218 - flash_energy2 = 41483 - spatial_frequency_response2 = 41484 - noise2 = 41485 - focal_plane_x_resolution2 = 41486 - focal_plane_y_resolution2 = 41487 - focal_plane_resolution_unit2 = 41488 - image_number2 = 41489 - security_classification2 = 41490 - image_history2 = 41491 - subject_location = 41492 - exposure_index2 = 41493 - tiff_ep_standard_id2 = 41494 - sensing_method2 = 41495 - file_source = 41728 - scene_type = 41729 - cfa_pattern = 41730 - custom_rendered = 41985 - exposure_mode = 41986 - white_balance = 41987 - digital_zoom_ratio = 41988 - focal_length_in35mm_format = 41989 - scene_capture_type = 41990 - gain_control = 41991 - contrast = 41992 - saturation = 41993 - sharpness = 41994 - device_setting_description = 41995 - subject_distance_range = 41996 - image_unique_id = 42016 - owner_name = 42032 - serial_number = 42033 - lens_info = 42034 - lens_make = 42035 - lens_model = 42036 - lens_serial_number = 42037 - gdal_metadata = 42112 - gdal_no_data = 42113 - gamma = 42240 - expand_software = 44992 - expand_lens = 44993 - expand_film = 44994 - expand_filter_lens = 44995 - expand_scanner = 44996 - expand_flash_lamp = 44997 - pixel_format = 48129 - transformation = 48130 - uncompressed = 48131 - image_type = 48132 - image_width2 = 48256 - image_height2 = 48257 - width_resolution = 48258 - height_resolution = 48259 - image_offset = 48320 - image_byte_count = 48321 - alpha_offset = 48322 - alpha_byte_count = 48323 - image_data_discard = 48324 - alpha_data_discard = 48325 - oce_scanjob_desc = 50215 - oce_application_selector = 50216 - oce_id_number = 50217 - oce_image_logic = 50218 - annotations = 50255 - print_im = 50341 - original_file_name = 50547 - uspto_original_content_type = 50560 - dng_version = 50706 - dng_backward_version = 50707 - unique_camera_model = 50708 - localized_camera_model = 50709 - cfa_plane_color = 50710 - cfa_layout = 50711 - linearization_table = 50712 - black_level_repeat_dim = 50713 - black_level = 50714 - black_level_delta_h = 50715 - black_level_delta_v = 50716 - white_level = 50717 - default_scale = 50718 - default_crop_origin = 50719 - default_crop_size = 50720 - color_matrix1 = 50721 - color_matrix2 = 50722 - camera_calibration1 = 50723 - camera_calibration2 = 50724 - reduction_matrix1 = 50725 - reduction_matrix2 = 50726 - analog_balance = 50727 - as_shot_neutral = 50728 - as_shot_white_xy = 50729 - baseline_exposure = 50730 - baseline_noise = 50731 - baseline_sharpness = 50732 - bayer_green_split = 50733 - linear_response_limit = 50734 - camera_serial_number = 50735 - dng_lens_info = 50736 - chroma_blur_radius = 50737 - anti_alias_strength = 50738 - shadow_scale = 50739 - sr2_private = 50740 - maker_note_safety = 50741 - raw_image_segmentation = 50752 - calibration_illuminant1 = 50778 - calibration_illuminant2 = 50779 - best_quality_scale = 50780 - raw_data_unique_id = 50781 - alias_layer_metadata = 50784 - original_raw_file_name = 50827 - original_raw_file_data = 50828 - active_area = 50829 - masked_areas = 50830 - as_shot_icc_profile = 50831 - as_shot_pre_profile_matrix = 50832 - current_icc_profile = 50833 - current_pre_profile_matrix = 50834 - colorimetric_reference = 50879 - s_raw_type = 50885 - panasonic_title = 50898 - panasonic_title2 = 50899 - camera_calibration_sig = 50931 - profile_calibration_sig = 50932 - profile_ifd = 50933 - as_shot_profile_name = 50934 - noise_reduction_applied = 50935 - profile_name = 50936 - profile_hue_sat_map_dims = 50937 - profile_hue_sat_map_data1 = 50938 - profile_hue_sat_map_data2 = 50939 - profile_tone_curve = 50940 - profile_embed_policy = 50941 - profile_copyright = 50942 - forward_matrix1 = 50964 - forward_matrix2 = 50965 - preview_application_name = 50966 - preview_application_version = 50967 - preview_settings_name = 50968 - preview_settings_digest = 50969 - preview_color_space = 50970 - preview_date_time = 50971 - raw_image_digest = 50972 - original_raw_file_digest = 50973 - sub_tile_block_size = 50974 - row_interleave_factor = 50975 - profile_look_table_dims = 50981 - profile_look_table_data = 50982 - opcode_list1 = 51008 - opcode_list2 = 51009 - opcode_list3 = 51022 - noise_profile = 51041 - time_codes = 51043 - frame_rate = 51044 - t_stop = 51058 - reel_name = 51081 - original_default_final_size = 51089 - original_best_quality_size = 51090 - original_default_crop_size = 51091 - camera_label = 51105 - profile_hue_sat_map_encoding = 51107 - profile_look_table_encoding = 51108 - baseline_exposure_offset = 51109 - default_black_render = 51110 - new_raw_image_digest = 51111 - raw_to_preview_gain = 51112 - default_user_crop = 51125 - padding = 59932 - offset_schema = 59933 - owner_name2 = 65000 - serial_number2 = 65001 - lens = 65002 - kdc_ifd = 65024 - raw_file = 65100 - converter = 65101 - white_balance2 = 65102 - exposure = 65105 - shadows = 65106 - brightness = 65107 - contrast2 = 65108 - saturation2 = 65109 - sharpness2 = 65110 - smoothness = 65111 - moire_filter = 65112 - SEQ_FIELDS = ["tag", "field_type", "length", "ofs_or_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = KaitaiStream.resolve_enum(self._root.IfdField.TagEnum, self._io.read_u2be()) - self._debug['tag']['end'] = self._io.pos() - self._debug['field_type']['start'] = self._io.pos() - self.field_type = KaitaiStream.resolve_enum(self._root.IfdField.FieldTypeEnum, self._io.read_u2be()) - self._debug['field_type']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4be() - self._debug['length']['end'] = self._io.pos() - self._debug['ofs_or_data']['start'] = self._io.pos() - self.ofs_or_data = self._io.read_u4be() - self._debug['ofs_or_data']['end'] = self._io.pos() - - @property - def type_byte_length(self): - if hasattr(self, '_m_type_byte_length'): - return self._m_type_byte_length if hasattr(self, '_m_type_byte_length') else None - - self._m_type_byte_length = (2 if self.field_type == self._root.IfdField.FieldTypeEnum.word else (4 if self.field_type == self._root.IfdField.FieldTypeEnum.dword else 1)) - return self._m_type_byte_length if hasattr(self, '_m_type_byte_length') else None - - @property - def byte_length(self): - if hasattr(self, '_m_byte_length'): - return self._m_byte_length if hasattr(self, '_m_byte_length') else None - - self._m_byte_length = (self.length * self.type_byte_length) - return self._m_byte_length if hasattr(self, '_m_byte_length') else None - - @property - def is_immediate_data(self): - if hasattr(self, '_m_is_immediate_data'): - return self._m_is_immediate_data if hasattr(self, '_m_is_immediate_data') else None - - self._m_is_immediate_data = self.byte_length <= 4 - return self._m_is_immediate_data if hasattr(self, '_m_is_immediate_data') else None - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - if not (self.is_immediate_data): - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_or_data) - self._debug['_m_data']['start'] = io.pos() - self._m_data = io.read_bytes(self.byte_length) - self._debug['_m_data']['end'] = io.pos() - io.seek(_pos) - - return self._m_data if hasattr(self, '_m_data') else None - - - @property - def ifd0(self): - if hasattr(self, '_m_ifd0'): - return self._m_ifd0 if hasattr(self, '_m_ifd0') else None - - _pos = self._io.pos() - self._io.seek(self.ifd0_ofs) - self._debug['_m_ifd0']['start'] = self._io.pos() - self._m_ifd0 = self._root.Ifd(self._io, self, self._root) - self._m_ifd0._read() - self._debug['_m_ifd0']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_ifd0 if hasattr(self, '_m_ifd0') else None - - diff --git a/python/examples/kaitai/exif_le.py b/python/examples/kaitai/exif_le.py deleted file mode 100644 index 4ea8edd6..00000000 --- a/python/examples/kaitai/exif_le.py +++ /dev/null @@ -1,620 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 ExifLe(KaitaiStruct): - SEQ_FIELDS = ["version", "ifd0_ofs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['ifd0_ofs']['start'] = self._io.pos() - self.ifd0_ofs = self._io.read_u4le() - self._debug['ifd0_ofs']['end'] = self._io.pos() - - class Ifd(KaitaiStruct): - SEQ_FIELDS = ["num_fields", "fields", "next_ifd_ofs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_fields']['start'] = self._io.pos() - self.num_fields = self._io.read_u2le() - self._debug['num_fields']['end'] = self._io.pos() - self._debug['fields']['start'] = self._io.pos() - self.fields = [None] * (self.num_fields) - for i in range(self.num_fields): - if not 'arr' in self._debug['fields']: - self._debug['fields']['arr'] = [] - self._debug['fields']['arr'].append({'start': self._io.pos()}) - _t_fields = self._root.IfdField(self._io, self, self._root) - _t_fields._read() - self.fields[i] = _t_fields - self._debug['fields']['arr'][i]['end'] = self._io.pos() - - self._debug['fields']['end'] = self._io.pos() - self._debug['next_ifd_ofs']['start'] = self._io.pos() - self.next_ifd_ofs = self._io.read_u4le() - self._debug['next_ifd_ofs']['end'] = self._io.pos() - - @property - def next_ifd(self): - if hasattr(self, '_m_next_ifd'): - return self._m_next_ifd if hasattr(self, '_m_next_ifd') else None - - if self.next_ifd_ofs != 0: - _pos = self._io.pos() - self._io.seek(self.next_ifd_ofs) - self._debug['_m_next_ifd']['start'] = self._io.pos() - self._m_next_ifd = self._root.Ifd(self._io, self, self._root) - self._m_next_ifd._read() - self._debug['_m_next_ifd']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_next_ifd if hasattr(self, '_m_next_ifd') else None - - - class IfdField(KaitaiStruct): - - class FieldTypeEnum(Enum): - byte = 1 - ascii_string = 2 - word = 3 - dword = 4 - rational = 5 - undefined = 7 - slong = 9 - srational = 10 - - class TagEnum(Enum): - image_width = 256 - image_height = 257 - bits_per_sample = 258 - compression = 259 - photometric_interpretation = 262 - thresholding = 263 - cell_width = 264 - cell_length = 265 - fill_order = 266 - document_name = 269 - image_description = 270 - make = 271 - model = 272 - strip_offsets = 273 - orientation = 274 - samples_per_pixel = 277 - rows_per_strip = 278 - strip_byte_counts = 279 - min_sample_value = 280 - max_sample_value = 281 - x_resolution = 282 - y_resolution = 283 - planar_configuration = 284 - page_name = 285 - x_position = 286 - y_position = 287 - free_offsets = 288 - free_byte_counts = 289 - gray_response_unit = 290 - gray_response_curve = 291 - t4_options = 292 - t6_options = 293 - resolution_unit = 296 - page_number = 297 - color_response_unit = 300 - transfer_function = 301 - software = 305 - modify_date = 306 - artist = 315 - host_computer = 316 - predictor = 317 - white_point = 318 - primary_chromaticities = 319 - color_map = 320 - halftone_hints = 321 - tile_width = 322 - tile_length = 323 - tile_offsets = 324 - tile_byte_counts = 325 - bad_fax_lines = 326 - clean_fax_data = 327 - consecutive_bad_fax_lines = 328 - sub_ifd = 330 - ink_set = 332 - ink_names = 333 - numberof_inks = 334 - dot_range = 336 - target_printer = 337 - extra_samples = 338 - sample_format = 339 - s_min_sample_value = 340 - s_max_sample_value = 341 - transfer_range = 342 - clip_path = 343 - x_clip_path_units = 344 - y_clip_path_units = 345 - indexed = 346 - jpeg_tables = 347 - opi_proxy = 351 - global_parameters_ifd = 400 - profile_type = 401 - fax_profile = 402 - coding_methods = 403 - version_year = 404 - mode_number = 405 - decode = 433 - default_image_color = 434 - t82_options = 435 - jpeg_tables2 = 437 - jpeg_proc = 512 - thumbnail_offset = 513 - thumbnail_length = 514 - jpeg_restart_interval = 515 - jpeg_lossless_predictors = 517 - jpeg_point_transforms = 518 - jpegq_tables = 519 - jpegdc_tables = 520 - jpegac_tables = 521 - y_cb_cr_coefficients = 529 - y_cb_cr_sub_sampling = 530 - y_cb_cr_positioning = 531 - reference_black_white = 532 - strip_row_counts = 559 - application_notes = 700 - uspto_miscellaneous = 999 - related_image_file_format = 4096 - related_image_width = 4097 - related_image_height = 4098 - rating = 18246 - xp_dip_xml = 18247 - stitch_info = 18248 - rating_percent = 18249 - sony_raw_file_type = 28672 - light_falloff_params = 28722 - chromatic_aberration_corr_params = 28725 - distortion_corr_params = 28727 - image_id = 32781 - wang_tag1 = 32931 - wang_annotation = 32932 - wang_tag3 = 32933 - wang_tag4 = 32934 - image_reference_points = 32953 - region_xform_tack_point = 32954 - warp_quadrilateral = 32955 - affine_transform_mat = 32956 - matteing = 32995 - data_type = 32996 - image_depth = 32997 - tile_depth = 32998 - image_full_width = 33300 - image_full_height = 33301 - texture_format = 33302 - wrap_modes = 33303 - fov_cot = 33304 - matrix_world_to_screen = 33305 - matrix_world_to_camera = 33306 - model2 = 33405 - cfa_repeat_pattern_dim = 33421 - cfa_pattern2 = 33422 - battery_level = 33423 - kodak_ifd = 33424 - copyright = 33432 - exposure_time = 33434 - f_number = 33437 - md_file_tag = 33445 - md_scale_pixel = 33446 - md_color_table = 33447 - md_lab_name = 33448 - md_sample_info = 33449 - md_prep_date = 33450 - md_prep_time = 33451 - md_file_units = 33452 - pixel_scale = 33550 - advent_scale = 33589 - advent_revision = 33590 - uic1_tag = 33628 - uic2_tag = 33629 - uic3_tag = 33630 - uic4_tag = 33631 - iptc_naa = 33723 - intergraph_packet_data = 33918 - intergraph_flag_registers = 33919 - intergraph_matrix = 33920 - ingr_reserved = 33921 - model_tie_point = 33922 - site = 34016 - color_sequence = 34017 - it8_header = 34018 - raster_padding = 34019 - bits_per_run_length = 34020 - bits_per_extended_run_length = 34021 - color_table = 34022 - image_color_indicator = 34023 - background_color_indicator = 34024 - image_color_value = 34025 - background_color_value = 34026 - pixel_intensity_range = 34027 - transparency_indicator = 34028 - color_characterization = 34029 - hc_usage = 34030 - trap_indicator = 34031 - cmyk_equivalent = 34032 - sem_info = 34118 - afcp_iptc = 34152 - pixel_magic_jbig_options = 34232 - jpl_carto_ifd = 34263 - model_transform = 34264 - wb_grgb_levels = 34306 - leaf_data = 34310 - photoshop_settings = 34377 - exif_offset = 34665 - icc_profile = 34675 - tiff_fx_extensions = 34687 - multi_profiles = 34688 - shared_data = 34689 - t88_options = 34690 - image_layer = 34732 - geo_tiff_directory = 34735 - geo_tiff_double_params = 34736 - geo_tiff_ascii_params = 34737 - jbig_options = 34750 - exposure_program = 34850 - spectral_sensitivity = 34852 - gps_info = 34853 - iso = 34855 - opto_electric_conv_factor = 34856 - interlace = 34857 - time_zone_offset = 34858 - self_timer_mode = 34859 - sensitivity_type = 34864 - standard_output_sensitivity = 34865 - recommended_exposure_index = 34866 - iso_speed = 34867 - iso_speed_latitudeyyy = 34868 - iso_speed_latitudezzz = 34869 - fax_recv_params = 34908 - fax_sub_address = 34909 - fax_recv_time = 34910 - fedex_edr = 34929 - leaf_sub_ifd = 34954 - exif_version = 36864 - date_time_original = 36867 - create_date = 36868 - google_plus_upload_code = 36873 - offset_time = 36880 - offset_time_original = 36881 - offset_time_digitized = 36882 - components_configuration = 37121 - compressed_bits_per_pixel = 37122 - shutter_speed_value = 37377 - aperture_value = 37378 - brightness_value = 37379 - exposure_compensation = 37380 - max_aperture_value = 37381 - subject_distance = 37382 - metering_mode = 37383 - light_source = 37384 - flash = 37385 - focal_length = 37386 - flash_energy = 37387 - spatial_frequency_response = 37388 - noise = 37389 - focal_plane_x_resolution = 37390 - focal_plane_y_resolution = 37391 - focal_plane_resolution_unit = 37392 - image_number = 37393 - security_classification = 37394 - image_history = 37395 - subject_area = 37396 - exposure_index = 37397 - tiff_ep_standard_id = 37398 - sensing_method = 37399 - cip3_data_file = 37434 - cip3_sheet = 37435 - cip3_side = 37436 - sto_nits = 37439 - maker_note = 37500 - user_comment = 37510 - sub_sec_time = 37520 - sub_sec_time_original = 37521 - sub_sec_time_digitized = 37522 - ms_document_text = 37679 - ms_property_set_storage = 37680 - ms_document_text_position = 37681 - image_source_data = 37724 - ambient_temperature = 37888 - humidity = 37889 - pressure = 37890 - water_depth = 37891 - acceleration = 37892 - camera_elevation_angle = 37893 - xp_title = 40091 - xp_comment = 40092 - xp_author = 40093 - xp_keywords = 40094 - xp_subject = 40095 - flashpix_version = 40960 - color_space = 40961 - exif_image_width = 40962 - exif_image_height = 40963 - related_sound_file = 40964 - interop_offset = 40965 - samsung_raw_pointers_offset = 40976 - samsung_raw_pointers_length = 40977 - samsung_raw_byte_order = 41217 - samsung_raw_unknown = 41218 - flash_energy2 = 41483 - spatial_frequency_response2 = 41484 - noise2 = 41485 - focal_plane_x_resolution2 = 41486 - focal_plane_y_resolution2 = 41487 - focal_plane_resolution_unit2 = 41488 - image_number2 = 41489 - security_classification2 = 41490 - image_history2 = 41491 - subject_location = 41492 - exposure_index2 = 41493 - tiff_ep_standard_id2 = 41494 - sensing_method2 = 41495 - file_source = 41728 - scene_type = 41729 - cfa_pattern = 41730 - custom_rendered = 41985 - exposure_mode = 41986 - white_balance = 41987 - digital_zoom_ratio = 41988 - focal_length_in35mm_format = 41989 - scene_capture_type = 41990 - gain_control = 41991 - contrast = 41992 - saturation = 41993 - sharpness = 41994 - device_setting_description = 41995 - subject_distance_range = 41996 - image_unique_id = 42016 - owner_name = 42032 - serial_number = 42033 - lens_info = 42034 - lens_make = 42035 - lens_model = 42036 - lens_serial_number = 42037 - gdal_metadata = 42112 - gdal_no_data = 42113 - gamma = 42240 - expand_software = 44992 - expand_lens = 44993 - expand_film = 44994 - expand_filter_lens = 44995 - expand_scanner = 44996 - expand_flash_lamp = 44997 - pixel_format = 48129 - transformation = 48130 - uncompressed = 48131 - image_type = 48132 - image_width2 = 48256 - image_height2 = 48257 - width_resolution = 48258 - height_resolution = 48259 - image_offset = 48320 - image_byte_count = 48321 - alpha_offset = 48322 - alpha_byte_count = 48323 - image_data_discard = 48324 - alpha_data_discard = 48325 - oce_scanjob_desc = 50215 - oce_application_selector = 50216 - oce_id_number = 50217 - oce_image_logic = 50218 - annotations = 50255 - print_im = 50341 - original_file_name = 50547 - uspto_original_content_type = 50560 - dng_version = 50706 - dng_backward_version = 50707 - unique_camera_model = 50708 - localized_camera_model = 50709 - cfa_plane_color = 50710 - cfa_layout = 50711 - linearization_table = 50712 - black_level_repeat_dim = 50713 - black_level = 50714 - black_level_delta_h = 50715 - black_level_delta_v = 50716 - white_level = 50717 - default_scale = 50718 - default_crop_origin = 50719 - default_crop_size = 50720 - color_matrix1 = 50721 - color_matrix2 = 50722 - camera_calibration1 = 50723 - camera_calibration2 = 50724 - reduction_matrix1 = 50725 - reduction_matrix2 = 50726 - analog_balance = 50727 - as_shot_neutral = 50728 - as_shot_white_xy = 50729 - baseline_exposure = 50730 - baseline_noise = 50731 - baseline_sharpness = 50732 - bayer_green_split = 50733 - linear_response_limit = 50734 - camera_serial_number = 50735 - dng_lens_info = 50736 - chroma_blur_radius = 50737 - anti_alias_strength = 50738 - shadow_scale = 50739 - sr2_private = 50740 - maker_note_safety = 50741 - raw_image_segmentation = 50752 - calibration_illuminant1 = 50778 - calibration_illuminant2 = 50779 - best_quality_scale = 50780 - raw_data_unique_id = 50781 - alias_layer_metadata = 50784 - original_raw_file_name = 50827 - original_raw_file_data = 50828 - active_area = 50829 - masked_areas = 50830 - as_shot_icc_profile = 50831 - as_shot_pre_profile_matrix = 50832 - current_icc_profile = 50833 - current_pre_profile_matrix = 50834 - colorimetric_reference = 50879 - s_raw_type = 50885 - panasonic_title = 50898 - panasonic_title2 = 50899 - camera_calibration_sig = 50931 - profile_calibration_sig = 50932 - profile_ifd = 50933 - as_shot_profile_name = 50934 - noise_reduction_applied = 50935 - profile_name = 50936 - profile_hue_sat_map_dims = 50937 - profile_hue_sat_map_data1 = 50938 - profile_hue_sat_map_data2 = 50939 - profile_tone_curve = 50940 - profile_embed_policy = 50941 - profile_copyright = 50942 - forward_matrix1 = 50964 - forward_matrix2 = 50965 - preview_application_name = 50966 - preview_application_version = 50967 - preview_settings_name = 50968 - preview_settings_digest = 50969 - preview_color_space = 50970 - preview_date_time = 50971 - raw_image_digest = 50972 - original_raw_file_digest = 50973 - sub_tile_block_size = 50974 - row_interleave_factor = 50975 - profile_look_table_dims = 50981 - profile_look_table_data = 50982 - opcode_list1 = 51008 - opcode_list2 = 51009 - opcode_list3 = 51022 - noise_profile = 51041 - time_codes = 51043 - frame_rate = 51044 - t_stop = 51058 - reel_name = 51081 - original_default_final_size = 51089 - original_best_quality_size = 51090 - original_default_crop_size = 51091 - camera_label = 51105 - profile_hue_sat_map_encoding = 51107 - profile_look_table_encoding = 51108 - baseline_exposure_offset = 51109 - default_black_render = 51110 - new_raw_image_digest = 51111 - raw_to_preview_gain = 51112 - default_user_crop = 51125 - padding = 59932 - offset_schema = 59933 - owner_name2 = 65000 - serial_number2 = 65001 - lens = 65002 - kdc_ifd = 65024 - raw_file = 65100 - converter = 65101 - white_balance2 = 65102 - exposure = 65105 - shadows = 65106 - brightness = 65107 - contrast2 = 65108 - saturation2 = 65109 - sharpness2 = 65110 - smoothness = 65111 - moire_filter = 65112 - SEQ_FIELDS = ["tag", "field_type", "length", "ofs_or_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = KaitaiStream.resolve_enum(self._root.IfdField.TagEnum, self._io.read_u2le()) - self._debug['tag']['end'] = self._io.pos() - self._debug['field_type']['start'] = self._io.pos() - self.field_type = KaitaiStream.resolve_enum(self._root.IfdField.FieldTypeEnum, self._io.read_u2le()) - self._debug['field_type']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['ofs_or_data']['start'] = self._io.pos() - self.ofs_or_data = self._io.read_u4le() - self._debug['ofs_or_data']['end'] = self._io.pos() - - @property - def type_byte_length(self): - if hasattr(self, '_m_type_byte_length'): - return self._m_type_byte_length if hasattr(self, '_m_type_byte_length') else None - - self._m_type_byte_length = (2 if self.field_type == self._root.IfdField.FieldTypeEnum.word else (4 if self.field_type == self._root.IfdField.FieldTypeEnum.dword else 1)) - return self._m_type_byte_length if hasattr(self, '_m_type_byte_length') else None - - @property - def byte_length(self): - if hasattr(self, '_m_byte_length'): - return self._m_byte_length if hasattr(self, '_m_byte_length') else None - - self._m_byte_length = (self.length * self.type_byte_length) - return self._m_byte_length if hasattr(self, '_m_byte_length') else None - - @property - def is_immediate_data(self): - if hasattr(self, '_m_is_immediate_data'): - return self._m_is_immediate_data if hasattr(self, '_m_is_immediate_data') else None - - self._m_is_immediate_data = self.byte_length <= 4 - return self._m_is_immediate_data if hasattr(self, '_m_is_immediate_data') else None - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - if not (self.is_immediate_data): - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_or_data) - self._debug['_m_data']['start'] = io.pos() - self._m_data = io.read_bytes(self.byte_length) - self._debug['_m_data']['end'] = io.pos() - io.seek(_pos) - - return self._m_data if hasattr(self, '_m_data') else None - - - @property - def ifd0(self): - if hasattr(self, '_m_ifd0'): - return self._m_ifd0 if hasattr(self, '_m_ifd0') else None - - _pos = self._io.pos() - self._io.seek(self.ifd0_ofs) - self._debug['_m_ifd0']['start'] = self._io.pos() - self._m_ifd0 = self._root.Ifd(self._io, self, self._root) - self._m_ifd0._read() - self._debug['_m_ifd0']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_ifd0 if hasattr(self, '_m_ifd0') else None - - diff --git a/python/examples/kaitai/ext2.py b/python/examples/kaitai/ext2.py deleted file mode 100644 index 50cf4824..00000000 --- a/python/examples/kaitai/ext2.py +++ /dev/null @@ -1,534 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Ext2(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class SuperBlockStruct(KaitaiStruct): - - class StateEnum(Enum): - valid_fs = 1 - error_fs = 2 - - class ErrorsEnum(Enum): - act_continue = 1 - act_ro = 2 - act_panic = 3 - SEQ_FIELDS = ["inodes_count", "blocks_count", "r_blocks_count", "free_blocks_count", "free_inodes_count", "first_data_block", "log_block_size", "log_frag_size", "blocks_per_group", "frags_per_group", "inodes_per_group", "mtime", "wtime", "mnt_count", "max_mnt_count", "magic", "state", "errors", "minor_rev_level", "lastcheck", "checkinterval", "creator_os", "rev_level", "def_resuid", "def_resgid", "first_ino", "inode_size", "block_group_nr", "feature_compat", "feature_incompat", "feature_ro_compat", "uuid", "volume_name", "last_mounted", "algo_bitmap", "prealloc_blocks", "prealloc_dir_blocks", "padding1", "journal_uuid", "journal_inum", "journal_dev", "last_orphan", "hash_seed", "def_hash_version"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['inodes_count']['start'] = self._io.pos() - self.inodes_count = self._io.read_u4le() - self._debug['inodes_count']['end'] = self._io.pos() - self._debug['blocks_count']['start'] = self._io.pos() - self.blocks_count = self._io.read_u4le() - self._debug['blocks_count']['end'] = self._io.pos() - self._debug['r_blocks_count']['start'] = self._io.pos() - self.r_blocks_count = self._io.read_u4le() - self._debug['r_blocks_count']['end'] = self._io.pos() - self._debug['free_blocks_count']['start'] = self._io.pos() - self.free_blocks_count = self._io.read_u4le() - self._debug['free_blocks_count']['end'] = self._io.pos() - self._debug['free_inodes_count']['start'] = self._io.pos() - self.free_inodes_count = self._io.read_u4le() - self._debug['free_inodes_count']['end'] = self._io.pos() - self._debug['first_data_block']['start'] = self._io.pos() - self.first_data_block = self._io.read_u4le() - self._debug['first_data_block']['end'] = self._io.pos() - self._debug['log_block_size']['start'] = self._io.pos() - self.log_block_size = self._io.read_u4le() - self._debug['log_block_size']['end'] = self._io.pos() - self._debug['log_frag_size']['start'] = self._io.pos() - self.log_frag_size = self._io.read_u4le() - self._debug['log_frag_size']['end'] = self._io.pos() - self._debug['blocks_per_group']['start'] = self._io.pos() - self.blocks_per_group = self._io.read_u4le() - self._debug['blocks_per_group']['end'] = self._io.pos() - self._debug['frags_per_group']['start'] = self._io.pos() - self.frags_per_group = self._io.read_u4le() - self._debug['frags_per_group']['end'] = self._io.pos() - self._debug['inodes_per_group']['start'] = self._io.pos() - self.inodes_per_group = self._io.read_u4le() - self._debug['inodes_per_group']['end'] = self._io.pos() - self._debug['mtime']['start'] = self._io.pos() - self.mtime = self._io.read_u4le() - self._debug['mtime']['end'] = self._io.pos() - self._debug['wtime']['start'] = self._io.pos() - self.wtime = self._io.read_u4le() - self._debug['wtime']['end'] = self._io.pos() - self._debug['mnt_count']['start'] = self._io.pos() - self.mnt_count = self._io.read_u2le() - self._debug['mnt_count']['end'] = self._io.pos() - self._debug['max_mnt_count']['start'] = self._io.pos() - self.max_mnt_count = self._io.read_u2le() - self._debug['max_mnt_count']['end'] = self._io.pos() - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x53\xEF") - self._debug['magic']['end'] = self._io.pos() - self._debug['state']['start'] = self._io.pos() - self.state = KaitaiStream.resolve_enum(self._root.SuperBlockStruct.StateEnum, self._io.read_u2le()) - self._debug['state']['end'] = self._io.pos() - self._debug['errors']['start'] = self._io.pos() - self.errors = KaitaiStream.resolve_enum(self._root.SuperBlockStruct.ErrorsEnum, self._io.read_u2le()) - self._debug['errors']['end'] = self._io.pos() - self._debug['minor_rev_level']['start'] = self._io.pos() - self.minor_rev_level = self._io.read_u2le() - self._debug['minor_rev_level']['end'] = self._io.pos() - self._debug['lastcheck']['start'] = self._io.pos() - self.lastcheck = self._io.read_u4le() - self._debug['lastcheck']['end'] = self._io.pos() - self._debug['checkinterval']['start'] = self._io.pos() - self.checkinterval = self._io.read_u4le() - self._debug['checkinterval']['end'] = self._io.pos() - self._debug['creator_os']['start'] = self._io.pos() - self.creator_os = self._io.read_u4le() - self._debug['creator_os']['end'] = self._io.pos() - self._debug['rev_level']['start'] = self._io.pos() - self.rev_level = self._io.read_u4le() - self._debug['rev_level']['end'] = self._io.pos() - self._debug['def_resuid']['start'] = self._io.pos() - self.def_resuid = self._io.read_u2le() - self._debug['def_resuid']['end'] = self._io.pos() - self._debug['def_resgid']['start'] = self._io.pos() - self.def_resgid = self._io.read_u2le() - self._debug['def_resgid']['end'] = self._io.pos() - self._debug['first_ino']['start'] = self._io.pos() - self.first_ino = self._io.read_u4le() - self._debug['first_ino']['end'] = self._io.pos() - self._debug['inode_size']['start'] = self._io.pos() - self.inode_size = self._io.read_u2le() - self._debug['inode_size']['end'] = self._io.pos() - self._debug['block_group_nr']['start'] = self._io.pos() - self.block_group_nr = self._io.read_u2le() - self._debug['block_group_nr']['end'] = self._io.pos() - self._debug['feature_compat']['start'] = self._io.pos() - self.feature_compat = self._io.read_u4le() - self._debug['feature_compat']['end'] = self._io.pos() - self._debug['feature_incompat']['start'] = self._io.pos() - self.feature_incompat = self._io.read_u4le() - self._debug['feature_incompat']['end'] = self._io.pos() - self._debug['feature_ro_compat']['start'] = self._io.pos() - self.feature_ro_compat = self._io.read_u4le() - self._debug['feature_ro_compat']['end'] = self._io.pos() - self._debug['uuid']['start'] = self._io.pos() - self.uuid = self._io.read_bytes(16) - self._debug['uuid']['end'] = self._io.pos() - self._debug['volume_name']['start'] = self._io.pos() - self.volume_name = self._io.read_bytes(16) - self._debug['volume_name']['end'] = self._io.pos() - self._debug['last_mounted']['start'] = self._io.pos() - self.last_mounted = self._io.read_bytes(64) - self._debug['last_mounted']['end'] = self._io.pos() - self._debug['algo_bitmap']['start'] = self._io.pos() - self.algo_bitmap = self._io.read_u4le() - self._debug['algo_bitmap']['end'] = self._io.pos() - self._debug['prealloc_blocks']['start'] = self._io.pos() - self.prealloc_blocks = self._io.read_u1() - self._debug['prealloc_blocks']['end'] = self._io.pos() - self._debug['prealloc_dir_blocks']['start'] = self._io.pos() - self.prealloc_dir_blocks = self._io.read_u1() - self._debug['prealloc_dir_blocks']['end'] = self._io.pos() - self._debug['padding1']['start'] = self._io.pos() - self.padding1 = self._io.read_bytes(2) - self._debug['padding1']['end'] = self._io.pos() - self._debug['journal_uuid']['start'] = self._io.pos() - self.journal_uuid = self._io.read_bytes(16) - self._debug['journal_uuid']['end'] = self._io.pos() - self._debug['journal_inum']['start'] = self._io.pos() - self.journal_inum = self._io.read_u4le() - self._debug['journal_inum']['end'] = self._io.pos() - self._debug['journal_dev']['start'] = self._io.pos() - self.journal_dev = self._io.read_u4le() - self._debug['journal_dev']['end'] = self._io.pos() - self._debug['last_orphan']['start'] = self._io.pos() - self.last_orphan = self._io.read_u4le() - self._debug['last_orphan']['end'] = self._io.pos() - self._debug['hash_seed']['start'] = self._io.pos() - self.hash_seed = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['hash_seed']: - self._debug['hash_seed']['arr'] = [] - self._debug['hash_seed']['arr'].append({'start': self._io.pos()}) - self.hash_seed[i] = self._io.read_u4le() - self._debug['hash_seed']['arr'][i]['end'] = self._io.pos() - - self._debug['hash_seed']['end'] = self._io.pos() - self._debug['def_hash_version']['start'] = self._io.pos() - self.def_hash_version = self._io.read_u1() - self._debug['def_hash_version']['end'] = self._io.pos() - - @property - def block_size(self): - if hasattr(self, '_m_block_size'): - return self._m_block_size if hasattr(self, '_m_block_size') else None - - self._m_block_size = (1024 << self.log_block_size) - return self._m_block_size if hasattr(self, '_m_block_size') else None - - @property - def block_group_count(self): - if hasattr(self, '_m_block_group_count'): - return self._m_block_group_count if hasattr(self, '_m_block_group_count') else None - - self._m_block_group_count = self.blocks_count // self.blocks_per_group - return self._m_block_group_count if hasattr(self, '_m_block_group_count') else None - - - class DirEntry(KaitaiStruct): - - class FileTypeEnum(Enum): - unknown = 0 - reg_file = 1 - dir = 2 - chrdev = 3 - blkdev = 4 - fifo = 5 - sock = 6 - symlink = 7 - SEQ_FIELDS = ["inode_ptr", "rec_len", "name_len", "file_type", "name", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['inode_ptr']['start'] = self._io.pos() - self.inode_ptr = self._io.read_u4le() - self._debug['inode_ptr']['end'] = self._io.pos() - self._debug['rec_len']['start'] = self._io.pos() - self.rec_len = self._io.read_u2le() - self._debug['rec_len']['end'] = self._io.pos() - self._debug['name_len']['start'] = self._io.pos() - self.name_len = self._io.read_u1() - self._debug['name_len']['end'] = self._io.pos() - self._debug['file_type']['start'] = self._io.pos() - self.file_type = KaitaiStream.resolve_enum(self._root.DirEntry.FileTypeEnum, self._io.read_u1()) - self._debug['file_type']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.name_len)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes(((self.rec_len - self.name_len) - 8)) - self._debug['padding']['end'] = self._io.pos() - - @property - def inode(self): - if hasattr(self, '_m_inode'): - return self._m_inode if hasattr(self, '_m_inode') else None - - self._m_inode = self._root.bg1.block_groups[(self.inode_ptr - 1) // self._root.bg1.super_block.inodes_per_group].inodes[((self.inode_ptr - 1) % self._root.bg1.super_block.inodes_per_group)] - return self._m_inode if hasattr(self, '_m_inode') else None - - - class Inode(KaitaiStruct): - SEQ_FIELDS = ["mode", "uid", "size", "atime", "ctime", "mtime", "dtime", "gid", "links_count", "blocks", "flags", "osd1", "block", "generation", "file_acl", "dir_acl", "faddr", "osd2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['mode']['start'] = self._io.pos() - self.mode = self._io.read_u2le() - self._debug['mode']['end'] = self._io.pos() - self._debug['uid']['start'] = self._io.pos() - self.uid = self._io.read_u2le() - self._debug['uid']['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['atime']['start'] = self._io.pos() - self.atime = self._io.read_u4le() - self._debug['atime']['end'] = self._io.pos() - self._debug['ctime']['start'] = self._io.pos() - self.ctime = self._io.read_u4le() - self._debug['ctime']['end'] = self._io.pos() - self._debug['mtime']['start'] = self._io.pos() - self.mtime = self._io.read_u4le() - self._debug['mtime']['end'] = self._io.pos() - self._debug['dtime']['start'] = self._io.pos() - self.dtime = self._io.read_u4le() - self._debug['dtime']['end'] = self._io.pos() - self._debug['gid']['start'] = self._io.pos() - self.gid = self._io.read_u2le() - self._debug['gid']['end'] = self._io.pos() - self._debug['links_count']['start'] = self._io.pos() - self.links_count = self._io.read_u2le() - self._debug['links_count']['end'] = self._io.pos() - self._debug['blocks']['start'] = self._io.pos() - self.blocks = self._io.read_u4le() - self._debug['blocks']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['osd1']['start'] = self._io.pos() - self.osd1 = self._io.read_u4le() - self._debug['osd1']['end'] = self._io.pos() - self._debug['block']['start'] = self._io.pos() - self.block = [None] * (15) - for i in range(15): - if not 'arr' in self._debug['block']: - self._debug['block']['arr'] = [] - self._debug['block']['arr'].append({'start': self._io.pos()}) - _t_block = self._root.BlockPtr(self._io, self, self._root) - _t_block._read() - self.block[i] = _t_block - self._debug['block']['arr'][i]['end'] = self._io.pos() - - self._debug['block']['end'] = self._io.pos() - self._debug['generation']['start'] = self._io.pos() - self.generation = self._io.read_u4le() - self._debug['generation']['end'] = self._io.pos() - self._debug['file_acl']['start'] = self._io.pos() - self.file_acl = self._io.read_u4le() - self._debug['file_acl']['end'] = self._io.pos() - self._debug['dir_acl']['start'] = self._io.pos() - self.dir_acl = self._io.read_u4le() - self._debug['dir_acl']['end'] = self._io.pos() - self._debug['faddr']['start'] = self._io.pos() - self.faddr = self._io.read_u4le() - self._debug['faddr']['end'] = self._io.pos() - self._debug['osd2']['start'] = self._io.pos() - self.osd2 = self._io.read_bytes(12) - self._debug['osd2']['end'] = self._io.pos() - - @property - def as_dir(self): - if hasattr(self, '_m_as_dir'): - return self._m_as_dir if hasattr(self, '_m_as_dir') else None - - io = self.block[0].body._io - _pos = io.pos() - io.seek(0) - self._debug['_m_as_dir']['start'] = io.pos() - self._m_as_dir = self._root.Dir(io, self, self._root) - self._m_as_dir._read() - self._debug['_m_as_dir']['end'] = io.pos() - io.seek(_pos) - return self._m_as_dir if hasattr(self, '_m_as_dir') else None - - - class BlockPtr(KaitaiStruct): - SEQ_FIELDS = ["ptr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ptr']['start'] = self._io.pos() - self.ptr = self._io.read_u4le() - self._debug['ptr']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek((self.ptr * self._root.bg1.super_block.block_size)) - self._debug['_m_body']['start'] = self._io.pos() - self._raw__m_body = self._io.read_bytes(self._root.bg1.super_block.block_size) - io = KaitaiStream(BytesIO(self._raw__m_body)) - self._m_body = self._root.RawBlock(io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class Dir(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.DirEntry(self._io, self, self._root) - _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() - - - class BlockGroup(KaitaiStruct): - SEQ_FIELDS = ["super_block", "block_groups"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['super_block']['start'] = self._io.pos() - self._raw_super_block = self._io.read_bytes(1024) - io = KaitaiStream(BytesIO(self._raw_super_block)) - self.super_block = self._root.SuperBlockStruct(io, self, self._root) - self.super_block._read() - self._debug['super_block']['end'] = self._io.pos() - self._debug['block_groups']['start'] = self._io.pos() - self.block_groups = [None] * (self.super_block.block_group_count) - for i in range(self.super_block.block_group_count): - if not 'arr' in self._debug['block_groups']: - self._debug['block_groups']['arr'] = [] - self._debug['block_groups']['arr'].append({'start': self._io.pos()}) - _t_block_groups = self._root.Bgd(self._io, self, self._root) - _t_block_groups._read() - self.block_groups[i] = _t_block_groups - self._debug['block_groups']['arr'][i]['end'] = self._io.pos() - - self._debug['block_groups']['end'] = self._io.pos() - - - class Bgd(KaitaiStruct): - SEQ_FIELDS = ["block_bitmap_block", "inode_bitmap_block", "inode_table_block", "free_blocks_count", "free_inodes_count", "used_dirs_count", "pad_reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_bitmap_block']['start'] = self._io.pos() - self.block_bitmap_block = self._io.read_u4le() - self._debug['block_bitmap_block']['end'] = self._io.pos() - self._debug['inode_bitmap_block']['start'] = self._io.pos() - self.inode_bitmap_block = self._io.read_u4le() - self._debug['inode_bitmap_block']['end'] = self._io.pos() - self._debug['inode_table_block']['start'] = self._io.pos() - self.inode_table_block = self._io.read_u4le() - self._debug['inode_table_block']['end'] = self._io.pos() - self._debug['free_blocks_count']['start'] = self._io.pos() - self.free_blocks_count = self._io.read_u2le() - self._debug['free_blocks_count']['end'] = self._io.pos() - self._debug['free_inodes_count']['start'] = self._io.pos() - self.free_inodes_count = self._io.read_u2le() - self._debug['free_inodes_count']['end'] = self._io.pos() - self._debug['used_dirs_count']['start'] = self._io.pos() - self.used_dirs_count = self._io.read_u2le() - self._debug['used_dirs_count']['end'] = self._io.pos() - self._debug['pad_reserved']['start'] = self._io.pos() - self.pad_reserved = self._io.read_bytes((2 + 12)) - self._debug['pad_reserved']['end'] = self._io.pos() - - @property - def block_bitmap(self): - if hasattr(self, '_m_block_bitmap'): - return self._m_block_bitmap if hasattr(self, '_m_block_bitmap') else None - - _pos = self._io.pos() - self._io.seek((self.block_bitmap_block * self._root.bg1.super_block.block_size)) - self._debug['_m_block_bitmap']['start'] = self._io.pos() - self._m_block_bitmap = self._io.read_bytes(1024) - self._debug['_m_block_bitmap']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_block_bitmap if hasattr(self, '_m_block_bitmap') else None - - @property - def inode_bitmap(self): - if hasattr(self, '_m_inode_bitmap'): - return self._m_inode_bitmap if hasattr(self, '_m_inode_bitmap') else None - - _pos = self._io.pos() - self._io.seek((self.inode_bitmap_block * self._root.bg1.super_block.block_size)) - self._debug['_m_inode_bitmap']['start'] = self._io.pos() - self._m_inode_bitmap = self._io.read_bytes(1024) - self._debug['_m_inode_bitmap']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_inode_bitmap if hasattr(self, '_m_inode_bitmap') else None - - @property - def inodes(self): - if hasattr(self, '_m_inodes'): - return self._m_inodes if hasattr(self, '_m_inodes') else None - - _pos = self._io.pos() - self._io.seek((self.inode_table_block * self._root.bg1.super_block.block_size)) - self._debug['_m_inodes']['start'] = self._io.pos() - self._m_inodes = [None] * (self._root.bg1.super_block.inodes_per_group) - for i in range(self._root.bg1.super_block.inodes_per_group): - if not 'arr' in self._debug['_m_inodes']: - self._debug['_m_inodes']['arr'] = [] - self._debug['_m_inodes']['arr'].append({'start': self._io.pos()}) - _t__m_inodes = self._root.Inode(self._io, self, self._root) - _t__m_inodes._read() - self._m_inodes[i] = _t__m_inodes - self._debug['_m_inodes']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_inodes']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_inodes if hasattr(self, '_m_inodes') else None - - - class RawBlock(KaitaiStruct): - SEQ_FIELDS = ["body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self._root.bg1.super_block.block_size) - self._debug['body']['end'] = self._io.pos() - - - @property - def bg1(self): - if hasattr(self, '_m_bg1'): - return self._m_bg1 if hasattr(self, '_m_bg1') else None - - _pos = self._io.pos() - self._io.seek(1024) - self._debug['_m_bg1']['start'] = self._io.pos() - self._m_bg1 = self._root.BlockGroup(self._io, self, self._root) - self._m_bg1._read() - self._debug['_m_bg1']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_bg1 if hasattr(self, '_m_bg1') else None - - @property - def root_dir(self): - if hasattr(self, '_m_root_dir'): - return self._m_root_dir if hasattr(self, '_m_root_dir') else None - - self._m_root_dir = self.bg1.block_groups[0].inodes[1].as_dir - return self._m_root_dir if hasattr(self, '_m_root_dir') else None - - diff --git a/python/examples/kaitai/fallout2_dat.py b/python/examples/kaitai/fallout2_dat.py deleted file mode 100644 index c6350d89..00000000 --- a/python/examples/kaitai/fallout2_dat.py +++ /dev/null @@ -1,160 +0,0 @@ -# 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 -import collections -import zlib - - -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 Fallout2Dat(KaitaiStruct): - - class Compression(Enum): - none = 0 - zlib = 1 - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class Pstr(KaitaiStruct): - SEQ_FIELDS = ["size", "str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - self._debug['str']['start'] = self._io.pos() - self.str = (self._io.read_bytes(self.size)).decode(u"ASCII") - self._debug['str']['end'] = self._io.pos() - - - class Footer(KaitaiStruct): - SEQ_FIELDS = ["index_size", "file_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['index_size']['start'] = self._io.pos() - self.index_size = self._io.read_u4le() - self._debug['index_size']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u4le() - self._debug['file_size']['end'] = self._io.pos() - - - class Index(KaitaiStruct): - SEQ_FIELDS = ["file_count", "files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_count']['start'] = self._io.pos() - self.file_count = self._io.read_u4le() - self._debug['file_count']['end'] = self._io.pos() - self._debug['files']['start'] = self._io.pos() - self.files = [None] * (self.file_count) - for i in range(self.file_count): - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.File(self._io, self, self._root) - _t_files._read() - self.files[i] = _t_files - self._debug['files']['arr'][i]['end'] = self._io.pos() - - self._debug['files']['end'] = self._io.pos() - - - class File(KaitaiStruct): - SEQ_FIELDS = ["name", "flags", "size_unpacked", "size_packed", "offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.Pstr(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.Compression, self._io.read_u1()) - self._debug['flags']['end'] = self._io.pos() - self._debug['size_unpacked']['start'] = self._io.pos() - self.size_unpacked = self._io.read_u4le() - self._debug['size_unpacked']['end'] = self._io.pos() - self._debug['size_packed']['start'] = self._io.pos() - self.size_packed = self._io.read_u4le() - self._debug['size_packed']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['end'] = self._io.pos() - - @property - def contents(self): - if hasattr(self, '_m_contents'): - return self._m_contents if hasattr(self, '_m_contents') else None - - if self.flags == self._root.Compression.zlib: - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_contents']['start'] = io.pos() - self._raw__m_contents = io.read_bytes(self.size_packed) - self._m_contents = zlib.decompress(self._raw__m_contents) - self._debug['_m_contents']['end'] = io.pos() - io.seek(_pos) - - return self._m_contents if hasattr(self, '_m_contents') else None - - - @property - def footer(self): - if hasattr(self, '_m_footer'): - return self._m_footer if hasattr(self, '_m_footer') else None - - _pos = self._io.pos() - self._io.seek((self._io.size() - 8)) - self._debug['_m_footer']['start'] = self._io.pos() - self._m_footer = self._root.Footer(self._io, self, self._root) - self._m_footer._read() - self._debug['_m_footer']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_footer if hasattr(self, '_m_footer') else None - - @property - def index(self): - if hasattr(self, '_m_index'): - return self._m_index if hasattr(self, '_m_index') else None - - _pos = self._io.pos() - self._io.seek(((self._io.size() - 8) - self.footer.index_size)) - self._debug['_m_index']['start'] = self._io.pos() - self._m_index = self._root.Index(self._io, self, self._root) - self._m_index._read() - self._debug['_m_index']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_index if hasattr(self, '_m_index') else None - - diff --git a/python/examples/kaitai/fallout_dat.py b/python/examples/kaitai/fallout_dat.py deleted file mode 100644 index 5885100c..00000000 --- a/python/examples/kaitai/fallout_dat.py +++ /dev/null @@ -1,155 +0,0 @@ -# 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 -import collections - - -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 FalloutDat(KaitaiStruct): - - class Compression(Enum): - none = 32 - lzss = 64 - SEQ_FIELDS = ["folder_count", "unknown1", "unknown2", "timestamp", "folder_names", "folders"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['folder_count']['start'] = self._io.pos() - self.folder_count = self._io.read_u4be() - self._debug['folder_count']['end'] = self._io.pos() - self._debug['unknown1']['start'] = self._io.pos() - self.unknown1 = self._io.read_u4be() - self._debug['unknown1']['end'] = self._io.pos() - self._debug['unknown2']['start'] = self._io.pos() - self.unknown2 = self._io.read_u4be() - self._debug['unknown2']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4be() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['folder_names']['start'] = self._io.pos() - self.folder_names = [None] * (self.folder_count) - for i in range(self.folder_count): - if not 'arr' in self._debug['folder_names']: - self._debug['folder_names']['arr'] = [] - self._debug['folder_names']['arr'].append({'start': self._io.pos()}) - _t_folder_names = self._root.Pstr(self._io, self, self._root) - _t_folder_names._read() - self.folder_names[i] = _t_folder_names - self._debug['folder_names']['arr'][i]['end'] = self._io.pos() - - self._debug['folder_names']['end'] = self._io.pos() - self._debug['folders']['start'] = self._io.pos() - self.folders = [None] * (self.folder_count) - for i in range(self.folder_count): - if not 'arr' in self._debug['folders']: - self._debug['folders']['arr'] = [] - self._debug['folders']['arr'].append({'start': self._io.pos()}) - _t_folders = self._root.Folder(self._io, self, self._root) - _t_folders._read() - self.folders[i] = _t_folders - self._debug['folders']['arr'][i]['end'] = self._io.pos() - - self._debug['folders']['end'] = self._io.pos() - - class Pstr(KaitaiStruct): - SEQ_FIELDS = ["size", "str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u1() - self._debug['size']['end'] = self._io.pos() - self._debug['str']['start'] = self._io.pos() - self.str = (self._io.read_bytes(self.size)).decode(u"ASCII") - self._debug['str']['end'] = self._io.pos() - - - class Folder(KaitaiStruct): - SEQ_FIELDS = ["file_count", "unknown", "flags", "timestamp", "files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_count']['start'] = self._io.pos() - self.file_count = self._io.read_u4be() - self._debug['file_count']['end'] = self._io.pos() - self._debug['unknown']['start'] = self._io.pos() - self.unknown = self._io.read_u4be() - self._debug['unknown']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4be() - self._debug['flags']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4be() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['files']['start'] = self._io.pos() - self.files = [None] * (self.file_count) - for i in range(self.file_count): - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.File(self._io, self, self._root) - _t_files._read() - self.files[i] = _t_files - self._debug['files']['arr'][i]['end'] = self._io.pos() - - self._debug['files']['end'] = self._io.pos() - - - class File(KaitaiStruct): - SEQ_FIELDS = ["name", "flags", "offset", "size_unpacked", "size_packed"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.Pstr(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.Compression, self._io.read_u4be()) - self._debug['flags']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4be() - self._debug['offset']['end'] = self._io.pos() - self._debug['size_unpacked']['start'] = self._io.pos() - self.size_unpacked = self._io.read_u4be() - self._debug['size_unpacked']['end'] = self._io.pos() - self._debug['size_packed']['start'] = self._io.pos() - self.size_packed = self._io.read_u4be() - self._debug['size_packed']['end'] = self._io.pos() - - @property - 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() - self._m_contents = io.read_bytes((self.size_unpacked if self.flags == self._root.Compression.none else self.size_packed)) - self._debug['_m_contents']['end'] = io.pos() - io.seek(_pos) - return self._m_contents if hasattr(self, '_m_contents') else None - - - diff --git a/python/examples/kaitai/fasttracker_xm_module.py b/python/examples/kaitai/fasttracker_xm_module.py deleted file mode 100644 index 9dacb370..00000000 --- a/python/examples/kaitai/fasttracker_xm_module.py +++ /dev/null @@ -1,553 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 FasttrackerXmModule(KaitaiStruct): - """XM (standing for eXtended Module) is a popular module music file - format, that was introduced in 1994 in FastTracker2 by Triton demo - group. Akin to MOD files, it bundles both digital samples - (instruments) and instructions on which note to play at what time - (patterns), which provides good audio quality with relatively small - file size. Audio is reproducible without relying on the sound of - particular hardware samplers or synths. - - .. seealso:: - Source - http://sid.ethz.ch/debian/milkytracker/milkytracker-0.90.85%2Bdfsg/resources/reference/xm-form.txt - ftp://ftp.modland.com/pub/documents/format_documentation/FastTracker%202%20v2.04%20(.xm).html - """ - SEQ_FIELDS = ["preheader", "header", "patterns", "instruments"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['preheader']['start'] = self._io.pos() - self.preheader = self._root.Preheader(self._io, self, self._root) - self.preheader._read() - self._debug['preheader']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes((self.preheader.header_size - 4)) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['patterns']['start'] = self._io.pos() - self.patterns = [None] * (self.header.num_patterns) - for i in range(self.header.num_patterns): - if not 'arr' in self._debug['patterns']: - self._debug['patterns']['arr'] = [] - self._debug['patterns']['arr'].append({'start': self._io.pos()}) - _t_patterns = self._root.Pattern(self._io, self, self._root) - _t_patterns._read() - self.patterns[i] = _t_patterns - self._debug['patterns']['arr'][i]['end'] = self._io.pos() - - self._debug['patterns']['end'] = self._io.pos() - self._debug['instruments']['start'] = self._io.pos() - self.instruments = [None] * (self.header.num_instruments) - for i in range(self.header.num_instruments): - if not 'arr' in self._debug['instruments']: - self._debug['instruments']['arr'] = [] - self._debug['instruments']['arr'].append({'start': self._io.pos()}) - _t_instruments = self._root.Instrument(self._io, self, self._root) - _t_instruments._read() - self.instruments[i] = _t_instruments - self._debug['instruments']['arr'][i]['end'] = self._io.pos() - - self._debug['instruments']['end'] = self._io.pos() - - class Preheader(KaitaiStruct): - SEQ_FIELDS = ["signature0", "module_name", "signature1", "tracker_name", "version_number", "header_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature0']['start'] = self._io.pos() - self.signature0 = self._io.ensure_fixed_contents(b"\x45\x78\x74\x65\x6E\x64\x65\x64\x20\x4D\x6F\x64\x75\x6C\x65\x3A\x20") - self._debug['signature0']['end'] = self._io.pos() - self._debug['module_name']['start'] = self._io.pos() - self.module_name = (KaitaiStream.bytes_terminate(self._io.read_bytes(20), 0, False)).decode(u"utf-8") - self._debug['module_name']['end'] = self._io.pos() - self._debug['signature1']['start'] = self._io.pos() - self.signature1 = self._io.ensure_fixed_contents(b"\x1A") - self._debug['signature1']['end'] = self._io.pos() - self._debug['tracker_name']['start'] = self._io.pos() - self.tracker_name = (KaitaiStream.bytes_terminate(self._io.read_bytes(20), 0, False)).decode(u"utf-8") - self._debug['tracker_name']['end'] = self._io.pos() - self._debug['version_number']['start'] = self._io.pos() - self.version_number = self._root.Preheader.Version(self._io, self, self._root) - self.version_number._read() - self._debug['version_number']['end'] = self._io.pos() - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_u4le() - self._debug['header_size']['end'] = self._io.pos() - - class Version(KaitaiStruct): - SEQ_FIELDS = ["minor", "major"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u1() - self._debug['minor']['end'] = self._io.pos() - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u1() - self._debug['major']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = ((self.major << 8) | self.minor) - return self._m_value if hasattr(self, '_m_value') else None - - - - class Pattern(KaitaiStruct): - SEQ_FIELDS = ["header", "packed_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Pattern.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['packed_data']['start'] = self._io.pos() - self.packed_data = self._io.read_bytes(self.header.main.len_packed_pattern) - self._debug['packed_data']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["header_length", "main"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header_length']['start'] = self._io.pos() - self.header_length = self._io.read_u4le() - self._debug['header_length']['end'] = self._io.pos() - self._debug['main']['start'] = self._io.pos() - self._raw_main = self._io.read_bytes((self.header_length - 4)) - io = KaitaiStream(BytesIO(self._raw_main)) - self.main = self._root.Pattern.Header.HeaderMain(io, self, self._root) - self.main._read() - self._debug['main']['end'] = self._io.pos() - - class HeaderMain(KaitaiStruct): - SEQ_FIELDS = ["packing_type", "num_rows_raw", "len_packed_pattern"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['packing_type']['start'] = self._io.pos() - self.packing_type = self._io.read_u1() - self._debug['packing_type']['end'] = self._io.pos() - self._debug['num_rows_raw']['start'] = self._io.pos() - _on = self._root.preheader.version_number.value - if _on == 258: - self.num_rows_raw = self._io.read_u1() - else: - self.num_rows_raw = self._io.read_u2le() - self._debug['num_rows_raw']['end'] = self._io.pos() - self._debug['len_packed_pattern']['start'] = self._io.pos() - self.len_packed_pattern = self._io.read_u2le() - self._debug['len_packed_pattern']['end'] = self._io.pos() - - @property - def num_rows(self): - if hasattr(self, '_m_num_rows'): - return self._m_num_rows if hasattr(self, '_m_num_rows') else None - - self._m_num_rows = (self.num_rows_raw + (1 if self._root.preheader.version_number.value == 258 else 0)) - return self._m_num_rows if hasattr(self, '_m_num_rows') else None - - - - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["reserved", "freq_table_type"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(15) - self._debug['reserved']['end'] = self._io.pos() - self._debug['freq_table_type']['start'] = self._io.pos() - self.freq_table_type = self._io.read_bits_int(1) != 0 - self._debug['freq_table_type']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - SEQ_FIELDS = ["song_length", "restart_position", "num_channels", "num_patterns", "num_instruments", "flags", "default_tempo", "default_bpm", "pattern_order_table"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['song_length']['start'] = self._io.pos() - self.song_length = self._io.read_u2le() - self._debug['song_length']['end'] = self._io.pos() - self._debug['restart_position']['start'] = self._io.pos() - self.restart_position = self._io.read_u2le() - self._debug['restart_position']['end'] = self._io.pos() - self._debug['num_channels']['start'] = self._io.pos() - self.num_channels = self._io.read_u2le() - self._debug['num_channels']['end'] = self._io.pos() - self._debug['num_patterns']['start'] = self._io.pos() - self.num_patterns = self._io.read_u2le() - self._debug['num_patterns']['end'] = self._io.pos() - self._debug['num_instruments']['start'] = self._io.pos() - self.num_instruments = self._io.read_u2le() - self._debug['num_instruments']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['default_tempo']['start'] = self._io.pos() - self.default_tempo = self._io.read_u2le() - self._debug['default_tempo']['end'] = self._io.pos() - self._debug['default_bpm']['start'] = self._io.pos() - self.default_bpm = self._io.read_u2le() - self._debug['default_bpm']['end'] = self._io.pos() - self._debug['pattern_order_table']['start'] = self._io.pos() - self.pattern_order_table = [None] * (256) - for i in range(256): - if not 'arr' in self._debug['pattern_order_table']: - self._debug['pattern_order_table']['arr'] = [] - self._debug['pattern_order_table']['arr'].append({'start': self._io.pos()}) - self.pattern_order_table[i] = self._io.read_u1() - self._debug['pattern_order_table']['arr'][i]['end'] = self._io.pos() - - self._debug['pattern_order_table']['end'] = self._io.pos() - - - class Instrument(KaitaiStruct): - """XM's notion of "instrument" typically constitutes of a - instrument metadata and one or several samples. Metadata - includes: - - * instrument's name - * instruction of which sample to use for which note - * volume and panning envelopes and looping instructions - * vibrato settings - """ - SEQ_FIELDS = ["header_size", "header", "samples_headers", "samples"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes((self.header_size - 4)) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Instrument.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['samples_headers']['start'] = self._io.pos() - self.samples_headers = [None] * (self.header.num_samples) - for i in range(self.header.num_samples): - if not 'arr' in self._debug['samples_headers']: - self._debug['samples_headers']['arr'] = [] - self._debug['samples_headers']['arr'].append({'start': self._io.pos()}) - _t_samples_headers = self._root.Instrument.SampleHeader(self._io, self, self._root) - _t_samples_headers._read() - self.samples_headers[i] = _t_samples_headers - self._debug['samples_headers']['arr'][i]['end'] = self._io.pos() - - self._debug['samples_headers']['end'] = self._io.pos() - self._debug['samples']['start'] = self._io.pos() - self.samples = [None] * (self.header.num_samples) - for i in range(self.header.num_samples): - if not 'arr' in self._debug['samples']: - self._debug['samples']['arr'] = [] - self._debug['samples']['arr'].append({'start': self._io.pos()}) - _t_samples = self._root.Instrument.SamplesData(self.samples_headers[i], self._io, self, self._root) - _t_samples._read() - self.samples[i] = _t_samples - self._debug['samples']['arr'][i]['end'] = self._io.pos() - - self._debug['samples']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["name", "type", "num_samples", "extra_header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(self._io.read_bytes(22), 0, False)).decode(u"utf-8") - self._debug['name']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u1() - self._debug['type']['end'] = self._io.pos() - self._debug['num_samples']['start'] = self._io.pos() - self.num_samples = self._io.read_u2le() - self._debug['num_samples']['end'] = self._io.pos() - if self.num_samples > 0: - self._debug['extra_header']['start'] = self._io.pos() - self.extra_header = self._root.Instrument.ExtraHeader(self._io, self, self._root) - self.extra_header._read() - self._debug['extra_header']['end'] = self._io.pos() - - - - class ExtraHeader(KaitaiStruct): - - class Type(Enum): - true = 0 - sustain = 1 - loop = 2 - SEQ_FIELDS = ["len_sample_header", "idx_sample_per_note", "volume_points", "panning_points", "num_volume_points", "num_panning_points", "volume_sustain_point", "volume_loop_start_point", "volume_loop_end_point", "panning_sustain_point", "panning_loop_start_point", "panning_loop_end_point", "volume_type", "panning_type", "vibrato_type", "vibrato_sweep", "vibrato_depth", "vibrato_rate", "volume_fadeout", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_sample_header']['start'] = self._io.pos() - self.len_sample_header = self._io.read_u4le() - self._debug['len_sample_header']['end'] = self._io.pos() - self._debug['idx_sample_per_note']['start'] = self._io.pos() - self.idx_sample_per_note = [None] * (96) - for i in range(96): - if not 'arr' in self._debug['idx_sample_per_note']: - self._debug['idx_sample_per_note']['arr'] = [] - self._debug['idx_sample_per_note']['arr'].append({'start': self._io.pos()}) - self.idx_sample_per_note[i] = self._io.read_u1() - self._debug['idx_sample_per_note']['arr'][i]['end'] = self._io.pos() - - self._debug['idx_sample_per_note']['end'] = self._io.pos() - self._debug['volume_points']['start'] = self._io.pos() - self.volume_points = [None] * (12) - for i in range(12): - if not 'arr' in self._debug['volume_points']: - self._debug['volume_points']['arr'] = [] - self._debug['volume_points']['arr'].append({'start': self._io.pos()}) - _t_volume_points = self._root.Instrument.ExtraHeader.EnvelopePoint(self._io, self, self._root) - _t_volume_points._read() - self.volume_points[i] = _t_volume_points - self._debug['volume_points']['arr'][i]['end'] = self._io.pos() - - self._debug['volume_points']['end'] = self._io.pos() - self._debug['panning_points']['start'] = self._io.pos() - self.panning_points = [None] * (12) - for i in range(12): - if not 'arr' in self._debug['panning_points']: - self._debug['panning_points']['arr'] = [] - self._debug['panning_points']['arr'].append({'start': self._io.pos()}) - _t_panning_points = self._root.Instrument.ExtraHeader.EnvelopePoint(self._io, self, self._root) - _t_panning_points._read() - self.panning_points[i] = _t_panning_points - self._debug['panning_points']['arr'][i]['end'] = self._io.pos() - - self._debug['panning_points']['end'] = self._io.pos() - self._debug['num_volume_points']['start'] = self._io.pos() - self.num_volume_points = self._io.read_u1() - self._debug['num_volume_points']['end'] = self._io.pos() - self._debug['num_panning_points']['start'] = self._io.pos() - self.num_panning_points = self._io.read_u1() - self._debug['num_panning_points']['end'] = self._io.pos() - self._debug['volume_sustain_point']['start'] = self._io.pos() - self.volume_sustain_point = self._io.read_u1() - self._debug['volume_sustain_point']['end'] = self._io.pos() - self._debug['volume_loop_start_point']['start'] = self._io.pos() - self.volume_loop_start_point = self._io.read_u1() - self._debug['volume_loop_start_point']['end'] = self._io.pos() - self._debug['volume_loop_end_point']['start'] = self._io.pos() - self.volume_loop_end_point = self._io.read_u1() - self._debug['volume_loop_end_point']['end'] = self._io.pos() - self._debug['panning_sustain_point']['start'] = self._io.pos() - self.panning_sustain_point = self._io.read_u1() - self._debug['panning_sustain_point']['end'] = self._io.pos() - self._debug['panning_loop_start_point']['start'] = self._io.pos() - self.panning_loop_start_point = self._io.read_u1() - self._debug['panning_loop_start_point']['end'] = self._io.pos() - self._debug['panning_loop_end_point']['start'] = self._io.pos() - self.panning_loop_end_point = self._io.read_u1() - self._debug['panning_loop_end_point']['end'] = self._io.pos() - self._debug['volume_type']['start'] = self._io.pos() - self.volume_type = KaitaiStream.resolve_enum(self._root.Instrument.ExtraHeader.Type, self._io.read_u1()) - self._debug['volume_type']['end'] = self._io.pos() - self._debug['panning_type']['start'] = self._io.pos() - self.panning_type = KaitaiStream.resolve_enum(self._root.Instrument.ExtraHeader.Type, self._io.read_u1()) - self._debug['panning_type']['end'] = self._io.pos() - self._debug['vibrato_type']['start'] = self._io.pos() - self.vibrato_type = self._io.read_u1() - self._debug['vibrato_type']['end'] = self._io.pos() - self._debug['vibrato_sweep']['start'] = self._io.pos() - self.vibrato_sweep = self._io.read_u1() - self._debug['vibrato_sweep']['end'] = self._io.pos() - self._debug['vibrato_depth']['start'] = self._io.pos() - self.vibrato_depth = self._io.read_u1() - self._debug['vibrato_depth']['end'] = self._io.pos() - self._debug['vibrato_rate']['start'] = self._io.pos() - self.vibrato_rate = self._io.read_u1() - self._debug['vibrato_rate']['end'] = self._io.pos() - self._debug['volume_fadeout']['start'] = self._io.pos() - self.volume_fadeout = self._io.read_u2le() - self._debug['volume_fadeout']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u2le() - self._debug['reserved']['end'] = self._io.pos() - - class EnvelopePoint(KaitaiStruct): - """Envelope frame-counters work in range 0..FFFFh (0..65535 dec). - BUT! FT2 only itself supports only range 0..FFh (0..255 dec). - Some other trackers (like SoundTracker for Unix), however, can use the full range 0..FFFF, so it should be supported. - !!TIP: This is also a good way to detect if the module has been made with FT2 or not. (In case the tracker name is brain- deadly left unchanged!) - Of course it does not help if all instruments have the values inside FT2 supported range. - The value-field of the envelope point is ranged between 00..3Fh (0..64 dec). - """ - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_u2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_u2le() - self._debug['y']['end'] = self._io.pos() - - - - class SamplesData(KaitaiStruct): - """The saved data uses simple delta-encoding to achieve better compression ratios (when compressed with pkzip, etc.) - Pseudocode for converting the delta-coded data to normal data, - old = 0 - for i in range(data_len): - new = sample[i] + old - sample[i] = new - old = new - """ - SEQ_FIELDS = ["data"] - def __init__(self, header, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.header = header - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes((self.header.sample_length * (2 if self.header.type.is_sample_data_16_bit else 1))) - self._debug['data']['end'] = self._io.pos() - - - class SampleHeader(KaitaiStruct): - SEQ_FIELDS = ["sample_length", "sample_loop_start", "sample_loop_length", "volume", "fine_tune", "type", "panning", "relative_note_number", "reserved", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sample_length']['start'] = self._io.pos() - self.sample_length = self._io.read_u4le() - self._debug['sample_length']['end'] = self._io.pos() - self._debug['sample_loop_start']['start'] = self._io.pos() - self.sample_loop_start = self._io.read_u4le() - self._debug['sample_loop_start']['end'] = self._io.pos() - self._debug['sample_loop_length']['start'] = self._io.pos() - self.sample_loop_length = self._io.read_u4le() - self._debug['sample_loop_length']['end'] = self._io.pos() - self._debug['volume']['start'] = self._io.pos() - self.volume = self._io.read_u1() - self._debug['volume']['end'] = self._io.pos() - self._debug['fine_tune']['start'] = self._io.pos() - self.fine_tune = self._io.read_s1() - self._debug['fine_tune']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._root.Instrument.SampleHeader.LoopType(self._io, self, self._root) - self.type._read() - self._debug['type']['end'] = self._io.pos() - self._debug['panning']['start'] = self._io.pos() - self.panning = self._io.read_u1() - self._debug['panning']['end'] = self._io.pos() - self._debug['relative_note_number']['start'] = self._io.pos() - self.relative_note_number = self._io.read_s1() - self._debug['relative_note_number']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u1() - self._debug['reserved']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(self._io.read_bytes(22), 0, False)).decode(u"utf-8") - self._debug['name']['end'] = self._io.pos() - - class LoopType(KaitaiStruct): - - class LoopType(Enum): - none = 0 - forward = 1 - ping_pong = 2 - SEQ_FIELDS = ["reserved0", "is_sample_data_16_bit", "reserved1", "loop_type"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved0']['start'] = self._io.pos() - self.reserved0 = self._io.read_bits_int(3) - self._debug['reserved0']['end'] = self._io.pos() - self._debug['is_sample_data_16_bit']['start'] = self._io.pos() - self.is_sample_data_16_bit = self._io.read_bits_int(1) != 0 - self._debug['is_sample_data_16_bit']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(2) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['loop_type']['start'] = self._io.pos() - self.loop_type = KaitaiStream.resolve_enum(self._root.Instrument.SampleHeader.LoopType.LoopType, self._io.read_bits_int(2)) - self._debug['loop_type']['end'] = self._io.pos() - - - - - diff --git a/python/examples/kaitai/ftl_dat.py b/python/examples/kaitai/ftl_dat.py deleted file mode 100644 index 21ca6a07..00000000 --- a/python/examples/kaitai/ftl_dat.py +++ /dev/null @@ -1,89 +0,0 @@ -# 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 -import collections - - -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 FtlDat(KaitaiStruct): - SEQ_FIELDS = ["num_files", "files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_files']['start'] = self._io.pos() - self.num_files = self._io.read_u4le() - self._debug['num_files']['end'] = self._io.pos() - self._debug['files']['start'] = self._io.pos() - self.files = [None] * (self.num_files) - for i in range(self.num_files): - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.File(self._io, self, self._root) - _t_files._read() - self.files[i] = _t_files - self._debug['files']['arr'][i]['end'] = self._io.pos() - - self._debug['files']['end'] = self._io.pos() - - class File(KaitaiStruct): - SEQ_FIELDS = ["ofs_meta"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs_meta']['start'] = self._io.pos() - self.ofs_meta = self._io.read_u4le() - self._debug['ofs_meta']['end'] = self._io.pos() - - @property - def meta(self): - if hasattr(self, '_m_meta'): - return self._m_meta if hasattr(self, '_m_meta') else None - - if self.ofs_meta != 0: - _pos = self._io.pos() - self._io.seek(self.ofs_meta) - self._debug['_m_meta']['start'] = self._io.pos() - self._m_meta = self._root.Meta(self._io, self, self._root) - self._m_meta._read() - self._debug['_m_meta']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_meta if hasattr(self, '_m_meta') else None - - - class Meta(KaitaiStruct): - SEQ_FIELDS = ["len_file", "len_filename", "filename", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_file']['start'] = self._io.pos() - self.len_file = self._io.read_u4le() - self._debug['len_file']['end'] = self._io.pos() - self._debug['len_filename']['start'] = self._io.pos() - self.len_filename = self._io.read_u4le() - self._debug['len_filename']['end'] = self._io.pos() - self._debug['filename']['start'] = self._io.pos() - self.filename = (self._io.read_bytes(self.len_filename)).decode(u"UTF-8") - self._debug['filename']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len_file) - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/genmidi_op2.py b/python/examples/kaitai/genmidi_op2.py deleted file mode 100644 index ab39962a..00000000 --- a/python/examples/kaitai/genmidi_op2.py +++ /dev/null @@ -1,150 +0,0 @@ -# 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 -import collections - - -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 GenmidiOp2(KaitaiStruct): - """GENMIDI.OP2 is a sound bank file used by players based on DMX sound - library to play MIDI files with General MIDI instruments using OPL2 - sound chip (which was commonly installed on popular AdLib and Sound - Blaster sound cards). - - Major users of DMX sound library include: - - * Original Doom game engine (and games based on it: Heretic, Hexen, Strife, Chex Quest) - * Raptor: Call of the Shadows - - .. seealso:: - http://doom.wikia.com/wiki/GENMIDI - http://www.fit.vutbr.cz/~arnost/muslib/op2_form.zip - """ - SEQ_FIELDS = ["magic", "instruments", "instrument_names"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x23\x4F\x50\x4C\x5F\x49\x49\x23") - self._debug['magic']['end'] = self._io.pos() - self._debug['instruments']['start'] = self._io.pos() - self.instruments = [None] * (175) - for i in range(175): - if not 'arr' in self._debug['instruments']: - self._debug['instruments']['arr'] = [] - self._debug['instruments']['arr'].append({'start': self._io.pos()}) - _t_instruments = self._root.InstrumentEntry(self._io, self, self._root) - _t_instruments._read() - self.instruments[i] = _t_instruments - self._debug['instruments']['arr'][i]['end'] = self._io.pos() - - self._debug['instruments']['end'] = self._io.pos() - self._debug['instrument_names']['start'] = self._io.pos() - self.instrument_names = [None] * (175) - for i in range(175): - if not 'arr' in self._debug['instrument_names']: - self._debug['instrument_names']['arr'] = [] - self._debug['instrument_names']['arr'].append({'start': self._io.pos()}) - self.instrument_names[i] = (KaitaiStream.bytes_terminate(KaitaiStream.bytes_strip_right(self._io.read_bytes(32), 0), 0, False)).decode(u"ASCII") - self._debug['instrument_names']['arr'][i]['end'] = self._io.pos() - - self._debug['instrument_names']['end'] = self._io.pos() - - class InstrumentEntry(KaitaiStruct): - SEQ_FIELDS = ["flags", "finetune", "note", "instruments"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['finetune']['start'] = self._io.pos() - self.finetune = self._io.read_u1() - self._debug['finetune']['end'] = self._io.pos() - self._debug['note']['start'] = self._io.pos() - self.note = self._io.read_u1() - self._debug['note']['end'] = self._io.pos() - self._debug['instruments']['start'] = self._io.pos() - self.instruments = [None] * (2) - for i in range(2): - if not 'arr' in self._debug['instruments']: - self._debug['instruments']['arr'] = [] - self._debug['instruments']['arr'].append({'start': self._io.pos()}) - _t_instruments = self._root.Instrument(self._io, self, self._root) - _t_instruments._read() - self.instruments[i] = _t_instruments - self._debug['instruments']['arr'][i]['end'] = self._io.pos() - - self._debug['instruments']['end'] = self._io.pos() - - - class Instrument(KaitaiStruct): - SEQ_FIELDS = ["op1", "feedback", "op2", "unused", "base_note"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['op1']['start'] = self._io.pos() - self.op1 = self._root.OpSettings(self._io, self, self._root) - self.op1._read() - self._debug['op1']['end'] = self._io.pos() - self._debug['feedback']['start'] = self._io.pos() - self.feedback = self._io.read_u1() - self._debug['feedback']['end'] = self._io.pos() - self._debug['op2']['start'] = self._io.pos() - self.op2 = self._root.OpSettings(self._io, self, self._root) - self.op2._read() - self._debug['op2']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_u1() - self._debug['unused']['end'] = self._io.pos() - self._debug['base_note']['start'] = self._io.pos() - self.base_note = self._io.read_s2le() - self._debug['base_note']['end'] = self._io.pos() - - - class OpSettings(KaitaiStruct): - """OPL2 settings for one operator (carrier or modulator) - """ - SEQ_FIELDS = ["trem_vibr", "att_dec", "sust_rel", "wave", "scale", "level"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['trem_vibr']['start'] = self._io.pos() - self.trem_vibr = self._io.read_u1() - self._debug['trem_vibr']['end'] = self._io.pos() - self._debug['att_dec']['start'] = self._io.pos() - self.att_dec = self._io.read_u1() - self._debug['att_dec']['end'] = self._io.pos() - self._debug['sust_rel']['start'] = self._io.pos() - self.sust_rel = self._io.read_u1() - self._debug['sust_rel']['end'] = self._io.pos() - self._debug['wave']['start'] = self._io.pos() - self.wave = self._io.read_u1() - self._debug['wave']['end'] = self._io.pos() - self._debug['scale']['start'] = self._io.pos() - self.scale = self._io.read_u1() - self._debug['scale']['end'] = self._io.pos() - self._debug['level']['start'] = self._io.pos() - self.level = self._io.read_u1() - self._debug['level']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/gettext_mo.py b/python/examples/kaitai/gettext_mo.py deleted file mode 100644 index c5de94b8..00000000 --- a/python/examples/kaitai/gettext_mo.py +++ /dev/null @@ -1,544 +0,0 @@ -# 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 -import collections - - -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 GettextMo(KaitaiStruct): - """[GNU gettext](https://www.gnu.org/software/gettext/) is a popular - solution in free/open source software world to do i18n/l10n of - software, by providing translated strings that will substitute - strings in original language (typically, English). - - gettext .mo is a binary database format which stores these string - translation pairs in an efficient binary format, ready to be used by - gettext-enabled software. .mo format is a result of compilation of - text-based .po files using - [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html#msgfmt-Invocation) - utility. The reverse conversion (.mo -> .po) is also possible using - [msgunfmt](https://www.gnu.org/software/gettext/manual/html_node/msgunfmt-Invocation.html#msgunfmt-Invocation) - decompiler utility. - - .. seealso:: - Source - https://gitlab.com/worr/libintl - """ - SEQ_FIELDS = ["signature", "mo"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.read_bytes(4) - self._debug['signature']['end'] = self._io.pos() - self._debug['mo']['start'] = self._io.pos() - self.mo = self._root.Mo(self._io, self, self._root) - self.mo._read() - self._debug['mo']['end'] = self._io.pos() - - class HashLookupIteration(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, idx, collision_step, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.idx = idx - self.collision_step = collision_step - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def original(self): - if hasattr(self, '_m_original'): - return self._m_original if hasattr(self, '_m_original') else None - - self._m_original = self._root.mo.originals[self.idx].str - return self._m_original if hasattr(self, '_m_original') else None - - @property - def translation(self): - if hasattr(self, '_m_translation'): - return self._m_translation if hasattr(self, '_m_translation') else None - - self._m_translation = self._root.mo.translations[self.idx].str - return self._m_translation if hasattr(self, '_m_translation') else None - - @property - def next_idx(self): - if hasattr(self, '_m_next_idx'): - return self._m_next_idx if hasattr(self, '_m_next_idx') else None - - self._m_next_idx = ((self.idx + self.collision_step) - (self._root.mo.num_hashtable_items if self.idx >= (self._root.mo.num_hashtable_items - self.collision_step) else 0)) - return self._m_next_idx if hasattr(self, '_m_next_idx') else None - - @property - def next(self): - if hasattr(self, '_m_next'): - return self._m_next if hasattr(self, '_m_next') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_next']['start'] = self._io.pos() - self._m_next = self._root.HashLookupIteration(self._root.mo.hashtable_items[self.next_idx].val, self.collision_step, self._io, self, self._root) - self._m_next._read() - self._debug['_m_next']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_next if hasattr(self, '_m_next') else None - - - class LookupIteration(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, current, query, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.current = current - self.query = query - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def found(self): - if hasattr(self, '_m_found'): - return self._m_found if hasattr(self, '_m_found') else None - - self._m_found = self.query == self.current.original - return self._m_found if hasattr(self, '_m_found') else None - - @property - def next(self): - if hasattr(self, '_m_next'): - return self._m_next if hasattr(self, '_m_next') else None - - if not (self.found): - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_next']['start'] = self._io.pos() - self._m_next = self._root.LookupIteration(self.current.next, self.query, self._io, self, self._root) - self._m_next._read() - self._debug['_m_next']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_next if hasattr(self, '_m_next') else None - - - class HashtableLookup(KaitaiStruct): - """def lookup(s:str, t:gettext_mo.GettextMo): - try: - l=gettext_mo.GettextMo.HashtableLookup(s, string_hash(s), t._io, _parent=t, _root=t) - e=l.entry - while(not e.found): - e=e.next - return e.current - except: - raise Exception("Not found "+s+" in the hashtable!") - - lookup(t.mo.originals[145].str, t) - - .. seealso:: - Source - https://gitlab.com/worr/libintl/raw/master/src/lib/libintl/gettext.c - """ - SEQ_FIELDS = [] - def __init__(self, query, hash, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.query = query - self.hash = hash - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def collision_step(self): - if hasattr(self, '_m_collision_step'): - return self._m_collision_step if hasattr(self, '_m_collision_step') else None - - self._m_collision_step = ((self.hash % (self._root.mo.num_hashtable_items - 2)) + 1) - return self._m_collision_step if hasattr(self, '_m_collision_step') else None - - @property - def idx(self): - if hasattr(self, '_m_idx'): - return self._m_idx if hasattr(self, '_m_idx') else None - - self._m_idx = (self.hash % self._root.mo.num_hashtable_items) - return self._m_idx if hasattr(self, '_m_idx') else None - - @property - def hash_lookup_iteration(self): - if hasattr(self, '_m_hash_lookup_iteration'): - return self._m_hash_lookup_iteration if hasattr(self, '_m_hash_lookup_iteration') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_hash_lookup_iteration']['start'] = self._io.pos() - self._m_hash_lookup_iteration = self._root.HashLookupIteration(self._root.mo.hashtable_items[self.idx].val, self.collision_step, self._io, self, self._root) - self._m_hash_lookup_iteration._read() - self._debug['_m_hash_lookup_iteration']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_hash_lookup_iteration if hasattr(self, '_m_hash_lookup_iteration') else None - - @property - def entry(self): - if hasattr(self, '_m_entry'): - return self._m_entry if hasattr(self, '_m_entry') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_entry']['start'] = self._io.pos() - self._m_entry = self._root.LookupIteration(self.hash_lookup_iteration, self.query, self._io, self, self._root) - self._m_entry._read() - self._debug['_m_entry']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_entry if hasattr(self, '_m_entry') else None - - - class Mo(KaitaiStruct): - SEQ_FIELDS = ["version", "num_translations", "ofs_originals", "ofs_translations", "num_hashtable_items", "ofs_hashtable_items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - _on = self._root.signature - if _on == b"\xDE\x12\x04\x95": - self._is_le = True - elif _on == b"\x95\x04\x12\xDE": - self._is_le = False - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Mo.Version(self._io, self, self._root, self._is_le) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['num_translations']['start'] = self._io.pos() - self.num_translations = self._io.read_u4le() - self._debug['num_translations']['end'] = self._io.pos() - self._debug['ofs_originals']['start'] = self._io.pos() - self.ofs_originals = self._io.read_u4le() - self._debug['ofs_originals']['end'] = self._io.pos() - self._debug['ofs_translations']['start'] = self._io.pos() - self.ofs_translations = self._io.read_u4le() - self._debug['ofs_translations']['end'] = self._io.pos() - self._debug['num_hashtable_items']['start'] = self._io.pos() - self.num_hashtable_items = self._io.read_u4le() - self._debug['num_hashtable_items']['end'] = self._io.pos() - self._debug['ofs_hashtable_items']['start'] = self._io.pos() - self.ofs_hashtable_items = self._io.read_u4le() - self._debug['ofs_hashtable_items']['end'] = self._io.pos() - - def _read_be(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Mo.Version(self._io, self, self._root, self._is_le) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['num_translations']['start'] = self._io.pos() - self.num_translations = self._io.read_u4be() - self._debug['num_translations']['end'] = self._io.pos() - self._debug['ofs_originals']['start'] = self._io.pos() - self.ofs_originals = self._io.read_u4be() - self._debug['ofs_originals']['end'] = self._io.pos() - self._debug['ofs_translations']['start'] = self._io.pos() - self.ofs_translations = self._io.read_u4be() - self._debug['ofs_translations']['end'] = self._io.pos() - self._debug['num_hashtable_items']['start'] = self._io.pos() - self.num_hashtable_items = self._io.read_u4be() - self._debug['num_hashtable_items']['end'] = self._io.pos() - self._debug['ofs_hashtable_items']['start'] = self._io.pos() - self.ofs_hashtable_items = self._io.read_u4be() - self._debug['ofs_hashtable_items']['end'] = self._io.pos() - - class Version(KaitaiStruct): - SEQ_FIELDS = ["version_raw"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['version_raw']['start'] = self._io.pos() - self.version_raw = self._io.read_u4le() - self._debug['version_raw']['end'] = self._io.pos() - - def _read_be(self): - self._debug['version_raw']['start'] = self._io.pos() - self.version_raw = self._io.read_u4be() - self._debug['version_raw']['end'] = self._io.pos() - - @property - def major(self): - if hasattr(self, '_m_major'): - return self._m_major if hasattr(self, '_m_major') else None - - self._m_major = (self.version_raw >> 16) - return self._m_major if hasattr(self, '_m_major') else None - - @property - def minor(self): - if hasattr(self, '_m_minor'): - return self._m_minor if hasattr(self, '_m_minor') else None - - self._m_minor = (self.version_raw & 65535) - return self._m_minor if hasattr(self, '_m_minor') else None - - - class HashtableItem(KaitaiStruct): - SEQ_FIELDS = ["raw_val"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['raw_val']['start'] = self._io.pos() - self.raw_val = self._io.read_u4le() - self._debug['raw_val']['end'] = self._io.pos() - - def _read_be(self): - self._debug['raw_val']['start'] = self._io.pos() - self.raw_val = self._io.read_u4be() - self._debug['raw_val']['end'] = self._io.pos() - - @property - def mask(self): - if hasattr(self, '_m_mask'): - return self._m_mask if hasattr(self, '_m_mask') else None - - self._m_mask = 2147483648 - return self._m_mask if hasattr(self, '_m_mask') else None - - @property - def val_1(self): - if hasattr(self, '_m_val_1'): - return self._m_val_1 if hasattr(self, '_m_val_1') else None - - if self.raw_val != 0: - self._m_val_1 = (self.raw_val - 1) - - return self._m_val_1 if hasattr(self, '_m_val_1') else None - - @property - def is_system_dependent(self): - if hasattr(self, '_m_is_system_dependent'): - return self._m_is_system_dependent if hasattr(self, '_m_is_system_dependent') else None - - if self.raw_val != 0: - self._m_is_system_dependent = (self.val_1 & self.mask) == 1 - - return self._m_is_system_dependent if hasattr(self, '_m_is_system_dependent') else None - - @property - def val(self): - if hasattr(self, '_m_val'): - return self._m_val if hasattr(self, '_m_val') else None - - if self.raw_val != 0: - self._m_val = (self.val_1 & ~(self.mask)) - - return self._m_val if hasattr(self, '_m_val') else None - - - class Descriptor(KaitaiStruct): - SEQ_FIELDS = ["len_str", "ofs_str"] - def __init__(self, _io, _parent=None, _root=None, _is_le=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._is_le = _is_le - self._debug = collections.defaultdict(dict) - - def _read(self): - - if self._is_le == True: - self._read_le() - elif self._is_le == False: - self._read_be() - else: - raise Exception("Unable to decide endianness") - - def _read_le(self): - self._debug['len_str']['start'] = self._io.pos() - self.len_str = self._io.read_u4le() - self._debug['len_str']['end'] = self._io.pos() - self._debug['ofs_str']['start'] = self._io.pos() - self.ofs_str = self._io.read_u4le() - self._debug['ofs_str']['end'] = self._io.pos() - - def _read_be(self): - self._debug['len_str']['start'] = self._io.pos() - self.len_str = self._io.read_u4be() - self._debug['len_str']['end'] = self._io.pos() - self._debug['ofs_str']['start'] = self._io.pos() - self.ofs_str = self._io.read_u4be() - self._debug['ofs_str']['end'] = self._io.pos() - - @property - def str(self): - if hasattr(self, '_m_str'): - return self._m_str if hasattr(self, '_m_str') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_str) - self._debug['_m_str']['start'] = io.pos() - if self._is_le: - self._m_str = (KaitaiStream.bytes_terminate(io.read_bytes(self.len_str), 0, False)).decode(u"UTF-8") - else: - self._m_str = (KaitaiStream.bytes_terminate(io.read_bytes(self.len_str), 0, False)).decode(u"UTF-8") - self._debug['_m_str']['end'] = io.pos() - io.seek(_pos) - return self._m_str if hasattr(self, '_m_str') else None - - - @property - def originals(self): - if hasattr(self, '_m_originals'): - return self._m_originals if hasattr(self, '_m_originals') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_originals) - self._debug['_m_originals']['start'] = io.pos() - if self._is_le: - self._m_originals = [None] * (self.num_translations) - for i in range(self.num_translations): - if not 'arr' in self._debug['_m_originals']: - self._debug['_m_originals']['arr'] = [] - self._debug['_m_originals']['arr'].append({'start': io.pos()}) - _t__m_originals = self._root.Mo.Descriptor(io, self, self._root, self._is_le) - _t__m_originals._read() - self._m_originals[i] = _t__m_originals - self._debug['_m_originals']['arr'][i]['end'] = io.pos() - - else: - self._m_originals = [None] * (self.num_translations) - for i in range(self.num_translations): - if not 'arr' in self._debug['_m_originals']: - self._debug['_m_originals']['arr'] = [] - self._debug['_m_originals']['arr'].append({'start': io.pos()}) - _t__m_originals = self._root.Mo.Descriptor(io, self, self._root, self._is_le) - _t__m_originals._read() - self._m_originals[i] = _t__m_originals - self._debug['_m_originals']['arr'][i]['end'] = io.pos() - - self._debug['_m_originals']['end'] = io.pos() - io.seek(_pos) - return self._m_originals if hasattr(self, '_m_originals') else None - - @property - def translations(self): - if hasattr(self, '_m_translations'): - return self._m_translations if hasattr(self, '_m_translations') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_translations) - self._debug['_m_translations']['start'] = io.pos() - if self._is_le: - self._m_translations = [None] * (self.num_translations) - for i in range(self.num_translations): - if not 'arr' in self._debug['_m_translations']: - self._debug['_m_translations']['arr'] = [] - self._debug['_m_translations']['arr'].append({'start': io.pos()}) - _t__m_translations = self._root.Mo.Descriptor(io, self, self._root, self._is_le) - _t__m_translations._read() - self._m_translations[i] = _t__m_translations - self._debug['_m_translations']['arr'][i]['end'] = io.pos() - - else: - self._m_translations = [None] * (self.num_translations) - for i in range(self.num_translations): - if not 'arr' in self._debug['_m_translations']: - self._debug['_m_translations']['arr'] = [] - self._debug['_m_translations']['arr'].append({'start': io.pos()}) - _t__m_translations = self._root.Mo.Descriptor(io, self, self._root, self._is_le) - _t__m_translations._read() - self._m_translations[i] = _t__m_translations - self._debug['_m_translations']['arr'][i]['end'] = io.pos() - - self._debug['_m_translations']['end'] = io.pos() - io.seek(_pos) - return self._m_translations if hasattr(self, '_m_translations') else None - - @property - def hashtable_items(self): - if hasattr(self, '_m_hashtable_items'): - return self._m_hashtable_items if hasattr(self, '_m_hashtable_items') else None - - if self.ofs_hashtable_items != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_hashtable_items) - self._debug['_m_hashtable_items']['start'] = io.pos() - if self._is_le: - self._m_hashtable_items = [None] * (self.num_hashtable_items) - for i in range(self.num_hashtable_items): - if not 'arr' in self._debug['_m_hashtable_items']: - self._debug['_m_hashtable_items']['arr'] = [] - self._debug['_m_hashtable_items']['arr'].append({'start': io.pos()}) - _t__m_hashtable_items = self._root.Mo.HashtableItem(io, self, self._root, self._is_le) - _t__m_hashtable_items._read() - self._m_hashtable_items[i] = _t__m_hashtable_items - self._debug['_m_hashtable_items']['arr'][i]['end'] = io.pos() - - else: - self._m_hashtable_items = [None] * (self.num_hashtable_items) - for i in range(self.num_hashtable_items): - if not 'arr' in self._debug['_m_hashtable_items']: - self._debug['_m_hashtable_items']['arr'] = [] - self._debug['_m_hashtable_items']['arr'].append({'start': io.pos()}) - _t__m_hashtable_items = self._root.Mo.HashtableItem(io, self, self._root, self._is_le) - _t__m_hashtable_items._read() - self._m_hashtable_items[i] = _t__m_hashtable_items - self._debug['_m_hashtable_items']['arr'][i]['end'] = io.pos() - - self._debug['_m_hashtable_items']['end'] = io.pos() - io.seek(_pos) - - return self._m_hashtable_items if hasattr(self, '_m_hashtable_items') else None - - - diff --git a/python/examples/kaitai/gif.py b/python/examples/kaitai/gif.py deleted file mode 100644 index 82cfc7b6..00000000 --- a/python/examples/kaitai/gif.py +++ /dev/null @@ -1,463 +0,0 @@ -# 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 -import collections - - -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 Gif(KaitaiStruct): - """GIF (Graphics Interchange Format) is an image file format, developed - in 1987. It became popular in 1990s as one of the main image formats - used in World Wide Web. - - GIF format allows encoding of palette-based images up to 256 colors - (each of the colors can be chosen from a 24-bit RGB - colorspace). Image data stream uses LZW (LempelAAAZivAAAWelch) lossless - compression. - - Over the years, several version of the format were published and - several extensions to it were made, namely, a popular Netscape - extension that allows to store several images in one file, switching - between them, which produces crude form of animation. - - Structurally, format consists of several mandatory headers and then - a stream of blocks follows. Blocks can carry additional - metainformation or image data. - """ - - class BlockType(Enum): - extension = 33 - local_image_descriptor = 44 - end_of_file = 59 - - class ExtensionLabel(Enum): - graphic_control = 249 - comment = 254 - application = 255 - SEQ_FIELDS = ["hdr", "logical_screen_descriptor", "global_color_table", "blocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hdr']['start'] = self._io.pos() - self.hdr = self._root.Header(self._io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - self._debug['logical_screen_descriptor']['start'] = self._io.pos() - self.logical_screen_descriptor = self._root.LogicalScreenDescriptorStruct(self._io, self, self._root) - self.logical_screen_descriptor._read() - self._debug['logical_screen_descriptor']['end'] = self._io.pos() - if self.logical_screen_descriptor.has_color_table: - self._debug['global_color_table']['start'] = self._io.pos() - self._raw_global_color_table = self._io.read_bytes((self.logical_screen_descriptor.color_table_size * 3)) - io = KaitaiStream(BytesIO(self._raw_global_color_table)) - self.global_color_table = self._root.ColorTable(io, self, self._root) - self.global_color_table._read() - self._debug['global_color_table']['end'] = self._io.pos() - - self._debug['blocks']['start'] = self._io.pos() - self.blocks = [] - i = 0 - while True: - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _t_blocks = self._root.Block(self._io, self, self._root) - _t_blocks._read() - _ = _t_blocks - self.blocks.append(_) - self._debug['blocks']['arr'][len(self.blocks) - 1]['end'] = self._io.pos() - if ((self._io.is_eof()) or (_.block_type == self._root.BlockType.end_of_file)) : - break - i += 1 - self._debug['blocks']['end'] = self._io.pos() - - class ImageData(KaitaiStruct): - """ - .. seealso:: - - section 22 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt - """ - SEQ_FIELDS = ["lzw_min_code_size", "subblocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['lzw_min_code_size']['start'] = self._io.pos() - self.lzw_min_code_size = self._io.read_u1() - self._debug['lzw_min_code_size']['end'] = self._io.pos() - self._debug['subblocks']['start'] = self._io.pos() - self.subblocks = self._root.Subblocks(self._io, self, self._root) - self.subblocks._read() - self._debug['subblocks']['end'] = self._io.pos() - - - class ColorTableEntry(KaitaiStruct): - SEQ_FIELDS = ["red", "green", "blue"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['red']['start'] = self._io.pos() - self.red = self._io.read_u1() - self._debug['red']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._io.read_u1() - self._debug['green']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._io.read_u1() - self._debug['blue']['end'] = self._io.pos() - - - class LogicalScreenDescriptorStruct(KaitaiStruct): - """ - .. seealso:: - - section 18 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt - """ - SEQ_FIELDS = ["screen_width", "screen_height", "flags", "bg_color_index", "pixel_aspect_ratio"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['screen_width']['start'] = self._io.pos() - self.screen_width = self._io.read_u2le() - self._debug['screen_width']['end'] = self._io.pos() - self._debug['screen_height']['start'] = self._io.pos() - self.screen_height = self._io.read_u2le() - self._debug['screen_height']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['bg_color_index']['start'] = self._io.pos() - self.bg_color_index = self._io.read_u1() - self._debug['bg_color_index']['end'] = self._io.pos() - self._debug['pixel_aspect_ratio']['start'] = self._io.pos() - self.pixel_aspect_ratio = self._io.read_u1() - self._debug['pixel_aspect_ratio']['end'] = self._io.pos() - - @property - def has_color_table(self): - if hasattr(self, '_m_has_color_table'): - return self._m_has_color_table if hasattr(self, '_m_has_color_table') else None - - self._m_has_color_table = (self.flags & 128) != 0 - return self._m_has_color_table if hasattr(self, '_m_has_color_table') else None - - @property - def color_table_size(self): - if hasattr(self, '_m_color_table_size'): - return self._m_color_table_size if hasattr(self, '_m_color_table_size') else None - - self._m_color_table_size = (2 << (self.flags & 7)) - return self._m_color_table_size if hasattr(self, '_m_color_table_size') else None - - - class LocalImageDescriptor(KaitaiStruct): - SEQ_FIELDS = ["left", "top", "width", "height", "flags", "local_color_table", "image_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left']['start'] = self._io.pos() - self.left = self._io.read_u2le() - self._debug['left']['end'] = self._io.pos() - self._debug['top']['start'] = self._io.pos() - self.top = self._io.read_u2le() - self._debug['top']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - if self.has_color_table: - self._debug['local_color_table']['start'] = self._io.pos() - self._raw_local_color_table = self._io.read_bytes((self.color_table_size * 3)) - io = KaitaiStream(BytesIO(self._raw_local_color_table)) - self.local_color_table = self._root.ColorTable(io, self, self._root) - self.local_color_table._read() - self._debug['local_color_table']['end'] = self._io.pos() - - self._debug['image_data']['start'] = self._io.pos() - self.image_data = self._root.ImageData(self._io, self, self._root) - self.image_data._read() - self._debug['image_data']['end'] = self._io.pos() - - @property - def has_color_table(self): - if hasattr(self, '_m_has_color_table'): - return self._m_has_color_table if hasattr(self, '_m_has_color_table') else None - - self._m_has_color_table = (self.flags & 128) != 0 - return self._m_has_color_table if hasattr(self, '_m_has_color_table') else None - - @property - def has_interlace(self): - if hasattr(self, '_m_has_interlace'): - return self._m_has_interlace if hasattr(self, '_m_has_interlace') else None - - self._m_has_interlace = (self.flags & 64) != 0 - return self._m_has_interlace if hasattr(self, '_m_has_interlace') else None - - @property - def has_sorted_color_table(self): - if hasattr(self, '_m_has_sorted_color_table'): - return self._m_has_sorted_color_table if hasattr(self, '_m_has_sorted_color_table') else None - - self._m_has_sorted_color_table = (self.flags & 32) != 0 - return self._m_has_sorted_color_table if hasattr(self, '_m_has_sorted_color_table') else None - - @property - def color_table_size(self): - if hasattr(self, '_m_color_table_size'): - return self._m_color_table_size if hasattr(self, '_m_color_table_size') else None - - self._m_color_table_size = (2 << (self.flags & 7)) - return self._m_color_table_size if hasattr(self, '_m_color_table_size') else None - - - class Block(KaitaiStruct): - SEQ_FIELDS = ["block_type", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_type']['start'] = self._io.pos() - self.block_type = KaitaiStream.resolve_enum(self._root.BlockType, self._io.read_u1()) - self._debug['block_type']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.block_type - if _on == self._root.BlockType.extension: - self.body = self._root.Extension(self._io, self, self._root) - self.body._read() - elif _on == self._root.BlockType.local_image_descriptor: - self.body = self._root.LocalImageDescriptor(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class ColorTable(KaitaiStruct): - """ - .. seealso:: - - section 19 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt - """ - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.ColorTableEntry(self._io, self, self._root) - _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() - - - class Header(KaitaiStruct): - """ - .. seealso:: - - section 17 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt - """ - SEQ_FIELDS = ["magic", "version"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x47\x49\x46") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = (self._io.read_bytes(3)).decode(u"ASCII") - self._debug['version']['end'] = self._io.pos() - - - class ExtGraphicControl(KaitaiStruct): - """ - .. seealso:: - - section 23 - https://www.w3.org/Graphics/GIF/spec-gif89a.txt - """ - SEQ_FIELDS = ["block_size", "flags", "delay_time", "transparent_idx", "terminator"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_size']['start'] = self._io.pos() - self.block_size = self._io.ensure_fixed_contents(b"\x04") - self._debug['block_size']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['delay_time']['start'] = self._io.pos() - self.delay_time = self._io.read_u2le() - self._debug['delay_time']['end'] = self._io.pos() - self._debug['transparent_idx']['start'] = self._io.pos() - self.transparent_idx = self._io.read_u1() - self._debug['transparent_idx']['end'] = self._io.pos() - self._debug['terminator']['start'] = self._io.pos() - self.terminator = self._io.ensure_fixed_contents(b"\x00") - self._debug['terminator']['end'] = self._io.pos() - - @property - def transparent_color_flag(self): - if hasattr(self, '_m_transparent_color_flag'): - return self._m_transparent_color_flag if hasattr(self, '_m_transparent_color_flag') else None - - self._m_transparent_color_flag = (self.flags & 1) != 0 - return self._m_transparent_color_flag if hasattr(self, '_m_transparent_color_flag') else None - - @property - def user_input_flag(self): - if hasattr(self, '_m_user_input_flag'): - return self._m_user_input_flag if hasattr(self, '_m_user_input_flag') else None - - self._m_user_input_flag = (self.flags & 2) != 0 - return self._m_user_input_flag if hasattr(self, '_m_user_input_flag') else None - - - class Subblock(KaitaiStruct): - SEQ_FIELDS = ["num_bytes", "bytes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_bytes']['start'] = self._io.pos() - self.num_bytes = self._io.read_u1() - self._debug['num_bytes']['end'] = self._io.pos() - self._debug['bytes']['start'] = self._io.pos() - self.bytes = self._io.read_bytes(self.num_bytes) - self._debug['bytes']['end'] = self._io.pos() - - - class ExtApplication(KaitaiStruct): - SEQ_FIELDS = ["application_id", "subblocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['application_id']['start'] = self._io.pos() - self.application_id = self._root.Subblock(self._io, self, self._root) - self.application_id._read() - self._debug['application_id']['end'] = self._io.pos() - self._debug['subblocks']['start'] = self._io.pos() - self.subblocks = [] - i = 0 - while True: - if not 'arr' in self._debug['subblocks']: - self._debug['subblocks']['arr'] = [] - self._debug['subblocks']['arr'].append({'start': self._io.pos()}) - _t_subblocks = self._root.Subblock(self._io, self, self._root) - _t_subblocks._read() - _ = _t_subblocks - self.subblocks.append(_) - self._debug['subblocks']['arr'][len(self.subblocks) - 1]['end'] = self._io.pos() - if _.num_bytes == 0: - break - i += 1 - self._debug['subblocks']['end'] = self._io.pos() - - - class Subblocks(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entries']['start'] = self._io.pos() - self.entries = [] - i = 0 - while True: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.Subblock(self._io, self, self._root) - _t_entries._read() - _ = _t_entries - self.entries.append(_) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - if _.num_bytes == 0: - break - i += 1 - self._debug['entries']['end'] = self._io.pos() - - - class Extension(KaitaiStruct): - SEQ_FIELDS = ["label", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['label']['start'] = self._io.pos() - self.label = KaitaiStream.resolve_enum(self._root.ExtensionLabel, self._io.read_u1()) - self._debug['label']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.label - if _on == self._root.ExtensionLabel.application: - self.body = self._root.ExtApplication(self._io, self, self._root) - self.body._read() - elif _on == self._root.ExtensionLabel.comment: - self.body = self._root.Subblocks(self._io, self, self._root) - self.body._read() - elif _on == self._root.ExtensionLabel.graphic_control: - self.body = self._root.ExtGraphicControl(self._io, self, self._root) - self.body._read() - else: - self.body = self._root.Subblocks(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/glibc_utmp.py b/python/examples/kaitai/glibc_utmp.py deleted file mode 100644 index 80ba88f9..00000000 --- a/python/examples/kaitai/glibc_utmp.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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 -import collections - - -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 GlibcUtmp(KaitaiStruct): - - class EntryType(Enum): - empty = 0 - run_lvl = 1 - boot_time = 2 - new_time = 3 - old_time = 4 - init_process = 5 - login_process = 6 - user_process = 7 - dead_process = 8 - accounting = 9 - SEQ_FIELDS = ["records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['records']['start'] = self._io.pos() - self._raw_records = [] - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - self._raw_records.append(self._io.read_bytes(384)) - io = KaitaiStream(BytesIO(self._raw_records[-1])) - _t_records = self._root.Record(io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class Record(KaitaiStruct): - SEQ_FIELDS = ["ut_type", "pid", "line", "id", "user", "host", "exit", "session", "tv", "addr_v6", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ut_type']['start'] = self._io.pos() - self.ut_type = KaitaiStream.resolve_enum(self._root.EntryType, self._io.read_s4le()) - self._debug['ut_type']['end'] = self._io.pos() - self._debug['pid']['start'] = self._io.pos() - self.pid = self._io.read_u4le() - self._debug['pid']['end'] = self._io.pos() - self._debug['line']['start'] = self._io.pos() - self.line = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['line']['end'] = self._io.pos() - self._debug['id']['start'] = self._io.pos() - self.id = (self._io.read_bytes(4)).decode(u"UTF-8") - self._debug['id']['end'] = self._io.pos() - self._debug['user']['start'] = self._io.pos() - self.user = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['user']['end'] = self._io.pos() - self._debug['host']['start'] = self._io.pos() - self.host = (self._io.read_bytes(256)).decode(u"UTF-8") - self._debug['host']['end'] = self._io.pos() - self._debug['exit']['start'] = self._io.pos() - self.exit = self._io.read_u4le() - self._debug['exit']['end'] = self._io.pos() - self._debug['session']['start'] = self._io.pos() - self.session = self._io.read_s4le() - self._debug['session']['end'] = self._io.pos() - self._debug['tv']['start'] = self._io.pos() - self.tv = self._root.Timeval(self._io, self, self._root) - self.tv._read() - self._debug['tv']['end'] = self._io.pos() - self._debug['addr_v6']['start'] = self._io.pos() - self.addr_v6 = self._io.read_bytes(16) - self._debug['addr_v6']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(20) - self._debug['reserved']['end'] = self._io.pos() - - - class Timeval(KaitaiStruct): - SEQ_FIELDS = ["sec", "usec"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sec']['start'] = self._io.pos() - self.sec = self._io.read_s4le() - self._debug['sec']['end'] = self._io.pos() - self._debug['usec']['start'] = self._io.pos() - self.usec = self._io.read_s4le() - self._debug['usec']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/google_protobuf.py b/python/examples/kaitai/google_protobuf.py deleted file mode 100644 index 74d8020e..00000000 --- a/python/examples/kaitai/google_protobuf.py +++ /dev/null @@ -1,150 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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)) - -from .vlq_base128_le import VlqBase128Le -class GoogleProtobuf(KaitaiStruct): - """Google Protocol Buffers (AKA protobuf) is a popular data - serialization scheme used for communication protocols, data storage, - etc. There are implementations are available for almost every - popular language. The focus points of this scheme are brevity (data - is encoded in a very size-efficient manner) and extensibility (one - can add keys to the structure, while keeping it readable in previous - version of software). - - Protobuf uses semi-self-describing encoding scheme for its - messages. It means that it is possible to parse overall structure of - the message (skipping over fields one can't understand), but to - fully understand the message, one needs a protocol definition file - (`.proto`). To be specific: - - * "Keys" in key-value pairs provided in the message are identified - only with an integer "field tag". `.proto` file provides info on - which symbolic field names these field tags map to. - * "Keys" also provide something called "wire type". It's not a data - type in its common sense (i.e. you can't, for example, distinguish - `sint32` vs `uint32` vs some enum, or `string` from `bytes`), but - it's enough information to determine how many bytes to - parse. Interpretation of the value should be done according to the - type specified in `.proto` file. - * There's no direct information on which fields are optional / - required, which fields may be repeated or constitute a map, what - restrictions are placed on fields usage in a single message, what - are the fields' default values, etc, etc. - - .. seealso:: - Source - https://developers.google.com/protocol-buffers/docs/encoding - """ - SEQ_FIELDS = ["pairs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pairs']['start'] = self._io.pos() - self.pairs = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['pairs']: - self._debug['pairs']['arr'] = [] - self._debug['pairs']['arr'].append({'start': self._io.pos()}) - _t_pairs = self._root.Pair(self._io, self, self._root) - _t_pairs._read() - self.pairs.append(_t_pairs) - self._debug['pairs']['arr'][len(self.pairs) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['pairs']['end'] = self._io.pos() - - class Pair(KaitaiStruct): - """Key-value pair.""" - - class WireTypes(Enum): - varint = 0 - bit_64 = 1 - len_delimited = 2 - group_start = 3 - group_end = 4 - bit_32 = 5 - SEQ_FIELDS = ["key", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key']['start'] = self._io.pos() - self.key = VlqBase128Le(self._io) - self.key._read() - self._debug['key']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - _on = self.wire_type - if _on == self._root.Pair.WireTypes.varint: - self.value = VlqBase128Le(self._io) - self.value._read() - elif _on == self._root.Pair.WireTypes.len_delimited: - self.value = self._root.DelimitedBytes(self._io, self, self._root) - self.value._read() - elif _on == self._root.Pair.WireTypes.bit_64: - self.value = self._io.read_u8le() - elif _on == self._root.Pair.WireTypes.bit_32: - self.value = self._io.read_u4le() - self._debug['value']['end'] = self._io.pos() - - @property - def wire_type(self): - """"Wire type" is a part of the "key" that carries enough - information to parse value from the wire, i.e. read correct - amount of bytes, but there's not enough informaton to - interprete in unambiguously. For example, one can't clearly - distinguish 64-bit fixed-sized integers from 64-bit floats, - signed zigzag-encoded varints from regular unsigned varints, - arbitrary bytes from UTF-8 encoded strings, etc. - """ - if hasattr(self, '_m_wire_type'): - return self._m_wire_type if hasattr(self, '_m_wire_type') else None - - self._m_wire_type = KaitaiStream.resolve_enum(self._root.Pair.WireTypes, (self.key.value & 7)) - return self._m_wire_type if hasattr(self, '_m_wire_type') else None - - @property - def field_tag(self): - """Identifies a field of protocol. One can look up symbolic - field name in a `.proto` file by this field tag. - """ - if hasattr(self, '_m_field_tag'): - return self._m_field_tag if hasattr(self, '_m_field_tag') else None - - self._m_field_tag = (self.key.value >> 3) - return self._m_field_tag if hasattr(self, '_m_field_tag') else None - - - class DelimitedBytes(KaitaiStruct): - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = VlqBase128Le(self._io) - self.len._read() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len.value) - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/gpt_partition_table.py b/python/examples/kaitai/gpt_partition_table.py deleted file mode 100644 index e6f0c9ed..00000000 --- a/python/examples/kaitai/gpt_partition_table.py +++ /dev/null @@ -1,172 +0,0 @@ -# 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 -import collections - - -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 GptPartitionTable(KaitaiStruct): - """ - .. seealso:: - Specification taken from https://en.wikipedia.org/wiki/GUID_Partition_Table - """ - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class PartitionEntry(KaitaiStruct): - SEQ_FIELDS = ["type_guid", "guid", "first_lba", "last_lba", "attributes", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type_guid']['start'] = self._io.pos() - self.type_guid = self._io.read_bytes(16) - self._debug['type_guid']['end'] = self._io.pos() - self._debug['guid']['start'] = self._io.pos() - self.guid = self._io.read_bytes(16) - self._debug['guid']['end'] = self._io.pos() - self._debug['first_lba']['start'] = self._io.pos() - self.first_lba = self._io.read_u8le() - self._debug['first_lba']['end'] = self._io.pos() - self._debug['last_lba']['start'] = self._io.pos() - self.last_lba = self._io.read_u8le() - self._debug['last_lba']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = self._io.read_u8le() - self._debug['attributes']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(72)).decode(u"UTF-16LE") - self._debug['name']['end'] = self._io.pos() - - - class PartitionHeader(KaitaiStruct): - SEQ_FIELDS = ["signature", "revision", "header_size", "crc32_header", "reserved", "current_lba", "backup_lba", "first_usable_lba", "last_usable_lba", "disk_guid", "entries_start", "entries_count", "entries_size", "crc32_array"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x45\x46\x49\x20\x50\x41\x52\x54") - self._debug['signature']['end'] = self._io.pos() - self._debug['revision']['start'] = self._io.pos() - self.revision = self._io.read_u4le() - self._debug['revision']['end'] = self._io.pos() - 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['crc32_header']['start'] = self._io.pos() - self.crc32_header = self._io.read_u4le() - self._debug['crc32_header']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u4le() - self._debug['reserved']['end'] = self._io.pos() - self._debug['current_lba']['start'] = self._io.pos() - self.current_lba = self._io.read_u8le() - self._debug['current_lba']['end'] = self._io.pos() - self._debug['backup_lba']['start'] = self._io.pos() - self.backup_lba = self._io.read_u8le() - self._debug['backup_lba']['end'] = self._io.pos() - self._debug['first_usable_lba']['start'] = self._io.pos() - self.first_usable_lba = self._io.read_u8le() - self._debug['first_usable_lba']['end'] = self._io.pos() - self._debug['last_usable_lba']['start'] = self._io.pos() - self.last_usable_lba = self._io.read_u8le() - self._debug['last_usable_lba']['end'] = self._io.pos() - self._debug['disk_guid']['start'] = self._io.pos() - self.disk_guid = self._io.read_bytes(16) - self._debug['disk_guid']['end'] = self._io.pos() - self._debug['entries_start']['start'] = self._io.pos() - self.entries_start = self._io.read_u8le() - self._debug['entries_start']['end'] = self._io.pos() - self._debug['entries_count']['start'] = self._io.pos() - self.entries_count = self._io.read_u4le() - self._debug['entries_count']['end'] = self._io.pos() - self._debug['entries_size']['start'] = self._io.pos() - self.entries_size = self._io.read_u4le() - self._debug['entries_size']['end'] = self._io.pos() - self._debug['crc32_array']['start'] = self._io.pos() - self.crc32_array = self._io.read_u4le() - self._debug['crc32_array']['end'] = self._io.pos() - - @property - def entries(self): - if hasattr(self, '_m_entries'): - return self._m_entries if hasattr(self, '_m_entries') else None - - io = self._root._io - _pos = io.pos() - io.seek((self.entries_start * self._root.sector_size)) - self._debug['_m_entries']['start'] = io.pos() - self._raw__m_entries = [None] * (self.entries_count) - self._m_entries = [None] * (self.entries_count) - for i in range(self.entries_count): - if not 'arr' in self._debug['_m_entries']: - self._debug['_m_entries']['arr'] = [] - self._debug['_m_entries']['arr'].append({'start': io.pos()}) - self._raw__m_entries[i] = io.read_bytes(self.entries_size) - io = KaitaiStream(BytesIO(self._raw__m_entries[i])) - _t__m_entries = self._root.PartitionEntry(io, self, self._root) - _t__m_entries._read() - self._m_entries[i] = _t__m_entries - self._debug['_m_entries']['arr'][i]['end'] = io.pos() - - self._debug['_m_entries']['end'] = io.pos() - io.seek(_pos) - return self._m_entries if hasattr(self, '_m_entries') else None - - - @property - def sector_size(self): - if hasattr(self, '_m_sector_size'): - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - self._m_sector_size = 512 - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - @property - def primary(self): - if hasattr(self, '_m_primary'): - return self._m_primary if hasattr(self, '_m_primary') else None - - io = self._root._io - _pos = io.pos() - io.seek(self._root.sector_size) - self._debug['_m_primary']['start'] = io.pos() - self._m_primary = self._root.PartitionHeader(io, self, self._root) - self._m_primary._read() - self._debug['_m_primary']['end'] = io.pos() - io.seek(_pos) - return self._m_primary if hasattr(self, '_m_primary') else None - - @property - def backup(self): - if hasattr(self, '_m_backup'): - return self._m_backup if hasattr(self, '_m_backup') else None - - io = self._root._io - _pos = io.pos() - io.seek((self._io.size() - self._root.sector_size)) - self._debug['_m_backup']['start'] = io.pos() - self._m_backup = self._root.PartitionHeader(io, self, self._root) - self._m_backup._read() - self._debug['_m_backup']['end'] = io.pos() - io.seek(_pos) - return self._m_backup if hasattr(self, '_m_backup') else None - - diff --git a/python/examples/kaitai/gran_turismo_vol.py b/python/examples/kaitai/gran_turismo_vol.py deleted file mode 100644 index 34e9df0e..00000000 --- a/python/examples/kaitai/gran_turismo_vol.py +++ /dev/null @@ -1,135 +0,0 @@ -# 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 -import collections - - -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 GranTurismoVol(KaitaiStruct): - SEQ_FIELDS = ["magic", "num_files", "num_entries", "reserved", "offsets"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x47\x54\x46\x53\x00\x00\x00\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['num_files']['start'] = self._io.pos() - self.num_files = self._io.read_u2le() - self._debug['num_files']['end'] = self._io.pos() - self._debug['num_entries']['start'] = self._io.pos() - self.num_entries = self._io.read_u2le() - self._debug['num_entries']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['offsets']['start'] = self._io.pos() - self.offsets = [None] * (self.num_files) - for i in range(self.num_files): - if not 'arr' in self._debug['offsets']: - self._debug['offsets']['arr'] = [] - self._debug['offsets']['arr'].append({'start': self._io.pos()}) - self.offsets[i] = self._io.read_u4le() - self._debug['offsets']['arr'][i]['end'] = self._io.pos() - - self._debug['offsets']['end'] = self._io.pos() - - class FileInfo(KaitaiStruct): - SEQ_FIELDS = ["timestamp", "offset_idx", "flags", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4le() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['offset_idx']['start'] = self._io.pos() - self.offset_idx = self._io.read_u2le() - self._debug['offset_idx']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(KaitaiStream.bytes_strip_right(self._io.read_bytes(25), 0), 0, False)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - - @property - def size(self): - if hasattr(self, '_m_size'): - return self._m_size if hasattr(self, '_m_size') else None - - self._m_size = ((self._root.offsets[(self.offset_idx + 1)] & 4294965248) - self._root.offsets[self.offset_idx]) - return self._m_size if hasattr(self, '_m_size') else None - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - if not (self.is_dir): - _pos = self._io.pos() - self._io.seek((self._root.offsets[self.offset_idx] & 4294965248)) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._io.read_bytes(self.size) - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_body if hasattr(self, '_m_body') else None - - @property - def is_dir(self): - if hasattr(self, '_m_is_dir'): - return self._m_is_dir if hasattr(self, '_m_is_dir') else None - - self._m_is_dir = (self.flags & 1) != 0 - return self._m_is_dir if hasattr(self, '_m_is_dir') else None - - @property - def is_last_entry(self): - if hasattr(self, '_m_is_last_entry'): - return self._m_is_last_entry if hasattr(self, '_m_is_last_entry') else None - - self._m_is_last_entry = (self.flags & 128) != 0 - return self._m_is_last_entry if hasattr(self, '_m_is_last_entry') else None - - - @property - def ofs_dir(self): - if hasattr(self, '_m_ofs_dir'): - return self._m_ofs_dir if hasattr(self, '_m_ofs_dir') else None - - self._m_ofs_dir = self.offsets[1] - return self._m_ofs_dir if hasattr(self, '_m_ofs_dir') else None - - @property - def files(self): - if hasattr(self, '_m_files'): - return self._m_files if hasattr(self, '_m_files') else None - - _pos = self._io.pos() - self._io.seek((self.ofs_dir & 4294965248)) - self._debug['_m_files']['start'] = self._io.pos() - self._m_files = [None] * (self._root.num_entries) - for i in range(self._root.num_entries): - if not 'arr' in self._debug['_m_files']: - self._debug['_m_files']['arr'] = [] - self._debug['_m_files']['arr'].append({'start': self._io.pos()}) - _t__m_files = self._root.FileInfo(self._io, self, self._root) - _t__m_files._read() - self._m_files[i] = _t__m_files - self._debug['_m_files']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_files']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_files if hasattr(self, '_m_files') else None - - diff --git a/python/examples/kaitai/gzip.py b/python/examples/kaitai/gzip.py deleted file mode 100644 index 2f03aeec..00000000 --- a/python/examples/kaitai/gzip.py +++ /dev/null @@ -1,229 +0,0 @@ -# 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 -import collections - - -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 Gzip(KaitaiStruct): - """Gzip is a popular and standard single-file archiving format. It - essentially provides a container that stores original file name, - timestamp and a few other things (like optional comment), basic - CRCs, etc, and a file compressed by a chosen compression algorithm. - - As of 2019, there is actually only one working solution for - compression algorithms, so it's typically raw DEFLATE stream - (without zlib header) in all gzipped files. - - .. seealso:: - Source - https://tools.ietf.org/html/rfc1952 - """ - - class CompressionMethods(Enum): - deflate = 8 - - class Oses(Enum): - fat = 0 - amiga = 1 - vms = 2 - unix = 3 - vm_cms = 4 - atari_tos = 5 - hpfs = 6 - macintosh = 7 - z_system = 8 - cp_m = 9 - tops_20 = 10 - ntfs = 11 - qdos = 12 - acorn_riscos = 13 - unknown = 255 - SEQ_FIELDS = ["magic", "compression_method", "flags", "mod_time", "extra_flags", "os", "extras", "name", "comment", "header_crc16", "body", "body_crc32", "len_uncompressed"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x1F\x8B") - self._debug['magic']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.CompressionMethods, self._io.read_u1()) - self._debug['compression_method']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['mod_time']['start'] = self._io.pos() - self.mod_time = self._io.read_u4le() - self._debug['mod_time']['end'] = self._io.pos() - self._debug['extra_flags']['start'] = self._io.pos() - _on = self.compression_method - if _on == self._root.CompressionMethods.deflate: - self.extra_flags = self._root.ExtraFlagsDeflate(self._io, self, self._root) - self.extra_flags._read() - self._debug['extra_flags']['end'] = self._io.pos() - self._debug['os']['start'] = self._io.pos() - self.os = KaitaiStream.resolve_enum(self._root.Oses, self._io.read_u1()) - self._debug['os']['end'] = self._io.pos() - if self.flags.has_extra: - self._debug['extras']['start'] = self._io.pos() - self.extras = self._root.Extras(self._io, self, self._root) - self.extras._read() - self._debug['extras']['end'] = self._io.pos() - - if self.flags.has_name: - self._debug['name']['start'] = self._io.pos() - self.name = self._io.read_bytes_term(0, False, True, True) - self._debug['name']['end'] = self._io.pos() - - if self.flags.has_comment: - self._debug['comment']['start'] = self._io.pos() - self.comment = self._io.read_bytes_term(0, False, True, True) - self._debug['comment']['end'] = self._io.pos() - - if self.flags.has_header_crc: - self._debug['header_crc16']['start'] = self._io.pos() - self.header_crc16 = self._io.read_u2le() - self._debug['header_crc16']['end'] = self._io.pos() - - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(((self._io.size() - self._io.pos()) - 8)) - self._debug['body']['end'] = self._io.pos() - self._debug['body_crc32']['start'] = self._io.pos() - self.body_crc32 = self._io.read_u4le() - self._debug['body_crc32']['end'] = self._io.pos() - self._debug['len_uncompressed']['start'] = self._io.pos() - self.len_uncompressed = self._io.read_u4le() - self._debug['len_uncompressed']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "has_comment", "has_name", "has_extra", "has_header_crc", "is_text"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(3) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['has_comment']['start'] = self._io.pos() - self.has_comment = self._io.read_bits_int(1) != 0 - self._debug['has_comment']['end'] = self._io.pos() - self._debug['has_name']['start'] = self._io.pos() - self.has_name = self._io.read_bits_int(1) != 0 - self._debug['has_name']['end'] = self._io.pos() - self._debug['has_extra']['start'] = self._io.pos() - self.has_extra = self._io.read_bits_int(1) != 0 - self._debug['has_extra']['end'] = self._io.pos() - self._debug['has_header_crc']['start'] = self._io.pos() - self.has_header_crc = self._io.read_bits_int(1) != 0 - self._debug['has_header_crc']['end'] = self._io.pos() - self._debug['is_text']['start'] = self._io.pos() - self.is_text = self._io.read_bits_int(1) != 0 - self._debug['is_text']['end'] = self._io.pos() - - - class ExtraFlagsDeflate(KaitaiStruct): - - class CompressionStrengths(Enum): - best = 2 - fast = 4 - SEQ_FIELDS = ["compression_strength"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['compression_strength']['start'] = self._io.pos() - self.compression_strength = KaitaiStream.resolve_enum(self._root.ExtraFlagsDeflate.CompressionStrengths, self._io.read_u1()) - self._debug['compression_strength']['end'] = self._io.pos() - - - class Subfields(KaitaiStruct): - """Container for many subfields, constrained by size of stream. - """ - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Subfield(self._io, self, self._root) - _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() - - - class Subfield(KaitaiStruct): - """Every subfield follows typical [TLV scheme](https://en.wikipedia.org/wiki/Type-length-value): - - * `id` serves role of "T"ype - * `len_data` serves role of "L"ength - * `data` serves role of "V"alue - - This way it's possible to for arbitrary parser to skip over - subfields it does not support. - """ - SEQ_FIELDS = ["id", "len_data", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = self._io.read_u2le() - self._debug['id']['end'] = self._io.pos() - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u2le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.len_data) - self._debug['data']['end'] = self._io.pos() - - - class Extras(KaitaiStruct): - SEQ_FIELDS = ["len_subfields", "subfields"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_subfields']['start'] = self._io.pos() - self.len_subfields = self._io.read_u2le() - self._debug['len_subfields']['end'] = self._io.pos() - self._debug['subfields']['start'] = self._io.pos() - self._raw_subfields = self._io.read_bytes(self.len_subfields) - io = KaitaiStream(BytesIO(self._raw_subfields)) - self.subfields = self._root.Subfields(io, self, self._root) - self.subfields._read() - self._debug['subfields']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/hccap.py b/python/examples/kaitai/hccap.py deleted file mode 100644 index 48fc17f4..00000000 --- a/python/examples/kaitai/hccap.py +++ /dev/null @@ -1,109 +0,0 @@ -# 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 -import collections - - -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 Hccap(KaitaiStruct): - """Native format of Hashcat password "recovery" utility. - - A sample of file for testing can be downloaded from https://web.archive.org/web/20150220013635if_/http://hashcat.net:80/misc/example_hashes/hashcat.hccap - - .. seealso:: - Source - https://hashcat.net/wiki/doku.php?id=hccap - """ - SEQ_FIELDS = ["records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.HccapRecord(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class HccapRecord(KaitaiStruct): - SEQ_FIELDS = ["essid", "mac_ap", "mac_station", "nonce_station", "nonce_ap", "eapol_buffer", "len_eapol", "keyver", "keymic"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['essid']['start'] = self._io.pos() - self.essid = self._io.read_bytes(36) - self._debug['essid']['end'] = self._io.pos() - self._debug['mac_ap']['start'] = self._io.pos() - self.mac_ap = self._io.read_bytes(6) - self._debug['mac_ap']['end'] = self._io.pos() - self._debug['mac_station']['start'] = self._io.pos() - self.mac_station = self._io.read_bytes(6) - self._debug['mac_station']['end'] = self._io.pos() - self._debug['nonce_station']['start'] = self._io.pos() - self.nonce_station = self._io.read_bytes(32) - self._debug['nonce_station']['end'] = self._io.pos() - self._debug['nonce_ap']['start'] = self._io.pos() - self.nonce_ap = self._io.read_bytes(32) - self._debug['nonce_ap']['end'] = self._io.pos() - self._debug['eapol_buffer']['start'] = self._io.pos() - self._raw_eapol_buffer = self._io.read_bytes(256) - io = KaitaiStream(BytesIO(self._raw_eapol_buffer)) - self.eapol_buffer = self._root.EapolDummy(io, self, self._root) - self.eapol_buffer._read() - self._debug['eapol_buffer']['end'] = self._io.pos() - self._debug['len_eapol']['start'] = self._io.pos() - self.len_eapol = self._io.read_u4le() - self._debug['len_eapol']['end'] = self._io.pos() - self._debug['keyver']['start'] = self._io.pos() - self.keyver = self._io.read_u4le() - self._debug['keyver']['end'] = self._io.pos() - self._debug['keymic']['start'] = self._io.pos() - self.keymic = self._io.read_bytes(16) - self._debug['keymic']['end'] = self._io.pos() - - @property - def eapol(self): - if hasattr(self, '_m_eapol'): - return self._m_eapol if hasattr(self, '_m_eapol') else None - - io = self.eapol_buffer._io - _pos = io.pos() - io.seek(0) - self._debug['_m_eapol']['start'] = io.pos() - self._m_eapol = io.read_bytes(self.len_eapol) - self._debug['_m_eapol']['end'] = io.pos() - io.seek(_pos) - return self._m_eapol if hasattr(self, '_m_eapol') else None - - - class EapolDummy(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - diff --git a/python/examples/kaitai/hccapx.py b/python/examples/kaitai/hccapx.py deleted file mode 100644 index 8727ecfe..00000000 --- a/python/examples/kaitai/hccapx.py +++ /dev/null @@ -1,100 +0,0 @@ -# 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 -import collections - - -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 Hccapx(KaitaiStruct): - """Native format of Hashcat password "recovery" utility - - .. seealso:: - Source - https://hashcat.net/wiki/doku.php?id=hccapx - """ - SEQ_FIELDS = ["records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.HccapxRecord(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class HccapxRecord(KaitaiStruct): - SEQ_FIELDS = ["magic", "version", "ignore_replay_counter", "message_pair", "len_essid", "essid", "padding1", "keyver", "keymic", "mac_ap", "nonce_ap", "mac_station", "nonce_station", "len_eapol", "eapol", "padding2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x48\x43\x50\x58") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u4le() - self._debug['version']['end'] = self._io.pos() - self._debug['ignore_replay_counter']['start'] = self._io.pos() - self.ignore_replay_counter = self._io.read_bits_int(1) != 0 - self._debug['ignore_replay_counter']['end'] = self._io.pos() - self._debug['message_pair']['start'] = self._io.pos() - self.message_pair = self._io.read_bits_int(7) - self._debug['message_pair']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['len_essid']['start'] = self._io.pos() - self.len_essid = self._io.read_u1() - self._debug['len_essid']['end'] = self._io.pos() - self._debug['essid']['start'] = self._io.pos() - self.essid = self._io.read_bytes(self.len_essid) - self._debug['essid']['end'] = self._io.pos() - self._debug['padding1']['start'] = self._io.pos() - self.padding1 = self._io.read_bytes((32 - self.len_essid)) - self._debug['padding1']['end'] = self._io.pos() - self._debug['keyver']['start'] = self._io.pos() - self.keyver = self._io.read_u1() - self._debug['keyver']['end'] = self._io.pos() - self._debug['keymic']['start'] = self._io.pos() - self.keymic = self._io.read_bytes(16) - self._debug['keymic']['end'] = self._io.pos() - self._debug['mac_ap']['start'] = self._io.pos() - self.mac_ap = self._io.read_bytes(6) - self._debug['mac_ap']['end'] = self._io.pos() - self._debug['nonce_ap']['start'] = self._io.pos() - self.nonce_ap = self._io.read_bytes(32) - self._debug['nonce_ap']['end'] = self._io.pos() - self._debug['mac_station']['start'] = self._io.pos() - self.mac_station = self._io.read_bytes(6) - self._debug['mac_station']['end'] = self._io.pos() - self._debug['nonce_station']['start'] = self._io.pos() - self.nonce_station = self._io.read_bytes(32) - self._debug['nonce_station']['end'] = self._io.pos() - self._debug['len_eapol']['start'] = self._io.pos() - self.len_eapol = self._io.read_u2le() - self._debug['len_eapol']['end'] = self._io.pos() - self._debug['eapol']['start'] = self._io.pos() - self.eapol = self._io.read_bytes(self.len_eapol) - self._debug['eapol']['end'] = self._io.pos() - self._debug['padding2']['start'] = self._io.pos() - self.padding2 = self._io.read_bytes((256 - self.len_eapol)) - self._debug['padding2']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/heaps_pak.py b/python/examples/kaitai/heaps_pak.py deleted file mode 100644 index a0e44da6..00000000 --- a/python/examples/kaitai/heaps_pak.py +++ /dev/null @@ -1,172 +0,0 @@ -# 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 -import collections - - -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 HeapsPak(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/HeapsIO/heaps/blob/2bbc2b386952dfd8856c04a854bb706a52cb4b58/hxd/fmt/pak/Reader.hx - """ - SEQ_FIELDS = ["header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["magic1", "version", "len_header", "len_data", "root_entry", "magic2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic1']['start'] = self._io.pos() - self.magic1 = self._io.ensure_fixed_contents(b"\x50\x41\x4B") - self._debug['magic1']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u4le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u4le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['root_entry']['start'] = self._io.pos() - self._raw_root_entry = self._io.read_bytes((self.len_header - 16)) - io = KaitaiStream(BytesIO(self._raw_root_entry)) - self.root_entry = self._root.Header.Entry(io, self, self._root) - self.root_entry._read() - self._debug['root_entry']['end'] = self._io.pos() - self._debug['magic2']['start'] = self._io.pos() - self.magic2 = self._io.ensure_fixed_contents(b"\x44\x41\x54\x41") - self._debug['magic2']['end'] = self._io.pos() - - class Entry(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/HeapsIO/heaps/blob/2bbc2b386952dfd8856c04a854bb706a52cb4b58/hxd/fmt/pak/Data.hx - """ - SEQ_FIELDS = ["len_name", "name", "flags", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_name']['start'] = self._io.pos() - self.len_name = self._io.read_u1() - self._debug['len_name']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.len_name)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Header.Entry.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.flags.is_dir - if _on == True: - self.body = self._root.Header.Dir(self._io, self, self._root) - self.body._read() - elif _on == False: - self.body = self._root.Header.File(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["unused", "is_dir"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_bits_int(7) - self._debug['unused']['end'] = self._io.pos() - self._debug['is_dir']['start'] = self._io.pos() - self.is_dir = self._io.read_bits_int(1) != 0 - self._debug['is_dir']['end'] = self._io.pos() - - - - class File(KaitaiStruct): - SEQ_FIELDS = ["ofs_data", "len_data", "checksum"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs_data']['start'] = self._io.pos() - self.ofs_data = self._io.read_u4le() - self._debug['ofs_data']['end'] = self._io.pos() - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u4le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_bytes(4) - self._debug['checksum']['end'] = self._io.pos() - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - io = self._root._io - _pos = io.pos() - io.seek((self._root.header.len_header + self.ofs_data)) - self._debug['_m_data']['start'] = io.pos() - self._m_data = io.read_bytes(self.len_data) - self._debug['_m_data']['end'] = io.pos() - io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - class Dir(KaitaiStruct): - SEQ_FIELDS = ["num_entries", "entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_entries']['start'] = self._io.pos() - self.num_entries = self._io.read_u4le() - self._debug['num_entries']['end'] = self._io.pos() - self._debug['entries']['start'] = self._io.pos() - self.entries = [None] * (self.num_entries) - for i in range(self.num_entries): - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.Header.Entry(self._io, self, self._root) - _t_entries._read() - self.entries[i] = _t_entries - self._debug['entries']['arr'][i]['end'] = self._io.pos() - - self._debug['entries']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/heroes_of_might_and_magic_agg.py b/python/examples/kaitai/heroes_of_might_and_magic_agg.py deleted file mode 100644 index 9e45cf0c..00000000 --- a/python/examples/kaitai/heroes_of_might_and_magic_agg.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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 -import collections - - -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 HeroesOfMightAndMagicAgg(KaitaiStruct): - """ - .. seealso:: - Source - http://rewiki.regengedanken.de/wiki/.AGG_(Heroes_of_Might_and_Magic) - """ - SEQ_FIELDS = ["num_files", "entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_files']['start'] = self._io.pos() - self.num_files = self._io.read_u2le() - self._debug['num_files']['end'] = self._io.pos() - self._debug['entries']['start'] = self._io.pos() - self.entries = [None] * (self.num_files) - for i in range(self.num_files): - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.Entry(self._io, self, self._root) - _t_entries._read() - self.entries[i] = _t_entries - self._debug['entries']['arr'][i]['end'] = self._io.pos() - - self._debug['entries']['end'] = self._io.pos() - - class Entry(KaitaiStruct): - SEQ_FIELDS = ["hash", "offset", "size", "size2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hash']['start'] = self._io.pos() - self.hash = self._io.read_u2le() - self._debug['hash']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['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['size2']['start'] = self._io.pos() - self.size2 = self._io.read_u4le() - self._debug['size2']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek(self.offset) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._io.read_bytes(self.size) - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class Filename(KaitaiStruct): - SEQ_FIELDS = ["str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['str']['start'] = self._io.pos() - self.str = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['str']['end'] = self._io.pos() - - - @property - def filenames(self): - if hasattr(self, '_m_filenames'): - return self._m_filenames if hasattr(self, '_m_filenames') else None - - _pos = self._io.pos() - self._io.seek((self.entries[-1].offset + self.entries[-1].size)) - self._debug['_m_filenames']['start'] = self._io.pos() - self._raw__m_filenames = [None] * (self.num_files) - self._m_filenames = [None] * (self.num_files) - for i in range(self.num_files): - if not 'arr' in self._debug['_m_filenames']: - self._debug['_m_filenames']['arr'] = [] - self._debug['_m_filenames']['arr'].append({'start': self._io.pos()}) - self._raw__m_filenames[i] = self._io.read_bytes(15) - io = KaitaiStream(BytesIO(self._raw__m_filenames[i])) - _t__m_filenames = self._root.Filename(io, self, self._root) - _t__m_filenames._read() - self._m_filenames[i] = _t__m_filenames - self._debug['_m_filenames']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_filenames']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_filenames if hasattr(self, '_m_filenames') else None - - diff --git a/python/examples/kaitai/heroes_of_might_and_magic_bmp.py b/python/examples/kaitai/heroes_of_might_and_magic_bmp.py deleted file mode 100644 index 014d9797..00000000 --- a/python/examples/kaitai/heroes_of_might_and_magic_bmp.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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 -import collections - - -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 HeroesOfMightAndMagicBmp(KaitaiStruct): - SEQ_FIELDS = ["magic", "width", "height", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.read_u2le() - self._debug['magic']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes((self.width * self.height)) - self._debug['data']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/icc_4.py b/python/examples/kaitai/icc_4.py deleted file mode 100644 index 4597e474..00000000 --- a/python/examples/kaitai/icc_4.py +++ /dev/null @@ -1,3369 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Icc4(KaitaiStruct): - SEQ_FIELDS = ["header", "tag_table"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.ProfileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['tag_table']['start'] = self._io.pos() - self.tag_table = self._root.TagTable(self._io, self, self._root) - self.tag_table._read() - self._debug['tag_table']['end'] = self._io.pos() - - class U8Fixed8Number(KaitaiStruct): - SEQ_FIELDS = ["number"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number']['start'] = self._io.pos() - self.number = self._io.read_bytes(2) - self._debug['number']['end'] = self._io.pos() - - - class U16Fixed16Number(KaitaiStruct): - SEQ_FIELDS = ["number"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number']['start'] = self._io.pos() - self.number = self._io.read_bytes(4) - self._debug['number']['end'] = self._io.pos() - - - class StandardIlluminantEncoding(KaitaiStruct): - - class StandardIlluminantEncodings(Enum): - unknown = 0 - d50 = 1 - d65 = 2 - d93 = 3 - f2 = 4 - d55 = 5 - a = 6 - equi_power = 7 - f8 = 8 - SEQ_FIELDS = ["standard_illuminant_encoding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['standard_illuminant_encoding']['start'] = self._io.pos() - self.standard_illuminant_encoding = KaitaiStream.resolve_enum(self._root.StandardIlluminantEncoding.StandardIlluminantEncodings, self._io.read_u4be()) - self._debug['standard_illuminant_encoding']['end'] = self._io.pos() - - - class ProfileHeader(KaitaiStruct): - - class CmmSignatures(Enum): - the_imaging_factory_cmm = 858931796 - agfa_cmm = 1094929747 - adobe_cmm = 1094992453 - color_gear_cmm = 1128484179 - logosync_cmm = 1147629395 - efi_cmm = 1162234144 - exact_scan_cmm = 1163411779 - fuji_film_cmm = 1179000864 - harlequin_rip_cmm = 1212370253 - heidelberg_cmm = 1212435744 - kodak_cmm = 1262701907 - konica_minolta_cmm = 1296256324 - device_link_cmm = 1380404563 - sample_icc_cmm = 1397310275 - mutoh_cmm = 1397311310 - toshiba_cmm = 1413696845 - color_gear_cmm_lite = 1430471501 - color_gear_cmm_c = 1430474067 - windows_color_system_cmm = 1464029984 - ware_to_go_cmm = 1465141024 - apple_cmm = 1634758764 - argyll_cms_cmm = 1634887532 - little_cms_cmm = 1818455411 - zoran_cmm = 2053320752 - - class PrimaryPlatforms(Enum): - apple_computer_inc = 1095782476 - microsoft_corporation = 1297303124 - silicon_graphics_inc = 1397180704 - sun_microsystems = 1398099543 - - class ProfileClasses(Enum): - abstract_profile = 1633842036 - device_link_profile = 1818848875 - display_device_profile = 1835955314 - named_color_profile = 1852662636 - output_device_profile = 1886549106 - input_device_profile = 1935896178 - color_space_profile = 1936744803 - - class RenderingIntents(Enum): - perceptual = 0 - media_relative_colorimetric = 1 - saturation = 2 - icc_absolute_colorimetric = 3 - - class DataColourSpaces(Enum): - two_colour = 843271250 - three_colour = 860048466 - four_colour = 876825682 - five_colour = 893602898 - six_colour = 910380114 - seven_colour = 927157330 - eight_colour = 943934546 - nine_colour = 960711762 - ten_colour = 1094929490 - eleven_colour = 1111706706 - twelve_colour = 1128483922 - cmy = 1129142560 - cmyk = 1129142603 - thirteen_colour = 1145261138 - fourteen_colour = 1162038354 - fifteen_colour = 1178815570 - gray = 1196573017 - hls = 1212961568 - hsv = 1213421088 - cielab_or_pcslab = 1281450528 - cieluv = 1282766368 - rgb = 1380401696 - nciexyz_or_pcsxyz = 1482250784 - ycbcr = 1497588338 - cieyxy = 1501067552 - SEQ_FIELDS = ["size", "preferred_cmm_type", "version", "device_class", "color_space", "pcs", "creation_date_time", "file_signature", "primary_platform", "profile_flags", "device_manufacturer", "device_model", "device_attributes", "rendering_intent", "nciexyz_values_of_illuminant_of_pcs", "creator", "identifier", "reserved_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4be() - self._debug['size']['end'] = self._io.pos() - self._debug['preferred_cmm_type']['start'] = self._io.pos() - self.preferred_cmm_type = KaitaiStream.resolve_enum(self._root.ProfileHeader.CmmSignatures, self._io.read_u4be()) - self._debug['preferred_cmm_type']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._root.ProfileHeader.VersionField(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['device_class']['start'] = self._io.pos() - self.device_class = KaitaiStream.resolve_enum(self._root.ProfileHeader.ProfileClasses, self._io.read_u4be()) - self._debug['device_class']['end'] = self._io.pos() - self._debug['color_space']['start'] = self._io.pos() - self.color_space = KaitaiStream.resolve_enum(self._root.ProfileHeader.DataColourSpaces, self._io.read_u4be()) - self._debug['color_space']['end'] = self._io.pos() - self._debug['pcs']['start'] = self._io.pos() - self.pcs = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['pcs']['end'] = self._io.pos() - self._debug['creation_date_time']['start'] = self._io.pos() - self.creation_date_time = self._root.DateTimeNumber(self._io, self, self._root) - self.creation_date_time._read() - self._debug['creation_date_time']['end'] = self._io.pos() - self._debug['file_signature']['start'] = self._io.pos() - self.file_signature = self._io.ensure_fixed_contents(b"\x61\x63\x73\x70") - self._debug['file_signature']['end'] = self._io.pos() - self._debug['primary_platform']['start'] = self._io.pos() - self.primary_platform = KaitaiStream.resolve_enum(self._root.ProfileHeader.PrimaryPlatforms, self._io.read_u4be()) - self._debug['primary_platform']['end'] = self._io.pos() - self._debug['profile_flags']['start'] = self._io.pos() - self.profile_flags = self._root.ProfileHeader.ProfileFlags(self._io, self, self._root) - self.profile_flags._read() - self._debug['profile_flags']['end'] = self._io.pos() - self._debug['device_manufacturer']['start'] = self._io.pos() - self.device_manufacturer = self._root.DeviceManufacturer(self._io, self, self._root) - self.device_manufacturer._read() - self._debug['device_manufacturer']['end'] = self._io.pos() - self._debug['device_model']['start'] = self._io.pos() - self.device_model = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['device_model']['end'] = self._io.pos() - self._debug['device_attributes']['start'] = self._io.pos() - self.device_attributes = self._root.DeviceAttributes(self._io, self, self._root) - self.device_attributes._read() - self._debug['device_attributes']['end'] = self._io.pos() - self._debug['rendering_intent']['start'] = self._io.pos() - self.rendering_intent = KaitaiStream.resolve_enum(self._root.ProfileHeader.RenderingIntents, self._io.read_u4be()) - self._debug['rendering_intent']['end'] = self._io.pos() - self._debug['nciexyz_values_of_illuminant_of_pcs']['start'] = self._io.pos() - self.nciexyz_values_of_illuminant_of_pcs = self._root.XyzNumber(self._io, self, self._root) - self.nciexyz_values_of_illuminant_of_pcs._read() - self._debug['nciexyz_values_of_illuminant_of_pcs']['end'] = self._io.pos() - self._debug['creator']['start'] = self._io.pos() - self.creator = self._root.DeviceManufacturer(self._io, self, self._root) - self.creator._read() - self._debug['creator']['end'] = self._io.pos() - self._debug['identifier']['start'] = self._io.pos() - self.identifier = self._io.read_bytes(16) - self._debug['identifier']['end'] = self._io.pos() - self._debug['reserved_data']['start'] = self._io.pos() - self.reserved_data = self._io.read_bytes(28) - self._debug['reserved_data']['end'] = self._io.pos() - - class VersionField(KaitaiStruct): - SEQ_FIELDS = ["major", "minor", "bug_fix_level", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['major']['start'] = self._io.pos() - self.major = self._io.ensure_fixed_contents(b"\x04") - self._debug['major']['end'] = self._io.pos() - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_bits_int(4) - self._debug['minor']['end'] = self._io.pos() - self._debug['bug_fix_level']['start'] = self._io.pos() - self.bug_fix_level = self._io.read_bits_int(4) - self._debug['bug_fix_level']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - - - class ProfileFlags(KaitaiStruct): - SEQ_FIELDS = ["embedded_profile", "profile_can_be_used_independently_of_embedded_colour_data", "other_flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['embedded_profile']['start'] = self._io.pos() - self.embedded_profile = self._io.read_bits_int(1) != 0 - self._debug['embedded_profile']['end'] = self._io.pos() - self._debug['profile_can_be_used_independently_of_embedded_colour_data']['start'] = self._io.pos() - self.profile_can_be_used_independently_of_embedded_colour_data = self._io.read_bits_int(1) != 0 - self._debug['profile_can_be_used_independently_of_embedded_colour_data']['end'] = self._io.pos() - self._debug['other_flags']['start'] = self._io.pos() - self.other_flags = self._io.read_bits_int(30) - self._debug['other_flags']['end'] = self._io.pos() - - - - class XyzNumber(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_bytes(4) - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_bytes(4) - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_bytes(4) - self._debug['z']['end'] = self._io.pos() - - - class DateTimeNumber(KaitaiStruct): - SEQ_FIELDS = ["year", "month", "day", "hour", "minute", "second"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = self._io.read_u2be() - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = self._io.read_u2be() - self._debug['month']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = self._io.read_u2be() - self._debug['day']['end'] = self._io.pos() - self._debug['hour']['start'] = self._io.pos() - self.hour = self._io.read_u2be() - self._debug['hour']['end'] = self._io.pos() - self._debug['minute']['start'] = self._io.pos() - self.minute = self._io.read_u2be() - self._debug['minute']['end'] = self._io.pos() - self._debug['second']['start'] = self._io.pos() - self.second = self._io.read_u2be() - self._debug['second']['end'] = self._io.pos() - - - class Response16Number(KaitaiStruct): - SEQ_FIELDS = ["number", "reserved", "measurement_value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number']['start'] = self._io.pos() - self.number = self._io.read_u4be() - self._debug['number']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['measurement_value']['start'] = self._io.pos() - self.measurement_value = self._root.S15Fixed16Number(self._io, self, self._root) - self.measurement_value._read() - self._debug['measurement_value']['end'] = self._io.pos() - - - class U1Fixed15Number(KaitaiStruct): - SEQ_FIELDS = ["number"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number']['start'] = self._io.pos() - self.number = self._io.read_bytes(2) - self._debug['number']['end'] = self._io.pos() - - - class TagTable(KaitaiStruct): - SEQ_FIELDS = ["tag_count", "tags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_count']['start'] = self._io.pos() - self.tag_count = self._io.read_u4be() - self._debug['tag_count']['end'] = self._io.pos() - self._debug['tags']['start'] = self._io.pos() - self.tags = [None] * (self.tag_count) - for i in range(self.tag_count): - if not 'arr' in self._debug['tags']: - self._debug['tags']['arr'] = [] - self._debug['tags']['arr'].append({'start': self._io.pos()}) - _t_tags = self._root.TagTable.TagDefinition(self._io, self, self._root) - _t_tags._read() - self.tags[i] = _t_tags - self._debug['tags']['arr'][i]['end'] = self._io.pos() - - self._debug['tags']['end'] = self._io.pos() - - class TagDefinition(KaitaiStruct): - - class TagSignatures(Enum): - a_to_b_0 = 1093812784 - a_to_b_1 = 1093812785 - a_to_b_2 = 1093812786 - b_to_a_0 = 1110589744 - b_to_a_1 = 1110589745 - b_to_a_2 = 1110589746 - b_to_d_0 = 1110590512 - b_to_d_1 = 1110590513 - b_to_d_2 = 1110590514 - b_to_d_3 = 1110590515 - d_to_b_0 = 1144144432 - d_to_b_1 = 1144144433 - d_to_b_2 = 1144144434 - d_to_b_3 = 1144144435 - blue_trc = 1649693251 - blue_matrix_column = 1649957210 - calibration_date_time = 1667329140 - chromatic_adaptation = 1667785060 - chromaticity = 1667789421 - colorimetric_intent_image_state = 1667852659 - colorant_table_out = 1668050804 - colorant_order = 1668051567 - colorant_table = 1668051572 - copyright = 1668313716 - profile_description = 1684370275 - device_model_desc = 1684890724 - device_mfg_desc = 1684893284 - green_trc = 1733579331 - green_matrix_column = 1733843290 - gamut = 1734438260 - gray_trc = 1800688195 - luminance = 1819635049 - measurement = 1835360627 - named_color_2 = 1852009522 - preview_0 = 1886545200 - preview_1 = 1886545201 - preview_2 = 1886545202 - profile_sequence = 1886610801 - profile_sequence_identifier = 1886611812 - red_trc = 1918128707 - red_matrix_column = 1918392666 - output_response = 1919251312 - perceptual_rendering_intent_gamut = 1919510320 - saturation_rendering_intent_gamut = 1919510322 - char_target = 1952543335 - technology = 1952801640 - viewing_conditions = 1986618743 - viewing_cond_desc = 1987405156 - media_white_point = 2004119668 - - class TagTypeSignatures(Enum): - xyz_type = 1482250784 - colorant_table_type = 1668051572 - curve_type = 1668641398 - data_type = 1684108385 - date_time_type = 1685350765 - multi_function_a_to_b_table_type = 1832993312 - multi_function_b_to_a_table_type = 1833058592 - measurement_type = 1835360627 - multi_function_table_with_one_byte_precision_type = 1835430961 - multi_function_table_with_two_byte_precision_type = 1835430962 - multi_localized_unicode_type = 1835824483 - multi_process_elements_type = 1836082548 - named_color_2_type = 1852009522 - parametric_curve_type = 1885434465 - profile_sequence_desc_type = 1886610801 - profile_sequence_identifier_type = 1886611812 - response_curve_set_16_type = 1919120178 - s_15_fixed_16_array_type = 1936077618 - signature_type = 1936287520 - text_type = 1952807028 - u_16_fixed_16_array_type = 1969632050 - u_int_8_array_type = 1969827896 - u_int_16_array_type = 1969828150 - u_int_32_array_type = 1969828658 - u_int_64_array_type = 1969829428 - viewing_conditions_type = 1986618743 - - class MultiProcessElementsTypes(Enum): - bacs_element_type = 1648444243 - clut_element_type = 1668052340 - one_dimensional_curves_type = 1668641382 - eacs_element_type = 1698775891 - matrix_element_type = 1835103334 - curve_set_element_table_type = 1835428980 - formula_curve_segments_type = 1885434470 - sampled_curve_segment_type = 1935764838 - SEQ_FIELDS = ["tag_signature", "offset_to_data_element", "size_of_data_element"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_signature']['start'] = self._io.pos() - self.tag_signature = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagSignatures, self._io.read_u4be()) - self._debug['tag_signature']['end'] = self._io.pos() - self._debug['offset_to_data_element']['start'] = self._io.pos() - self.offset_to_data_element = self._io.read_u4be() - self._debug['offset_to_data_element']['end'] = self._io.pos() - self._debug['size_of_data_element']['start'] = self._io.pos() - self.size_of_data_element = self._io.read_u4be() - self._debug['size_of_data_element']['end'] = self._io.pos() - - class BlueMatrixColumnTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.xyz_type: - self.tag_data = self._root.TagTable.TagDefinition.XyzType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DeviceMfgDescTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_localized_unicode_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class NamedColor2Type(KaitaiStruct): - SEQ_FIELDS = ["reserved", "vendor_specific_flag", "count_of_named_colours", "number_of_device_coordinates_for_each_named_colour", "prefix_for_each_colour_name", "prefix_for_each_colour_name_padding", "suffix_for_each_colour_name", "suffix_for_each_colour_name_padding", "named_colour_definitions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['vendor_specific_flag']['start'] = self._io.pos() - self.vendor_specific_flag = self._io.read_u4be() - self._debug['vendor_specific_flag']['end'] = self._io.pos() - self._debug['count_of_named_colours']['start'] = self._io.pos() - self.count_of_named_colours = self._io.read_u4be() - self._debug['count_of_named_colours']['end'] = self._io.pos() - self._debug['number_of_device_coordinates_for_each_named_colour']['start'] = self._io.pos() - self.number_of_device_coordinates_for_each_named_colour = self._io.read_u4be() - self._debug['number_of_device_coordinates_for_each_named_colour']['end'] = self._io.pos() - self._debug['prefix_for_each_colour_name']['start'] = self._io.pos() - self.prefix_for_each_colour_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['prefix_for_each_colour_name']['end'] = self._io.pos() - self._debug['prefix_for_each_colour_name_padding']['start'] = self._io.pos() - self.prefix_for_each_colour_name_padding = [None] * ((32 - len(self.prefix_for_each_colour_name))) - for i in range((32 - len(self.prefix_for_each_colour_name))): - if not 'arr' in self._debug['prefix_for_each_colour_name_padding']: - self._debug['prefix_for_each_colour_name_padding']['arr'] = [] - self._debug['prefix_for_each_colour_name_padding']['arr'].append({'start': self._io.pos()}) - self.prefix_for_each_colour_name_padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['prefix_for_each_colour_name_padding']['arr'][i]['end'] = self._io.pos() - - self._debug['prefix_for_each_colour_name_padding']['end'] = self._io.pos() - self._debug['suffix_for_each_colour_name']['start'] = self._io.pos() - self.suffix_for_each_colour_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['suffix_for_each_colour_name']['end'] = self._io.pos() - self._debug['suffix_for_each_colour_name_padding']['start'] = self._io.pos() - self.suffix_for_each_colour_name_padding = [None] * ((32 - len(self.suffix_for_each_colour_name))) - for i in range((32 - len(self.suffix_for_each_colour_name))): - if not 'arr' in self._debug['suffix_for_each_colour_name_padding']: - self._debug['suffix_for_each_colour_name_padding']['arr'] = [] - self._debug['suffix_for_each_colour_name_padding']['arr'].append({'start': self._io.pos()}) - self.suffix_for_each_colour_name_padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['suffix_for_each_colour_name_padding']['arr'][i]['end'] = self._io.pos() - - self._debug['suffix_for_each_colour_name_padding']['end'] = self._io.pos() - self._debug['named_colour_definitions']['start'] = self._io.pos() - self.named_colour_definitions = [None] * (self.count_of_named_colours) - for i in range(self.count_of_named_colours): - if not 'arr' in self._debug['named_colour_definitions']: - self._debug['named_colour_definitions']['arr'] = [] - self._debug['named_colour_definitions']['arr'].append({'start': self._io.pos()}) - _t_named_colour_definitions = self._root.TagTable.TagDefinition.NamedColor2Type.NamedColourDefinition(self._io, self, self._root) - _t_named_colour_definitions._read() - self.named_colour_definitions[i] = _t_named_colour_definitions - self._debug['named_colour_definitions']['arr'][i]['end'] = self._io.pos() - - self._debug['named_colour_definitions']['end'] = self._io.pos() - - class NamedColourDefinition(KaitaiStruct): - SEQ_FIELDS = ["root_name", "root_name_padding", "pcs_coordinates", "device_coordinates"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['root_name']['start'] = self._io.pos() - self.root_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['root_name']['end'] = self._io.pos() - self._debug['root_name_padding']['start'] = self._io.pos() - self.root_name_padding = [None] * ((32 - len(self.root_name))) - for i in range((32 - len(self.root_name))): - if not 'arr' in self._debug['root_name_padding']: - self._debug['root_name_padding']['arr'] = [] - self._debug['root_name_padding']['arr'].append({'start': self._io.pos()}) - self.root_name_padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['root_name_padding']['arr'][i]['end'] = self._io.pos() - - self._debug['root_name_padding']['end'] = self._io.pos() - self._debug['pcs_coordinates']['start'] = self._io.pos() - self.pcs_coordinates = self._io.read_bytes(6) - self._debug['pcs_coordinates']['end'] = self._io.pos() - if self._parent.number_of_device_coordinates_for_each_named_colour > 0: - self._debug['device_coordinates']['start'] = self._io.pos() - self.device_coordinates = [None] * (self._parent.count_of_named_colours) - for i in range(self._parent.count_of_named_colours): - if not 'arr' in self._debug['device_coordinates']: - self._debug['device_coordinates']['arr'] = [] - self._debug['device_coordinates']['arr'].append({'start': self._io.pos()}) - self.device_coordinates[i] = self._io.read_u2be() - self._debug['device_coordinates']['arr'][i]['end'] = self._io.pos() - - self._debug['device_coordinates']['end'] = self._io.pos() - - - - - class ViewingConditionsTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.viewing_conditions_type: - self.tag_data = self._root.TagTable.TagDefinition.ViewingConditionsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class BlueTrcTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.curve_type: - self.tag_data = self._root.TagTable.TagDefinition.CurveType(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.parametric_curve_type: - self.tag_data = self._root.TagTable.TagDefinition.ParametricCurveType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ResponseCurveSet16Type(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_channels", "count_of_measurement_types", "response_curve_structure_offsets", "response_curve_structures"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_channels']['start'] = self._io.pos() - self.number_of_channels = self._io.read_u2be() - self._debug['number_of_channels']['end'] = self._io.pos() - self._debug['count_of_measurement_types']['start'] = self._io.pos() - self.count_of_measurement_types = self._io.read_u2be() - self._debug['count_of_measurement_types']['end'] = self._io.pos() - self._debug['response_curve_structure_offsets']['start'] = self._io.pos() - self.response_curve_structure_offsets = [None] * (self.count_of_measurement_types) - for i in range(self.count_of_measurement_types): - if not 'arr' in self._debug['response_curve_structure_offsets']: - self._debug['response_curve_structure_offsets']['arr'] = [] - self._debug['response_curve_structure_offsets']['arr'].append({'start': self._io.pos()}) - self.response_curve_structure_offsets[i] = self._io.read_u4be() - self._debug['response_curve_structure_offsets']['arr'][i]['end'] = self._io.pos() - - self._debug['response_curve_structure_offsets']['end'] = self._io.pos() - self._debug['response_curve_structures']['start'] = self._io.pos() - self.response_curve_structures = self._io.read_bytes_full() - self._debug['response_curve_structures']['end'] = self._io.pos() - - - class CurveType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_entries", "curve_values", "curve_value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_entries']['start'] = self._io.pos() - self.number_of_entries = self._io.read_u4be() - self._debug['number_of_entries']['end'] = self._io.pos() - if self.number_of_entries > 1: - self._debug['curve_values']['start'] = self._io.pos() - self.curve_values = [None] * (self.number_of_entries) - for i in range(self.number_of_entries): - if not 'arr' in self._debug['curve_values']: - self._debug['curve_values']['arr'] = [] - self._debug['curve_values']['arr'].append({'start': self._io.pos()}) - self.curve_values[i] = self._io.read_u4be() - self._debug['curve_values']['arr'][i]['end'] = self._io.pos() - - self._debug['curve_values']['end'] = self._io.pos() - - if self.number_of_entries == 1: - self._debug['curve_value']['start'] = self._io.pos() - self.curve_value = self._io.read_u1() - self._debug['curve_value']['end'] = self._io.pos() - - - - class SaturationRenderingIntentGamutTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.signature_type: - self.tag_data = self._root.TagTable.TagDefinition.SignatureType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class XyzType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - _t_values = self._root.XyzNumber(self._io, self, self._root) - _t_values._read() - self.values.append(_t_values) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class Lut8Type(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_input_channels", "number_of_output_channels", "number_of_clut_grid_points", "padding", "encoded_e_parameters", "number_of_input_table_entries", "number_of_output_table_entries", "input_tables", "clut_values", "output_tables"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_input_channels']['start'] = self._io.pos() - self.number_of_input_channels = self._io.read_u1() - self._debug['number_of_input_channels']['end'] = self._io.pos() - self._debug['number_of_output_channels']['start'] = self._io.pos() - self.number_of_output_channels = self._io.read_u1() - self._debug['number_of_output_channels']['end'] = self._io.pos() - self._debug['number_of_clut_grid_points']['start'] = self._io.pos() - self.number_of_clut_grid_points = self._io.read_u1() - self._debug['number_of_clut_grid_points']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['padding']['end'] = self._io.pos() - self._debug['encoded_e_parameters']['start'] = self._io.pos() - self.encoded_e_parameters = [None] * (9) - for i in range(9): - if not 'arr' in self._debug['encoded_e_parameters']: - self._debug['encoded_e_parameters']['arr'] = [] - self._debug['encoded_e_parameters']['arr'].append({'start': self._io.pos()}) - self.encoded_e_parameters[i] = self._io.read_s4be() - self._debug['encoded_e_parameters']['arr'][i]['end'] = self._io.pos() - - self._debug['encoded_e_parameters']['end'] = self._io.pos() - self._debug['number_of_input_table_entries']['start'] = self._io.pos() - self.number_of_input_table_entries = self._io.read_u4be() - self._debug['number_of_input_table_entries']['end'] = self._io.pos() - self._debug['number_of_output_table_entries']['start'] = self._io.pos() - self.number_of_output_table_entries = self._io.read_u4be() - self._debug['number_of_output_table_entries']['end'] = self._io.pos() - self._debug['input_tables']['start'] = self._io.pos() - self.input_tables = self._io.read_bytes((256 * self.number_of_input_channels)) - self._debug['input_tables']['end'] = self._io.pos() - self._debug['clut_values']['start'] = self._io.pos() - self.clut_values = self._io.read_bytes(((self.number_of_clut_grid_points ^ self.number_of_input_channels) * self.number_of_output_channels)) - self._debug['clut_values']['end'] = self._io.pos() - self._debug['output_tables']['start'] = self._io.pos() - self.output_tables = self._io.read_bytes((256 * self.number_of_output_channels)) - self._debug['output_tables']['end'] = self._io.pos() - - - class BToA2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class LutAToBType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_input_channels", "number_of_output_channels", "padding", "offset_to_first_b_curve", "offset_to_matrix", "offset_to_first_m_curve", "offset_to_clut", "offset_to_first_a_curve", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_input_channels']['start'] = self._io.pos() - self.number_of_input_channels = self._io.read_u1() - self._debug['number_of_input_channels']['end'] = self._io.pos() - self._debug['number_of_output_channels']['start'] = self._io.pos() - self.number_of_output_channels = self._io.read_u1() - self._debug['number_of_output_channels']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['padding']['end'] = self._io.pos() - self._debug['offset_to_first_b_curve']['start'] = self._io.pos() - self.offset_to_first_b_curve = self._io.read_u4be() - self._debug['offset_to_first_b_curve']['end'] = self._io.pos() - self._debug['offset_to_matrix']['start'] = self._io.pos() - self.offset_to_matrix = self._io.read_u4be() - self._debug['offset_to_matrix']['end'] = self._io.pos() - self._debug['offset_to_first_m_curve']['start'] = self._io.pos() - self.offset_to_first_m_curve = self._io.read_u4be() - self._debug['offset_to_first_m_curve']['end'] = self._io.pos() - self._debug['offset_to_clut']['start'] = self._io.pos() - self.offset_to_clut = self._io.read_u4be() - self._debug['offset_to_clut']['end'] = self._io.pos() - self._debug['offset_to_first_a_curve']['start'] = self._io.pos() - self.offset_to_first_a_curve = self._io.read_u4be() - self._debug['offset_to_first_a_curve']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class BToA0Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class MediaWhitePointTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.xyz_type: - self.tag_data = self._root.TagTable.TagDefinition.XyzType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class Lut16Type(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_input_channels", "number_of_output_channels", "number_of_clut_grid_points", "padding", "encoded_e_parameters", "number_of_input_table_entries", "number_of_output_table_entries", "input_tables", "clut_values", "output_tables"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_input_channels']['start'] = self._io.pos() - self.number_of_input_channels = self._io.read_u1() - self._debug['number_of_input_channels']['end'] = self._io.pos() - self._debug['number_of_output_channels']['start'] = self._io.pos() - self.number_of_output_channels = self._io.read_u1() - self._debug['number_of_output_channels']['end'] = self._io.pos() - self._debug['number_of_clut_grid_points']['start'] = self._io.pos() - self.number_of_clut_grid_points = self._io.read_u1() - self._debug['number_of_clut_grid_points']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['padding']['end'] = self._io.pos() - self._debug['encoded_e_parameters']['start'] = self._io.pos() - self.encoded_e_parameters = [None] * (9) - for i in range(9): - if not 'arr' in self._debug['encoded_e_parameters']: - self._debug['encoded_e_parameters']['arr'] = [] - self._debug['encoded_e_parameters']['arr'].append({'start': self._io.pos()}) - self.encoded_e_parameters[i] = self._io.read_s4be() - self._debug['encoded_e_parameters']['arr'][i]['end'] = self._io.pos() - - self._debug['encoded_e_parameters']['end'] = self._io.pos() - self._debug['number_of_input_table_entries']['start'] = self._io.pos() - self.number_of_input_table_entries = self._io.read_u4be() - self._debug['number_of_input_table_entries']['end'] = self._io.pos() - self._debug['number_of_output_table_entries']['start'] = self._io.pos() - self.number_of_output_table_entries = self._io.read_u4be() - self._debug['number_of_output_table_entries']['end'] = self._io.pos() - self._debug['input_tables']['start'] = self._io.pos() - self.input_tables = self._io.read_bytes(((2 * self.number_of_input_channels) * self.number_of_input_table_entries)) - self._debug['input_tables']['end'] = self._io.pos() - self._debug['clut_values']['start'] = self._io.pos() - self.clut_values = self._io.read_bytes(((2 * (self.number_of_clut_grid_points ^ self.number_of_input_channels)) * self.number_of_output_channels)) - self._debug['clut_values']['end'] = self._io.pos() - self._debug['output_tables']['start'] = self._io.pos() - self.output_tables = self._io.read_bytes(((2 * self.number_of_output_channels) * self.number_of_output_table_entries)) - self._debug['output_tables']['end'] = self._io.pos() - - - class PerceptualRenderingIntentGamutTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.signature_type: - self.tag_data = self._root.TagTable.TagDefinition.SignatureType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class U16Fixed16ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - _t_values = self._root.U16Fixed16Number(self._io, self, self._root) - _t_values._read() - self.values.append(_t_values) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class ColorantTableOutTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.colorant_table_type: - self.tag_data = self._root.TagTable.TagDefinition.ColorantTableType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class MeasurementTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.measurement_type: - self.tag_data = self._root.TagTable.TagDefinition.MeasurementType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ProfileSequenceTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.profile_sequence_desc_type: - self.tag_data = self._root.TagTable.TagDefinition.ProfileSequenceDescType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class TechnologyTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.signature_type: - self.tag_data = self._root.TagTable.TagDefinition.SignatureType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class AToB0Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_a_to_b_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutAToBType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DToB0Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class OutputResponseTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.response_curve_set_16_type: - self.tag_data = self._root.TagTable.TagDefinition.ResponseCurveSet16Type(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class GreenMatrixColumnTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.xyz_type: - self.tag_data = self._root.TagTable.TagDefinition.XyzType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ProfileDescriptionTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_localized_unicode_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class Preview1Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class RedTrcTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.curve_type: - self.tag_data = self._root.TagTable.TagDefinition.CurveType(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.parametric_curve_type: - self.tag_data = self._root.TagTable.TagDefinition.ParametricCurveType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class BToD0Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DToB1Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class BToA1Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ParametricCurveType(KaitaiStruct): - - class ParametricCurveTypeFunctions(Enum): - y_equals_x_to_power_of_g = 0 - cie_122_1996 = 1 - iec_61966_3 = 2 - iec_61966_2_1 = 3 - y_equals_ob_ax_plus_b_cb_to_power_of_g_plus_c = 4 - SEQ_FIELDS = ["reserved", "function_type", "reserved_2", "parameters"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['function_type']['start'] = self._io.pos() - self.function_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions, self._io.read_u2be()) - self._debug['function_type']['end'] = self._io.pos() - self._debug['reserved_2']['start'] = self._io.pos() - self.reserved_2 = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['reserved_2']['end'] = self._io.pos() - self._debug['parameters']['start'] = self._io.pos() - _on = self.function_type - if _on == self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions.cie_122_1996: - self.parameters = self._root.TagTable.TagDefinition.ParametricCurveType.ParamsCie1221996(self._io, self, self._root) - self.parameters._read() - elif _on == self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions.iec_61966_3: - self.parameters = self._root.TagTable.TagDefinition.ParametricCurveType.ParamsIec619663(self._io, self, self._root) - self.parameters._read() - elif _on == self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions.iec_61966_2_1: - self.parameters = self._root.TagTable.TagDefinition.ParametricCurveType.ParamsIec6196621(self._io, self, self._root) - self.parameters._read() - elif _on == self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions.y_equals_ob_ax_plus_b_cb_to_power_of_g_plus_c: - self.parameters = self._root.TagTable.TagDefinition.ParametricCurveType.ParamsYEqualsObAxPlusBCbToPowerOfGPlusC(self._io, self, self._root) - self.parameters._read() - elif _on == self._root.TagTable.TagDefinition.ParametricCurveType.ParametricCurveTypeFunctions.y_equals_x_to_power_of_g: - self.parameters = self._root.TagTable.TagDefinition.ParametricCurveType.ParamsYEqualsXToPowerOfG(self._io, self, self._root) - self.parameters._read() - self._debug['parameters']['end'] = self._io.pos() - - class ParamsIec619663(KaitaiStruct): - SEQ_FIELDS = ["g", "a", "b", "c"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_s4be() - self._debug['g']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_s4be() - self._debug['a']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_s4be() - self._debug['b']['end'] = self._io.pos() - self._debug['c']['start'] = self._io.pos() - self.c = self._io.read_s4be() - self._debug['c']['end'] = self._io.pos() - - - class ParamsIec6196621(KaitaiStruct): - SEQ_FIELDS = ["g", "a", "b", "c", "d"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_s4be() - self._debug['g']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_s4be() - self._debug['a']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_s4be() - self._debug['b']['end'] = self._io.pos() - self._debug['c']['start'] = self._io.pos() - self.c = self._io.read_s4be() - self._debug['c']['end'] = self._io.pos() - self._debug['d']['start'] = self._io.pos() - self.d = self._io.read_s4be() - self._debug['d']['end'] = self._io.pos() - - - class ParamsYEqualsXToPowerOfG(KaitaiStruct): - SEQ_FIELDS = ["g"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_s4be() - self._debug['g']['end'] = self._io.pos() - - - class ParamsYEqualsObAxPlusBCbToPowerOfGPlusC(KaitaiStruct): - SEQ_FIELDS = ["g", "a", "b", "c", "d", "e", "f"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_s4be() - self._debug['g']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_s4be() - self._debug['a']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_s4be() - self._debug['b']['end'] = self._io.pos() - self._debug['c']['start'] = self._io.pos() - self.c = self._io.read_s4be() - self._debug['c']['end'] = self._io.pos() - self._debug['d']['start'] = self._io.pos() - self.d = self._io.read_s4be() - self._debug['d']['end'] = self._io.pos() - self._debug['e']['start'] = self._io.pos() - self.e = self._io.read_s4be() - self._debug['e']['end'] = self._io.pos() - self._debug['f']['start'] = self._io.pos() - self.f = self._io.read_s4be() - self._debug['f']['end'] = self._io.pos() - - - class ParamsCie1221996(KaitaiStruct): - SEQ_FIELDS = ["g", "a", "b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_s4be() - self._debug['g']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_s4be() - self._debug['a']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_s4be() - self._debug['b']['end'] = self._io.pos() - - - - class ChromaticityTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.chromaticity_type: - self.tag_data = self._root.TagTable.TagDefinition.ChromaticityType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ChromaticAdaptationTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.s_15_fixed_16_array_type: - self.tag_data = self._root.TagTable.TagDefinition.S15Fixed16ArrayType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class MeasurementType(KaitaiStruct): - - class StandardObserverEncodings(Enum): - unknown = 0 - cie_1931_standard_colorimetric_observer = 1 - cie_1964_standard_colorimetric_observer = 2 - - class MeasurementGeometryEncodings(Enum): - unknown = 0 - zero_degrees_to_45_degrees_or_45_degrees_to_zero_degrees = 1 - zero_degrees_to_d_degrees_or_d_degrees_to_zero_degrees = 2 - - class MeasurementFlareEncodings(Enum): - zero_percent = 0 - one_hundred_percent = 65536 - SEQ_FIELDS = ["reserved", "standard_observer_encoding", "nciexyz_tristimulus_values_for_measurement_backing", "measurement_geometry_encoding", "measurement_flare_encoding", "standard_illuminant_encoding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['standard_observer_encoding']['start'] = self._io.pos() - self.standard_observer_encoding = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.MeasurementType.StandardObserverEncodings, self._io.read_u4be()) - self._debug['standard_observer_encoding']['end'] = self._io.pos() - self._debug['nciexyz_tristimulus_values_for_measurement_backing']['start'] = self._io.pos() - self.nciexyz_tristimulus_values_for_measurement_backing = self._root.XyzNumber(self._io, self, self._root) - self.nciexyz_tristimulus_values_for_measurement_backing._read() - self._debug['nciexyz_tristimulus_values_for_measurement_backing']['end'] = self._io.pos() - self._debug['measurement_geometry_encoding']['start'] = self._io.pos() - self.measurement_geometry_encoding = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.MeasurementType.MeasurementGeometryEncodings, self._io.read_u4be()) - self._debug['measurement_geometry_encoding']['end'] = self._io.pos() - self._debug['measurement_flare_encoding']['start'] = self._io.pos() - self.measurement_flare_encoding = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.MeasurementType.MeasurementFlareEncodings, self._io.read_u4be()) - self._debug['measurement_flare_encoding']['end'] = self._io.pos() - self._debug['standard_illuminant_encoding']['start'] = self._io.pos() - self.standard_illuminant_encoding = self._root.StandardIlluminantEncoding(self._io, self, self._root) - self.standard_illuminant_encoding._read() - self._debug['standard_illuminant_encoding']['end'] = self._io.pos() - - - class TextType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = (KaitaiStream.bytes_terminate(self._io.read_bytes_full(), 0, False)).decode(u"ASCII") - self._debug['value']['end'] = self._io.pos() - - - class ProfileSequenceIdentifierType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_structures", "positions_table", "profile_identifiers"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_structures']['start'] = self._io.pos() - self.number_of_structures = self._io.read_u4be() - self._debug['number_of_structures']['end'] = self._io.pos() - self._debug['positions_table']['start'] = self._io.pos() - self.positions_table = [None] * (self.number_of_structures) - for i in range(self.number_of_structures): - if not 'arr' in self._debug['positions_table']: - self._debug['positions_table']['arr'] = [] - self._debug['positions_table']['arr'].append({'start': self._io.pos()}) - _t_positions_table = self._root.PositionNumber(self._io, self, self._root) - _t_positions_table._read() - self.positions_table[i] = _t_positions_table - self._debug['positions_table']['arr'][i]['end'] = self._io.pos() - - self._debug['positions_table']['end'] = self._io.pos() - self._debug['profile_identifiers']['start'] = self._io.pos() - self.profile_identifiers = [None] * (self.number_of_structures) - for i in range(self.number_of_structures): - if not 'arr' in self._debug['profile_identifiers']: - self._debug['profile_identifiers']['arr'] = [] - self._debug['profile_identifiers']['arr'].append({'start': self._io.pos()}) - _t_profile_identifiers = self._root.TagTable.TagDefinition.ProfileSequenceIdentifierType.ProfileIdentifier(self._io, self, self._root) - _t_profile_identifiers._read() - self.profile_identifiers[i] = _t_profile_identifiers - self._debug['profile_identifiers']['arr'][i]['end'] = self._io.pos() - - self._debug['profile_identifiers']['end'] = self._io.pos() - - class ProfileIdentifier(KaitaiStruct): - SEQ_FIELDS = ["profile_id", "profile_description"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['profile_id']['start'] = self._io.pos() - self.profile_id = self._io.read_bytes(16) - self._debug['profile_id']['end'] = self._io.pos() - self._debug['profile_description']['start'] = self._io.pos() - self.profile_description = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.profile_description._read() - self._debug['profile_description']['end'] = self._io.pos() - - - - class ColorantTableType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "count_of_colorants", "colorants"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['count_of_colorants']['start'] = self._io.pos() - self.count_of_colorants = self._io.read_u4be() - self._debug['count_of_colorants']['end'] = self._io.pos() - self._debug['colorants']['start'] = self._io.pos() - self.colorants = [None] * (self.count_of_colorants) - for i in range(self.count_of_colorants): - if not 'arr' in self._debug['colorants']: - self._debug['colorants']['arr'] = [] - self._debug['colorants']['arr'].append({'start': self._io.pos()}) - _t_colorants = self._root.TagTable.TagDefinition.ColorantTableType.Colorant(self._io, self, self._root) - _t_colorants._read() - self.colorants[i] = _t_colorants - self._debug['colorants']['arr'][i]['end'] = self._io.pos() - - self._debug['colorants']['end'] = self._io.pos() - - class Colorant(KaitaiStruct): - SEQ_FIELDS = ["name", "padding", "pcs_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = [None] * ((32 - len(self.name))) - for i in range((32 - len(self.name))): - if not 'arr' in self._debug['padding']: - self._debug['padding']['arr'] = [] - self._debug['padding']['arr'].append({'start': self._io.pos()}) - self.padding = self._io.ensure_fixed_contents(b"\x00") - self._debug['padding']['arr'][i]['end'] = self._io.pos() - - self._debug['padding']['end'] = self._io.pos() - self._debug['pcs_values']['start'] = self._io.pos() - self.pcs_values = self._io.read_bytes(6) - self._debug['pcs_values']['end'] = self._io.pos() - - - - class SignatureType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "signature"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['signature']['start'] = self._io.pos() - self.signature = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['signature']['end'] = self._io.pos() - - - class CopyrightTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_localized_unicode_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class Preview0Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_a_to_b_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutAToBType(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DateTimeType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "date_and_time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['date_and_time']['start'] = self._io.pos() - self.date_and_time = self._root.DateTimeNumber(self._io, self, self._root) - self.date_and_time._read() - self._debug['date_and_time']['end'] = self._io.pos() - - - class DToB3Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class Preview2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DeviceModelDescTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_localized_unicode_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class MultiProcessElementsType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_input_channels", "number_of_output_channels", "number_of_processing_elements", "process_element_positions_table", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_input_channels']['start'] = self._io.pos() - self.number_of_input_channels = self._io.read_u2be() - self._debug['number_of_input_channels']['end'] = self._io.pos() - self._debug['number_of_output_channels']['start'] = self._io.pos() - self.number_of_output_channels = self._io.read_u2be() - self._debug['number_of_output_channels']['end'] = self._io.pos() - self._debug['number_of_processing_elements']['start'] = self._io.pos() - self.number_of_processing_elements = self._io.read_u4be() - self._debug['number_of_processing_elements']['end'] = self._io.pos() - self._debug['process_element_positions_table']['start'] = self._io.pos() - self.process_element_positions_table = [None] * (self.number_of_processing_elements) - for i in range(self.number_of_processing_elements): - if not 'arr' in self._debug['process_element_positions_table']: - self._debug['process_element_positions_table']['arr'] = [] - self._debug['process_element_positions_table']['arr'].append({'start': self._io.pos()}) - _t_process_element_positions_table = self._root.PositionNumber(self._io, self, self._root) - _t_process_element_positions_table._read() - self.process_element_positions_table[i] = _t_process_element_positions_table - self._debug['process_element_positions_table']['arr'][i]['end'] = self._io.pos() - - self._debug['process_element_positions_table']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class UInt16ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - self.values.append(self._io.read_u2be()) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class ColorantOrderTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.colorant_order_type: - self.tag_data = self._root.TagTable.TagDefinition.ColorantOrderType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class DataType(KaitaiStruct): - - class DataTypes(Enum): - ascii_data = 0 - binary_data = 1 - SEQ_FIELDS = ["data_flag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data_flag']['start'] = self._io.pos() - self.data_flag = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.DataType.DataTypes, self._io.read_u4be()) - self._debug['data_flag']['end'] = self._io.pos() - - - class ChromaticityType(KaitaiStruct): - - class ColorantAndPhosphorEncodings(Enum): - unknown = 0 - itu_r_bt_709_2 = 1 - smpte_rp145 = 2 - ebu_tech_3213_e = 3 - p22 = 4 - SEQ_FIELDS = ["reserved", "number_of_device_channels", "colorant_and_phosphor_encoding", "ciexy_coordinates_per_channel"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_device_channels']['start'] = self._io.pos() - self.number_of_device_channels = self._io.read_u2be() - self._debug['number_of_device_channels']['end'] = self._io.pos() - self._debug['colorant_and_phosphor_encoding']['start'] = self._io.pos() - self.colorant_and_phosphor_encoding = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.ChromaticityType.ColorantAndPhosphorEncodings, self._io.read_u2be()) - self._debug['colorant_and_phosphor_encoding']['end'] = self._io.pos() - self._debug['ciexy_coordinates_per_channel']['start'] = self._io.pos() - self.ciexy_coordinates_per_channel = [None] * (self.number_of_device_channels) - for i in range(self.number_of_device_channels): - if not 'arr' in self._debug['ciexy_coordinates_per_channel']: - self._debug['ciexy_coordinates_per_channel']['arr'] = [] - self._debug['ciexy_coordinates_per_channel']['arr'].append({'start': self._io.pos()}) - _t_ciexy_coordinates_per_channel = self._root.TagTable.TagDefinition.ChromaticityType.CiexyCoordinateValues(self._io, self, self._root) - _t_ciexy_coordinates_per_channel._read() - self.ciexy_coordinates_per_channel[i] = _t_ciexy_coordinates_per_channel - self._debug['ciexy_coordinates_per_channel']['arr'][i]['end'] = self._io.pos() - - self._debug['ciexy_coordinates_per_channel']['end'] = self._io.pos() - - class CiexyCoordinateValues(KaitaiStruct): - SEQ_FIELDS = ["x_coordinate", "y_coordinate"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x_coordinate']['start'] = self._io.pos() - self.x_coordinate = self._io.read_u2be() - self._debug['x_coordinate']['end'] = self._io.pos() - self._debug['y_coordinate']['start'] = self._io.pos() - self.y_coordinate = self._io.read_u2be() - self._debug['y_coordinate']['end'] = self._io.pos() - - - - class LuminanceTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.xyz_type: - self.tag_data = self._root.TagTable.TagDefinition.XyzType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class S15Fixed16ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - _t_values = self._root.S15Fixed16Number(self._io, self, self._root) - _t_values._read() - self.values.append(_t_values) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class MultiLocalizedUnicodeType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_records", "record_size", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_records']['start'] = self._io.pos() - self.number_of_records = self._io.read_u4be() - self._debug['number_of_records']['end'] = self._io.pos() - self._debug['record_size']['start'] = self._io.pos() - self.record_size = self._io.read_u4be() - self._debug['record_size']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [None] * (self.number_of_records) - for i in range(self.number_of_records): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType.Record(self._io, self, self._root) - _t_records._read() - self.records[i] = _t_records - self._debug['records']['arr'][i]['end'] = self._io.pos() - - self._debug['records']['end'] = self._io.pos() - - class Record(KaitaiStruct): - SEQ_FIELDS = ["language_code", "country_code", "string_length", "string_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['language_code']['start'] = self._io.pos() - self.language_code = self._io.read_u2be() - self._debug['language_code']['end'] = self._io.pos() - self._debug['country_code']['start'] = self._io.pos() - self.country_code = self._io.read_u2be() - self._debug['country_code']['end'] = self._io.pos() - self._debug['string_length']['start'] = self._io.pos() - self.string_length = self._io.read_u4be() - self._debug['string_length']['end'] = self._io.pos() - self._debug['string_offset']['start'] = self._io.pos() - self.string_offset = self._io.read_u4be() - self._debug['string_offset']['end'] = self._io.pos() - - @property - def string_data(self): - if hasattr(self, '_m_string_data'): - return self._m_string_data if hasattr(self, '_m_string_data') else None - - _pos = self._io.pos() - self._io.seek(self.string_offset) - self._debug['_m_string_data']['start'] = self._io.pos() - self._m_string_data = (self._io.read_bytes(self.string_length)).decode(u"UTF-16BE") - self._debug['_m_string_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_string_data if hasattr(self, '_m_string_data') else None - - - - class AToB2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_a_to_b_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutAToBType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class AToB1Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_a_to_b_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutAToBType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ColorimetricIntentImageStateTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.signature_type: - self.tag_data = self._root.TagTable.TagDefinition.SignatureType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class CharTargetTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.text_type: - self.tag_data = self._root.TagTable.TagDefinition.TextType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ColorantTableTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.colorant_table_type: - self.tag_data = self._root.TagTable.TagDefinition.ColorantTableType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class CalibrationDateTimeTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.date_time_type: - self.tag_data = self._root.TagTable.TagDefinition.DateTimeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class NamedColor2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.named_color_2_type: - self.tag_data = self._root.TagTable.TagDefinition.NamedColor2Type(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ViewingCondDescTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_localized_unicode_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiLocalizedUnicodeType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class BToD3Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ProfileSequenceDescType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_description_structures", "profile_descriptions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_description_structures']['start'] = self._io.pos() - self.number_of_description_structures = self._io.read_u4be() - self._debug['number_of_description_structures']['end'] = self._io.pos() - self._debug['profile_descriptions']['start'] = self._io.pos() - self.profile_descriptions = [None] * (self.number_of_description_structures) - for i in range(self.number_of_description_structures): - if not 'arr' in self._debug['profile_descriptions']: - self._debug['profile_descriptions']['arr'] = [] - self._debug['profile_descriptions']['arr'].append({'start': self._io.pos()}) - _t_profile_descriptions = self._root.TagTable.TagDefinition.ProfileSequenceDescType.ProfileDescription(self._io, self, self._root) - _t_profile_descriptions._read() - self.profile_descriptions[i] = _t_profile_descriptions - self._debug['profile_descriptions']['arr'][i]['end'] = self._io.pos() - - self._debug['profile_descriptions']['end'] = self._io.pos() - - class ProfileDescription(KaitaiStruct): - SEQ_FIELDS = ["device_manufacturer", "device_model", "device_attributes", "device_technology", "description_of_device_manufacturer", "description_of_device_model"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['device_manufacturer']['start'] = self._io.pos() - self.device_manufacturer = self._root.DeviceManufacturer(self._io, self, self._root) - self.device_manufacturer._read() - self._debug['device_manufacturer']['end'] = self._io.pos() - self._debug['device_model']['start'] = self._io.pos() - self.device_model = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['device_model']['end'] = self._io.pos() - self._debug['device_attributes']['start'] = self._io.pos() - self.device_attributes = self._root.DeviceAttributes(self._io, self, self._root) - self.device_attributes._read() - self._debug['device_attributes']['end'] = self._io.pos() - self._debug['device_technology']['start'] = self._io.pos() - self.device_technology = self._root.TagTable.TagDefinition.TechnologyTag(self._io, self, self._root) - self.device_technology._read() - self._debug['device_technology']['end'] = self._io.pos() - self._debug['description_of_device_manufacturer']['start'] = self._io.pos() - self.description_of_device_manufacturer = self._root.TagTable.TagDefinition.DeviceMfgDescTag(self._io, self, self._root) - self.description_of_device_manufacturer._read() - self._debug['description_of_device_manufacturer']['end'] = self._io.pos() - self._debug['description_of_device_model']['start'] = self._io.pos() - self.description_of_device_model = self._root.TagTable.TagDefinition.DeviceModelDescTag(self._io, self, self._root) - self.description_of_device_model._read() - self._debug['description_of_device_model']['end'] = self._io.pos() - - - - class ProfileSequenceIdentifierTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.profile_sequence_identifier_type: - self.tag_data = self._root.TagTable.TagDefinition.ProfileSequenceIdentifierType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class BToD1Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ColorantOrderType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "count_of_colorants", "numbers_of_colorants_in_order_of_printing"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['count_of_colorants']['start'] = self._io.pos() - self.count_of_colorants = self._io.read_u4be() - self._debug['count_of_colorants']['end'] = self._io.pos() - self._debug['numbers_of_colorants_in_order_of_printing']['start'] = self._io.pos() - self.numbers_of_colorants_in_order_of_printing = [None] * (self.count_of_colorants) - for i in range(self.count_of_colorants): - if not 'arr' in self._debug['numbers_of_colorants_in_order_of_printing']: - self._debug['numbers_of_colorants_in_order_of_printing']['arr'] = [] - self._debug['numbers_of_colorants_in_order_of_printing']['arr'].append({'start': self._io.pos()}) - self.numbers_of_colorants_in_order_of_printing[i] = self._io.read_u1() - self._debug['numbers_of_colorants_in_order_of_printing']['arr'][i]['end'] = self._io.pos() - - self._debug['numbers_of_colorants_in_order_of_printing']['end'] = self._io.pos() - - - class DToB2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class GrayTrcTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.curve_type: - self.tag_data = self._root.TagTable.TagDefinition.CurveType(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.parametric_curve_type: - self.tag_data = self._root.TagTable.TagDefinition.ParametricCurveType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class ViewingConditionsType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "un_normalized_ciexyz_values_for_illuminant", "un_normalized_ciexyz_values_for_surround", "illuminant_type"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['un_normalized_ciexyz_values_for_illuminant']['start'] = self._io.pos() - self.un_normalized_ciexyz_values_for_illuminant = self._root.XyzNumber(self._io, self, self._root) - self.un_normalized_ciexyz_values_for_illuminant._read() - self._debug['un_normalized_ciexyz_values_for_illuminant']['end'] = self._io.pos() - self._debug['un_normalized_ciexyz_values_for_surround']['start'] = self._io.pos() - self.un_normalized_ciexyz_values_for_surround = self._root.XyzNumber(self._io, self, self._root) - self.un_normalized_ciexyz_values_for_surround._read() - self._debug['un_normalized_ciexyz_values_for_surround']['end'] = self._io.pos() - self._debug['illuminant_type']['start'] = self._io.pos() - self.illuminant_type = self._root.StandardIlluminantEncoding(self._io, self, self._root) - self.illuminant_type._read() - self._debug['illuminant_type']['end'] = self._io.pos() - - - class LutBToAType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "number_of_input_channels", "number_of_output_channels", "padding", "offset_to_first_b_curve", "offset_to_matrix", "offset_to_first_m_curve", "offset_to_clut", "offset_to_first_a_curve", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['number_of_input_channels']['start'] = self._io.pos() - self.number_of_input_channels = self._io.read_u1() - self._debug['number_of_input_channels']['end'] = self._io.pos() - self._debug['number_of_output_channels']['start'] = self._io.pos() - self.number_of_output_channels = self._io.read_u1() - self._debug['number_of_output_channels']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['padding']['end'] = self._io.pos() - self._debug['offset_to_first_b_curve']['start'] = self._io.pos() - self.offset_to_first_b_curve = self._io.read_u4be() - self._debug['offset_to_first_b_curve']['end'] = self._io.pos() - self._debug['offset_to_matrix']['start'] = self._io.pos() - self.offset_to_matrix = self._io.read_u4be() - self._debug['offset_to_matrix']['end'] = self._io.pos() - self._debug['offset_to_first_m_curve']['start'] = self._io.pos() - self.offset_to_first_m_curve = self._io.read_u4be() - self._debug['offset_to_first_m_curve']['end'] = self._io.pos() - self._debug['offset_to_clut']['start'] = self._io.pos() - self.offset_to_clut = self._io.read_u4be() - self._debug['offset_to_clut']['end'] = self._io.pos() - self._debug['offset_to_first_a_curve']['start'] = self._io.pos() - self.offset_to_first_a_curve = self._io.read_u4be() - self._debug['offset_to_first_a_curve']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class GreenTrcTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.curve_type: - self.tag_data = self._root.TagTable.TagDefinition.CurveType(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.parametric_curve_type: - self.tag_data = self._root.TagTable.TagDefinition.ParametricCurveType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class UInt32ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - self.values.append(self._io.read_u4be()) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class GamutTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_one_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut8Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_table_with_two_byte_precision_type: - self.tag_data = self._root.TagTable.TagDefinition.Lut16Type(self._io, self, self._root) - self.tag_data._read() - elif _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_function_b_to_a_table_type: - self.tag_data = self._root.TagTable.TagDefinition.LutBToAType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class UInt8ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - self.values.append(self._io.read_u1()) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class RedMatrixColumnTag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.xyz_type: - self.tag_data = self._root.TagTable.TagDefinition.XyzType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - class UInt64ArrayType(KaitaiStruct): - SEQ_FIELDS = ["reserved", "values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - self.values.append(self._io.read_u8be()) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - - class BToD2Tag(KaitaiStruct): - SEQ_FIELDS = ["tag_type", "tag_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_type']['start'] = self._io.pos() - self.tag_type = KaitaiStream.resolve_enum(self._root.TagTable.TagDefinition.TagTypeSignatures, self._io.read_u4be()) - self._debug['tag_type']['end'] = self._io.pos() - self._debug['tag_data']['start'] = self._io.pos() - _on = self.tag_type - if _on == self._root.TagTable.TagDefinition.TagTypeSignatures.multi_process_elements_type: - self.tag_data = self._root.TagTable.TagDefinition.MultiProcessElementsType(self._io, self, self._root) - self.tag_data._read() - self._debug['tag_data']['end'] = self._io.pos() - - - @property - def tag_data_element(self): - if hasattr(self, '_m_tag_data_element'): - return self._m_tag_data_element if hasattr(self, '_m_tag_data_element') else None - - _pos = self._io.pos() - self._io.seek(self.offset_to_data_element) - self._debug['_m_tag_data_element']['start'] = self._io.pos() - _on = self.tag_signature - if _on == self._root.TagTable.TagDefinition.TagSignatures.colorant_order: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ColorantOrderTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_a_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToA2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.media_white_point: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.MediaWhitePointTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_d_3: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToD3Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.colorimetric_intent_image_state: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ColorimetricIntentImageStateTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.viewing_cond_desc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ViewingCondDescTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.preview_1: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.Preview1Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.device_model_desc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DeviceModelDescTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.chromaticity: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ChromaticityTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.preview_0: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.Preview0Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.d_to_b_1: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DToB1Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.saturation_rendering_intent_gamut: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.SaturationRenderingIntentGamutTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_a_0: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToA0Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.green_matrix_column: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.GreenMatrixColumnTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.copyright: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.CopyrightTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.blue_matrix_column: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BlueMatrixColumnTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.chromatic_adaptation: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ChromaticAdaptationTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.a_to_b_1: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.AToB1Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.output_response: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.OutputResponseTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.profile_sequence: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ProfileSequenceTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.char_target: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.CharTargetTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.red_trc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.RedTrcTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.gamut: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.GamutTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.device_mfg_desc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DeviceMfgDescTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.measurement: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.MeasurementTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.green_trc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.GreenTrcTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.d_to_b_3: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DToB3Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.colorant_table: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ColorantTableTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.d_to_b_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DToB2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.profile_description: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ProfileDescriptionTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.profile_sequence_identifier: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ProfileSequenceIdentifierTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.gray_trc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.GrayTrcTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.perceptual_rendering_intent_gamut: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.PerceptualRenderingIntentGamutTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.blue_trc: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BlueTrcTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.d_to_b_0: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.DToB0Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.a_to_b_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.AToB2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.calibration_date_time: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.CalibrationDateTimeTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.colorant_table_out: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ColorantTableOutTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.red_matrix_column: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.RedMatrixColumnTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.preview_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.Preview2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.a_to_b_0: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.AToB0Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.luminance: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.LuminanceTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.named_color_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.NamedColor2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_d_2: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToD2Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_d_0: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToD0Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_a_1: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToA1Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.b_to_d_1: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.BToD1Tag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.viewing_conditions: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.ViewingConditionsTag(io, self, self._root) - self._m_tag_data_element._read() - elif _on == self._root.TagTable.TagDefinition.TagSignatures.technology: - self._raw__m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - io = KaitaiStream(BytesIO(self._raw__m_tag_data_element)) - self._m_tag_data_element = self._root.TagTable.TagDefinition.TechnologyTag(io, self, self._root) - self._m_tag_data_element._read() - else: - self._m_tag_data_element = self._io.read_bytes(self.size_of_data_element) - self._debug['_m_tag_data_element']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_tag_data_element if hasattr(self, '_m_tag_data_element') else None - - - - class DeviceAttributes(KaitaiStruct): - - class DeviceAttributesReflectiveOrTransparency(Enum): - reflective = 0 - transparency = 1 - - class DeviceAttributesGlossyOrMatte(Enum): - glossy = 0 - matte = 1 - - class DeviceAttributesPositiveOrNegativeMediaPolarity(Enum): - positive_media_polarity = 0 - negative_media_polarity = 1 - - class DeviceAttributesColourOrBlackAndWhiteMedia(Enum): - colour_media = 0 - black_and_white_media = 1 - SEQ_FIELDS = ["reflective_or_transparency", "glossy_or_matte", "positive_or_negative_media_polarity", "colour_or_black_and_white_media", "reserved", "vendor_specific"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reflective_or_transparency']['start'] = self._io.pos() - self.reflective_or_transparency = KaitaiStream.resolve_enum(self._root.DeviceAttributes.DeviceAttributesReflectiveOrTransparency, self._io.read_bits_int(1)) - self._debug['reflective_or_transparency']['end'] = self._io.pos() - self._debug['glossy_or_matte']['start'] = self._io.pos() - self.glossy_or_matte = KaitaiStream.resolve_enum(self._root.DeviceAttributes.DeviceAttributesGlossyOrMatte, self._io.read_bits_int(1)) - self._debug['glossy_or_matte']['end'] = self._io.pos() - self._debug['positive_or_negative_media_polarity']['start'] = self._io.pos() - self.positive_or_negative_media_polarity = KaitaiStream.resolve_enum(self._root.DeviceAttributes.DeviceAttributesPositiveOrNegativeMediaPolarity, self._io.read_bits_int(1)) - self._debug['positive_or_negative_media_polarity']['end'] = self._io.pos() - self._debug['colour_or_black_and_white_media']['start'] = self._io.pos() - self.colour_or_black_and_white_media = KaitaiStream.resolve_enum(self._root.DeviceAttributes.DeviceAttributesColourOrBlackAndWhiteMedia, self._io.read_bits_int(1)) - self._debug['colour_or_black_and_white_media']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(28) - self._debug['reserved']['end'] = self._io.pos() - self._debug['vendor_specific']['start'] = self._io.pos() - self.vendor_specific = self._io.read_bits_int(32) - self._debug['vendor_specific']['end'] = self._io.pos() - - - class DeviceManufacturer(KaitaiStruct): - - class DeviceManufacturers(Enum): - erdt_systems_gmbh_and_co_kg = 878981744 - aamazing_technologies_inc = 1094798657 - acer_peripherals = 1094927698 - acolyte_color_research = 1094929492 - actix_sytems_inc = 1094931529 - adara_technology_inc = 1094992210 - adobe_systems_incorporated = 1094992453 - adi_systems_inc = 1094994208 - agfa_graphics_nv = 1095190081 - alps_electric_usa_inc = 1095519556 - alps_electric_usa_inc_2 = 1095520339 - alwan_color_expertise = 1095522126 - amiable_technologies_inc = 1095586889 - aoc_international_usa_ltd = 1095713568 - apago = 1095778631 - apple_computer_inc = 1095782476 - ast = 1095980064 - atandt_computer_systems = 1096033876 - barbieri_electronic = 1111573836 - barco_nv = 1112687439 - breakpoint_pty_limited = 1112689488 - brother_industries_ltd = 1112690516 - bull = 1112886348 - bus_computer_systems = 1112888096 - c_itoh = 1127041364 - intel_corporation = 1128353106 - canon_inc_canon_development_americas_inc = 1128353359 - carroll_touch = 1128354386 - casio_computer_co_ltd = 1128354633 - colorbus_pl = 1128420691 - crossfield = 1128614944 - crossfield_2 = 1128615032 - cgs_publishing_technologies_international_gmbh = 1128747808 - rochester_robotics = 1128811808 - colour_imaging_group_london = 1128875852 - citizen = 1128879177 - candela_ltd = 1129066544 - color_iq = 1129072977 - chromaco_inc = 1129136975 - chromix = 1129146712 - colorgraphic_communications_corporation = 1129270351 - compaq_computer_corporation = 1129270608 - compeq_usa_focus_technology = 1129270640 - conrac_display_products = 1129270866 - cordata_technologies_inc = 1129271876 - compaq_computer_corporation_2 = 1129337120 - colorpro = 1129337423 - cornerstone = 1129467424 - ctx_international_inc = 1129601056 - colorvision = 1129728339 - fujitsu_laboratories_ltd = 1129792288 - darius_technology_ltd = 1145131593 - dataproducts = 1145132097 - dry_creek_photo = 1145262112 - digital_contents_resource_center_chung_ang_university = 1145262659 - dell_computer_corporation = 1145392204 - dainippon_ink_and_chemicals = 1145652000 - diconix = 1145652047 - digital = 1145653065 - digital_light_and_color = 1145841219 - doppelganger_llc = 1146113095 - dainippon_screen = 1146298400 - doosol = 1146310476 - dupont = 1146441806 - epson = 1162892111 - esko_graphics = 1163086671 - electronics_and_telecommunications_research_institute = 1163153993 - everex_systems_inc = 1163281746 - exactcode_gmbh = 1163411779 - eizo_nanao_corporation = 1164540527 - falco_data_products_inc = 1178684483 - fuji_photo_film_coltd = 1179000864 - fujifilm_electronic_imaging_ltd = 1179010377 - fnord_software = 1179537988 - fora_inc = 1179603521 - forefront_technology_corporation = 1179603525 - fujitsu = 1179658794 - waytech_development_inc = 1179664672 - fujitsu_2 = 1179994697 - fuji_xerox_co_ltd = 1180180512 - gcc_technologies_inc = 1195590432 - global_graphics_software_limited = 1195856716 - gretagmacbeth = 1196245536 - gmg_gmbh_and_co_kg = 1196246816 - goldstar_technology_inc = 1196379204 - giantprint_pty_ltd = 1196446292 - gretagmacbeth_2 = 1196707138 - waytech_development_inc_2 = 1196835616 - sony_corporation = 1196896843 - hci = 1212369184 - heidelberger_druckmaschinen_ag = 1212435744 - hermes = 1212502605 - hitachi_america_ltd = 1212765249 - hewlett_packard = 1213210656 - hitachi_ltd = 1213481760 - hiti_digital_inc = 1214862441 - ibm_corporation = 1229081888 - scitex_corporation_ltd = 1229213268 - hewlett_packard_2 = 1229275936 - iiyama_north_america_inc = 1229543745 - ikegami_electronics_inc = 1229669703 - image_systems_corporation = 1229799751 - ingram_micro_inc = 1229801760 - intel_corporation_2 = 1229870147 - intl = 1229870156 - intra_electronics_usa_inc = 1229870162 - iocomm_international_technology_corporation = 1229931343 - infoprint_solutions_company = 1230000928 - scitex_corporation_ltd_3 = 1230129491 - ichikawa_soft_laboratory = 1230195744 - itnl = 1230261836 - ivm = 1230392608 - iwatsu_electric_co_ltd = 1230455124 - scitex_corporation_ltd_2 = 1231318644 - inca_digital_printers_ltd = 1231971169 - scitex_corporation_ltd_4 = 1232234867 - jetsoft_development = 1246971476 - jvc_information_products_co = 1247167264 - scitex_corporation_ltd_6 = 1262572116 - kfc_computek_components_corporation = 1262895904 - klh_computers = 1263290400 - konica_minolta_holdings_inc = 1263355972 - konica_corporation = 1263420225 - kodak = 1263486017 - kyocera = 1264144195 - scitex_corporation_ltd_7 = 1264677492 - leica_camera_ag = 1279476039 - leeds_colour = 1279476548 - left_dakota = 1279541579 - leading_technology_inc = 1279607108 - lexmark_international_inc = 1279613005 - link_computer_inc = 1279872587 - linotronic = 1279872591 - lite_on_inc = 1279874117 - mag_computronic_usa_inc = 1296123715 - mag_innovision_inc = 1296123721 - mannesmann = 1296125518 - micron_technology_inc = 1296646990 - microtek = 1296646994 - microvitec_inc = 1296646998 - minolta = 1296649807 - mitsubishi_electronics_america_inc = 1296651347 - mitsuba_corporation = 1296651379 - minolta_2 = 1296976980 - modgraph_inc = 1297040455 - monitronix_inc = 1297043017 - monaco_systems_inc = 1297043027 - morse_technology_inc = 1297044051 - motive_systems = 1297044553 - microsoft_corporation = 1297303124 - mutoh_industries_ltd = 1297437775 - mitsubishi_electric_corporation_kyoto_works = 1298756723 - nanao_usa_corporation = 1312902721 - nec_corporation = 1313162016 - nexpress_solutions_llc = 1313167440 - nissei_sangyo_america_ltd = 1313428307 - nikon_corporation = 1313558350 - oce_technologies_bv = 1329808672 - ocecolor = 1329808707 - oki = 1330333984 - okidata = 1330334020 - okidata_2 = 1330334032 - olivetti = 1330399574 - olympus_optical_co_ltd = 1330403661 - onyx_graphics = 1330534744 - optiquest = 1330664521 - packard_bell = 1346454347 - matsushita_electric_industrial_co_ltd = 1346457153 - pantone_inc = 1346457172 - packard_bell_2 = 1346522656 - pfu_limited = 1346786592 - philips_consumer_electronics_co = 1346914636 - hoya_corporation_pentax_imaging_systems_division = 1347310680 - phase_one_a_s = 1347382885 - premier_computer_innovations = 1347568973 - princeton_graphic_systems = 1347569998 - princeton_publishing_labs = 1347570000 - qlux = 1363957080 - qms_inc = 1364022048 - qpcard_ab = 1364214596 - quadlaser = 1364541764 - qume_corporation = 1364544837 - radius_inc = 1380009033 - integrated_color_solutions_inc_2 = 1380205688 - roland_dg_corporation = 1380206368 - redms_group_inc = 1380271181 - relisys = 1380273225 - rolf_gierling_multitools = 1380404563 - ricoh_corporation = 1380533071 - edmund_ronald = 1380863044 - royal = 1380931905 - ricoh_printing_systemsltd = 1380991776 - royal_information_electronics_co_ltd = 1381256224 - sampo_corporation_of_america = 1396788560 - samsung_inc = 1396788563 - jaime_santana_pomares = 1396788820 - scitex_corporation_ltd_9 = 1396918612 - dainippon_screen_3 = 1396920910 - scitex_corporation_ltd_12 = 1396985888 - samsung_electronics_coltd = 1397048096 - seiko_instruments_usa_inc = 1397049675 - seikosha = 1397049707 - scanguycom = 1397183833 - sharp_laboratories = 1397244242 - international_color_consortium = 1397310275 - sony_corporation_2 = 1397706329 - spectracal = 1397769036 - star = 1398030674 - sampo_technology_corporation = 1398031136 - scitex_corporation_ltd_10 = 1399023988 - scitex_corporation_ltd_13 = 1399091232 - sony_corporation_3 = 1399811705 - talon_technology_corporation = 1413565519 - tandy = 1413566020 - tatung_co_of_america_inc = 1413567573 - taxan_america_inc = 1413568577 - tokyo_denshi_sekei_kk = 1413763872 - teco_information_systems_inc = 1413825359 - tegra = 1413826386 - tektronix_inc = 1413827412 - texas_instruments = 1414078496 - typemaker_ltd = 1414351698 - toshiba_corp = 1414484802 - toshiba_inc = 1414484808 - totoku_electric_co_ltd = 1414485067 - triumph = 1414678869 - toshiba_tec_corporation = 1414742612 - ttx_computer_products_inc = 1414813728 - tvm_professional_monitor_corporation = 1414941984 - tw_casper_corporation = 1414996000 - ulead_systems = 1431065432 - unisys = 1431193939 - utz_fehlau_and_sohn = 1431591494 - varityper = 1447121481 - viewsonic = 1447642455 - visual_communication = 1447646028 - wang = 1463897671 - wilbur_imaging = 1464615506 - ware_to_go = 1465141042 - wyse_technology = 1465471813 - xerox_corporation = 1480938072 - x_rite = 1481787732 - lavanyas_test_company = 1513173555 - zoran_corporation = 1515340110 - zebra_technologies_inc = 1516593778 - basiccolor_gmbh = 1648968515 - bergdesign_incorporated = 1650815591 - integrated_color_solutions_inc = 1667594596 - macdermid_colorspan_inc = 1668051824 - dainippon_screen_2 = 1685266464 - dupont_2 = 1685418094 - fujifilm_electronic_imaging_ltd_2 = 1717986665 - fluxdata_corporation = 1718383992 - scitex_corporation_ltd_5 = 1769105779 - scitex_corporation_ltd_8 = 1801548404 - erdt_systems_gmbh_and_co_kg_2 = 1868706916 - medigraph_gmbh = 1868720483 - qubyx_sarl = 1903518329 - scitex_corporation_ltd_11 = 1935894900 - dainippon_screen_4 = 1935897198 - scitex_corporation_ltd_14 = 1935962144 - siwi_grafika_corporation = 1936291689 - yxymaster_gmbh = 2037938541 - SEQ_FIELDS = ["device_manufacturer"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['device_manufacturer']['start'] = self._io.pos() - self.device_manufacturer = KaitaiStream.resolve_enum(self._root.DeviceManufacturer.DeviceManufacturers, self._io.read_u4be()) - self._debug['device_manufacturer']['end'] = self._io.pos() - - - class S15Fixed16Number(KaitaiStruct): - SEQ_FIELDS = ["number"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number']['start'] = self._io.pos() - self.number = self._io.read_bytes(4) - self._debug['number']['end'] = self._io.pos() - - - class PositionNumber(KaitaiStruct): - SEQ_FIELDS = ["offset_to_data_element", "size_of_data_element"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset_to_data_element']['start'] = self._io.pos() - self.offset_to_data_element = self._io.read_u4be() - self._debug['offset_to_data_element']['end'] = self._io.pos() - self._debug['size_of_data_element']['start'] = self._io.pos() - self.size_of_data_element = self._io.read_u4be() - self._debug['size_of_data_element']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/icmp_packet.py b/python/examples/kaitai/icmp_packet.py deleted file mode 100644 index 19b42e6f..00000000 --- a/python/examples/kaitai/icmp_packet.py +++ /dev/null @@ -1,133 +0,0 @@ -# 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 -import collections - - -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 IcmpPacket(KaitaiStruct): - - class IcmpTypeEnum(Enum): - echo_reply = 0 - destination_unreachable = 3 - source_quench = 4 - redirect = 5 - echo = 8 - time_exceeded = 11 - SEQ_FIELDS = ["icmp_type", "destination_unreachable", "time_exceeded", "echo"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['icmp_type']['start'] = self._io.pos() - self.icmp_type = KaitaiStream.resolve_enum(self._root.IcmpTypeEnum, self._io.read_u1()) - self._debug['icmp_type']['end'] = self._io.pos() - if self.icmp_type == self._root.IcmpTypeEnum.destination_unreachable: - self._debug['destination_unreachable']['start'] = self._io.pos() - self.destination_unreachable = self._root.DestinationUnreachableMsg(self._io, self, self._root) - self.destination_unreachable._read() - self._debug['destination_unreachable']['end'] = self._io.pos() - - if self.icmp_type == self._root.IcmpTypeEnum.time_exceeded: - self._debug['time_exceeded']['start'] = self._io.pos() - self.time_exceeded = self._root.TimeExceededMsg(self._io, self, self._root) - self.time_exceeded._read() - self._debug['time_exceeded']['end'] = self._io.pos() - - if ((self.icmp_type == self._root.IcmpTypeEnum.echo) or (self.icmp_type == self._root.IcmpTypeEnum.echo_reply)) : - self._debug['echo']['start'] = self._io.pos() - self.echo = self._root.EchoMsg(self._io, self, self._root) - self.echo._read() - self._debug['echo']['end'] = self._io.pos() - - - class DestinationUnreachableMsg(KaitaiStruct): - - class DestinationUnreachableCode(Enum): - net_unreachable = 0 - host_unreachable = 1 - protocol_unreachable = 2 - port_unreachable = 3 - fragmentation_needed_and_df_set = 4 - source_route_failed = 5 - dst_net_unkown = 6 - sdt_host_unkown = 7 - src_isolated = 8 - net_prohibited_by_admin = 9 - host_prohibited_by_admin = 10 - net_unreachable_for_tos = 11 - host_unreachable_for_tos = 12 - communication_prohibited_by_admin = 13 - host_precedence_violation = 14 - precedence_cuttoff_in_effect = 15 - SEQ_FIELDS = ["code", "checksum"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = KaitaiStream.resolve_enum(self._root.DestinationUnreachableMsg.DestinationUnreachableCode, self._io.read_u1()) - self._debug['code']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2be() - self._debug['checksum']['end'] = self._io.pos() - - - class TimeExceededMsg(KaitaiStruct): - - class TimeExceededCode(Enum): - time_to_live_exceeded_in_transit = 0 - fragment_reassembly_time_exceeded = 1 - SEQ_FIELDS = ["code", "checksum"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = KaitaiStream.resolve_enum(self._root.TimeExceededMsg.TimeExceededCode, self._io.read_u1()) - self._debug['code']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2be() - self._debug['checksum']['end'] = self._io.pos() - - - class EchoMsg(KaitaiStruct): - SEQ_FIELDS = ["code", "checksum", "identifier", "seq_num", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = self._io.ensure_fixed_contents(b"\x00") - self._debug['code']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2be() - self._debug['checksum']['end'] = self._io.pos() - self._debug['identifier']['start'] = self._io.pos() - self.identifier = self._io.read_u2be() - self._debug['identifier']['end'] = self._io.pos() - self._debug['seq_num']['start'] = self._io.pos() - self.seq_num = self._io.read_u2be() - self._debug['seq_num']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/ico.py b/python/examples/kaitai/ico.py deleted file mode 100644 index 408c4bc4..00000000 --- a/python/examples/kaitai/ico.py +++ /dev/null @@ -1,124 +0,0 @@ -# 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 -import collections - - -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 Ico(KaitaiStruct): - """Microsoft Windows uses specific file format to store applications - icons - ICO. This is a container that contains one or more image - files (effectively, DIB parts of BMP files or full PNG files are - contained inside). - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms997538.aspx - """ - SEQ_FIELDS = ["magic", "num_images", "images"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x00\x00\x01\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['num_images']['start'] = self._io.pos() - self.num_images = self._io.read_u2le() - self._debug['num_images']['end'] = self._io.pos() - self._debug['images']['start'] = self._io.pos() - self.images = [None] * (self.num_images) - for i in range(self.num_images): - if not 'arr' in self._debug['images']: - self._debug['images']['arr'] = [] - self._debug['images']['arr'].append({'start': self._io.pos()}) - _t_images = self._root.IconDirEntry(self._io, self, self._root) - _t_images._read() - self.images[i] = _t_images - self._debug['images']['arr'][i]['end'] = self._io.pos() - - self._debug['images']['end'] = self._io.pos() - - class IconDirEntry(KaitaiStruct): - SEQ_FIELDS = ["width", "height", "num_colors", "reserved", "num_planes", "bpp", "len_img", "ofs_img"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u1() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u1() - self._debug['height']['end'] = self._io.pos() - self._debug['num_colors']['start'] = self._io.pos() - self.num_colors = self._io.read_u1() - self._debug['num_colors']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['num_planes']['start'] = self._io.pos() - self.num_planes = self._io.read_u2le() - self._debug['num_planes']['end'] = self._io.pos() - self._debug['bpp']['start'] = self._io.pos() - self.bpp = self._io.read_u2le() - self._debug['bpp']['end'] = self._io.pos() - self._debug['len_img']['start'] = self._io.pos() - self.len_img = self._io.read_u4le() - self._debug['len_img']['end'] = self._io.pos() - self._debug['ofs_img']['start'] = self._io.pos() - self.ofs_img = self._io.read_u4le() - self._debug['ofs_img']['end'] = self._io.pos() - - @property - def img(self): - """Raw image data. Use `is_png` to determine whether this is an - embedded PNG file (true) or a DIB bitmap (false) and call a - relevant parser, if needed to parse image data further. - """ - if hasattr(self, '_m_img'): - return self._m_img if hasattr(self, '_m_img') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_img) - self._debug['_m_img']['start'] = self._io.pos() - self._m_img = self._io.read_bytes(self.len_img) - self._debug['_m_img']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_img if hasattr(self, '_m_img') else None - - @property - def png_header(self): - """Pre-reads first 8 bytes of the image to determine if it's an - embedded PNG file. - """ - if hasattr(self, '_m_png_header'): - return self._m_png_header if hasattr(self, '_m_png_header') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_img) - self._debug['_m_png_header']['start'] = self._io.pos() - self._m_png_header = self._io.read_bytes(8) - self._debug['_m_png_header']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_png_header if hasattr(self, '_m_png_header') else None - - @property - def is_png(self): - """True if this image is in PNG format.""" - if hasattr(self, '_m_is_png'): - return self._m_is_png if hasattr(self, '_m_is_png') else None - - self._m_is_png = self.png_header == b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A" - return self._m_is_png if hasattr(self, '_m_is_png') else None - - - diff --git a/python/examples/kaitai/id3v1_1.py b/python/examples/kaitai/id3v1_1.py deleted file mode 100644 index 41b2e880..00000000 --- a/python/examples/kaitai/id3v1_1.py +++ /dev/null @@ -1,217 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Id3v11(KaitaiStruct): - """ID3v1.1 tag is a method to store simple metadata in .mp3 files. The - tag is appended to the end of file and spans exactly 128 bytes. - - This type is supposed to be used on full .mp3 files, seeking to - proper position automatically. If you're interesting in parsing only - the tag itself, please use `id3v1_1::id3_v1_1_tag` subtype. - - .. seealso:: - Source - http://id3.org/ID3v1 - """ - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class Id3V11Tag(KaitaiStruct): - """ID3v1.1 tag itself, a fixed size 128 byte structure. Contains - several metadata fields as fixed-size strings. - - Note that string encoding is not specified by standard, so real - encoding used would vary a lot from one implementation to - another. Most Windows-based applications tend to use "ANSI" - (i.e. locale-dependent encoding, usually one byte per - character). Some embedded applications allow selection of - charset. - """ - - class GenreEnum(Enum): - blues = 0 - classic_rock = 1 - country = 2 - dance = 3 - disco = 4 - funk = 5 - grunge = 6 - hip_hop = 7 - jazz = 8 - metal = 9 - new_age = 10 - oldies = 11 - other = 12 - pop = 13 - rnb = 14 - rap = 15 - reggae = 16 - rock = 17 - techno = 18 - industrial = 19 - alternative = 20 - ska = 21 - death_metal = 22 - pranks = 23 - soundtrack = 24 - euro_techno = 25 - ambient = 26 - trip_hop = 27 - vocal = 28 - jazz_funk = 29 - fusion = 30 - trance = 31 - classical = 32 - instrumental = 33 - acid = 34 - house = 35 - game = 36 - sound_clip = 37 - gospel = 38 - noise = 39 - alternrock = 40 - bass = 41 - soul = 42 - punk = 43 - space = 44 - meditative = 45 - instrumental_pop = 46 - instrumental_rock = 47 - ethnic = 48 - gothic = 49 - darkwave = 50 - techno_industrial = 51 - electronic = 52 - pop_folk = 53 - eurodance = 54 - dream = 55 - southern_rock = 56 - comedy = 57 - cult = 58 - gangsta = 59 - top_40 = 60 - christian_rap = 61 - pop_funk = 62 - jungle = 63 - native_american = 64 - cabaret = 65 - new_wave = 66 - psychadelic = 67 - rave = 68 - showtunes = 69 - trailer = 70 - lo_fi = 71 - tribal = 72 - acid_punk = 73 - acid_jazz = 74 - polka = 75 - retro = 76 - musical = 77 - rock_n_roll = 78 - hard_rock = 79 - folk = 80 - folk_rock = 81 - national_folk = 82 - swing = 83 - fast_fusion = 84 - bebob = 85 - latin = 86 - revival = 87 - celtic = 88 - bluegrass = 89 - avantgarde = 90 - gothic_rock = 91 - progressive_rock = 92 - psychedelic_rock = 93 - symphonic_rock = 94 - slow_rock = 95 - big_band = 96 - chorus = 97 - easy_listening = 98 - acoustic = 99 - humour = 100 - speech = 101 - chanson = 102 - opera = 103 - chamber_music = 104 - sonata = 105 - symphony = 106 - booty_bass = 107 - primus = 108 - porn_groove = 109 - satire = 110 - slow_jam = 111 - club = 112 - tango = 113 - samba = 114 - folklore = 115 - ballad = 116 - power_ballad = 117 - rhythmic_soul = 118 - freestyle = 119 - duet = 120 - punk_rock = 121 - drum_solo = 122 - a_capella = 123 - euro_house = 124 - dance_hall = 125 - SEQ_FIELDS = ["magic", "title", "artist", "album", "year", "comment", "genre"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x54\x41\x47") - self._debug['magic']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = self._io.read_bytes(30) - self._debug['title']['end'] = self._io.pos() - self._debug['artist']['start'] = self._io.pos() - self.artist = self._io.read_bytes(30) - self._debug['artist']['end'] = self._io.pos() - self._debug['album']['start'] = self._io.pos() - self.album = self._io.read_bytes(30) - self._debug['album']['end'] = self._io.pos() - self._debug['year']['start'] = self._io.pos() - self.year = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['year']['end'] = self._io.pos() - self._debug['comment']['start'] = self._io.pos() - self.comment = self._io.read_bytes(30) - self._debug['comment']['end'] = self._io.pos() - self._debug['genre']['start'] = self._io.pos() - self.genre = KaitaiStream.resolve_enum(self._root.Id3V11Tag.GenreEnum, self._io.read_u1()) - self._debug['genre']['end'] = self._io.pos() - - - @property - def id3v1_tag(self): - if hasattr(self, '_m_id3v1_tag'): - return self._m_id3v1_tag if hasattr(self, '_m_id3v1_tag') else None - - _pos = self._io.pos() - self._io.seek((self._io.size() - 128)) - self._debug['_m_id3v1_tag']['start'] = self._io.pos() - self._m_id3v1_tag = self._root.Id3V11Tag(self._io, self, self._root) - self._m_id3v1_tag._read() - self._debug['_m_id3v1_tag']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_id3v1_tag if hasattr(self, '_m_id3v1_tag') else None - - diff --git a/python/examples/kaitai/id3v2_3.py b/python/examples/kaitai/id3v2_3.py deleted file mode 100644 index cf3c2d46..00000000 --- a/python/examples/kaitai/id3v2_3.py +++ /dev/null @@ -1,309 +0,0 @@ -# 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 -import collections - - -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 Id3v23(KaitaiStruct): - SEQ_FIELDS = ["tag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = self._root.Tag(self._io, self, self._root) - self.tag._read() - self._debug['tag']['end'] = self._io.pos() - - class U1beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["padding", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bits_int(1) != 0 - self._debug['padding']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bits_int(7) - self._debug['value']['end'] = self._io.pos() - - - class U2beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["byte0", "byte1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['byte0']['start'] = self._io.pos() - self.byte0 = self._root.U1beSynchsafe(self._io, self, self._root) - self.byte0._read() - self._debug['byte0']['end'] = self._io.pos() - self._debug['byte1']['start'] = self._io.pos() - self.byte1 = self._root.U1beSynchsafe(self._io, self, self._root) - self.byte1._read() - self._debug['byte1']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = ((self.byte0.value << 7) | self.byte1.value) - return self._m_value if hasattr(self, '_m_value') else None - - - class Tag(KaitaiStruct): - SEQ_FIELDS = ["header", "header_ex", "frames", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - if self.header.flags.flag_headerex: - self._debug['header_ex']['start'] = self._io.pos() - self.header_ex = self._root.HeaderEx(self._io, self, self._root) - self.header_ex._read() - self._debug['header_ex']['end'] = self._io.pos() - - self._debug['frames']['start'] = self._io.pos() - self.frames = [] - i = 0 - while True: - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.Frame(self._io, self, self._root) - _t_frames._read() - _ = _t_frames - self.frames.append(_) - self._debug['frames']['arr'][len(self.frames) - 1]['end'] = self._io.pos() - if (((self._io.pos() + _.size) > self.header.size.value) or (_.is_invalid)) : - break - i += 1 - self._debug['frames']['end'] = self._io.pos() - if self.header.flags.flag_headerex: - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes((self.header_ex.padding_size - self._io.pos())) - self._debug['padding']['end'] = self._io.pos() - - - - class U4beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["short0", "short1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['short0']['start'] = self._io.pos() - self.short0 = self._root.U2beSynchsafe(self._io, self, self._root) - self.short0._read() - self._debug['short0']['end'] = self._io.pos() - self._debug['short1']['start'] = self._io.pos() - self.short1 = self._root.U2beSynchsafe(self._io, self, self._root) - self.short1._read() - self._debug['short1']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = ((self.short0.value << 14) | self.short1.value) - return self._m_value if hasattr(self, '_m_value') else None - - - class Frame(KaitaiStruct): - SEQ_FIELDS = ["id", "size", "flags", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['id']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4be() - self._debug['size']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Frame.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.size) - self._debug['data']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["flag_discard_alter_tag", "flag_discard_alter_file", "flag_read_only", "reserved1", "flag_compressed", "flag_encrypted", "flag_grouping", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag_discard_alter_tag']['start'] = self._io.pos() - self.flag_discard_alter_tag = self._io.read_bits_int(1) != 0 - self._debug['flag_discard_alter_tag']['end'] = self._io.pos() - self._debug['flag_discard_alter_file']['start'] = self._io.pos() - self.flag_discard_alter_file = self._io.read_bits_int(1) != 0 - self._debug['flag_discard_alter_file']['end'] = self._io.pos() - self._debug['flag_read_only']['start'] = self._io.pos() - self.flag_read_only = self._io.read_bits_int(1) != 0 - self._debug['flag_read_only']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(5) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['flag_compressed']['start'] = self._io.pos() - self.flag_compressed = self._io.read_bits_int(1) != 0 - self._debug['flag_compressed']['end'] = self._io.pos() - self._debug['flag_encrypted']['start'] = self._io.pos() - self.flag_encrypted = self._io.read_bits_int(1) != 0 - self._debug['flag_encrypted']['end'] = self._io.pos() - self._debug['flag_grouping']['start'] = self._io.pos() - self.flag_grouping = self._io.read_bits_int(1) != 0 - self._debug['flag_grouping']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(5) - self._debug['reserved2']['end'] = self._io.pos() - - - @property - def is_invalid(self): - if hasattr(self, '_m_is_invalid'): - return self._m_is_invalid if hasattr(self, '_m_is_invalid') else None - - self._m_is_invalid = self.id == u"\000\000\000\000" - return self._m_is_invalid if hasattr(self, '_m_is_invalid') else None - - - class HeaderEx(KaitaiStruct): - """ID3v2 extended header. - - .. seealso:: - Section 3.2. ID3v2 extended header - """ - SEQ_FIELDS = ["size", "flags_ex", "padding_size", "crc"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4be() - self._debug['size']['end'] = self._io.pos() - self._debug['flags_ex']['start'] = self._io.pos() - self.flags_ex = self._root.HeaderEx.FlagsEx(self._io, self, self._root) - self.flags_ex._read() - self._debug['flags_ex']['end'] = self._io.pos() - self._debug['padding_size']['start'] = self._io.pos() - self.padding_size = self._io.read_u4be() - self._debug['padding_size']['end'] = self._io.pos() - if self.flags_ex.flag_crc: - self._debug['crc']['start'] = self._io.pos() - self.crc = self._io.read_u4be() - self._debug['crc']['end'] = self._io.pos() - - - class FlagsEx(KaitaiStruct): - SEQ_FIELDS = ["flag_crc", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag_crc']['start'] = self._io.pos() - self.flag_crc = self._io.read_bits_int(1) != 0 - self._debug['flag_crc']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(15) - self._debug['reserved']['end'] = self._io.pos() - - - - class Header(KaitaiStruct): - """ID3v2 fixed header. - - .. seealso:: - Section 3.1. ID3v2 header - """ - SEQ_FIELDS = ["magic", "version_major", "version_revision", "flags", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x49\x44\x33") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u1() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_revision']['start'] = self._io.pos() - self.version_revision = self._io.read_u1() - self._debug['version_revision']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Header.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._root.U4beSynchsafe(self._io, self, self._root) - self.size._read() - self._debug['size']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["flag_unsynchronization", "flag_headerex", "flag_experimental", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag_unsynchronization']['start'] = self._io.pos() - self.flag_unsynchronization = self._io.read_bits_int(1) != 0 - self._debug['flag_unsynchronization']['end'] = self._io.pos() - self._debug['flag_headerex']['start'] = self._io.pos() - self.flag_headerex = self._io.read_bits_int(1) != 0 - self._debug['flag_headerex']['end'] = self._io.pos() - self._debug['flag_experimental']['start'] = self._io.pos() - self.flag_experimental = self._io.read_bits_int(1) != 0 - self._debug['flag_experimental']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(5) - self._debug['reserved']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/id3v2_4.py b/python/examples/kaitai/id3v2_4.py deleted file mode 100644 index 528ea22b..00000000 --- a/python/examples/kaitai/id3v2_4.py +++ /dev/null @@ -1,410 +0,0 @@ -# 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 -import collections - - -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 Id3v24(KaitaiStruct): - SEQ_FIELDS = ["tag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = self._root.Tag(self._io, self, self._root) - self.tag._read() - self._debug['tag']['end'] = self._io.pos() - - class U1beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["padding", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bits_int(1) != 0 - self._debug['padding']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bits_int(7) - self._debug['value']['end'] = self._io.pos() - - - class U2beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["byte0", "byte1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['byte0']['start'] = self._io.pos() - self.byte0 = self._root.U1beSynchsafe(self._io, self, self._root) - self.byte0._read() - self._debug['byte0']['end'] = self._io.pos() - self._debug['byte1']['start'] = self._io.pos() - self.byte1 = self._root.U1beSynchsafe(self._io, self, self._root) - self.byte1._read() - self._debug['byte1']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = ((self.byte0.value << 7) | self.byte1.value) - return self._m_value if hasattr(self, '_m_value') else None - - - class Tag(KaitaiStruct): - SEQ_FIELDS = ["header", "header_ex", "frames", "padding", "footer"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - if self.header.flags.flag_headerex: - self._debug['header_ex']['start'] = self._io.pos() - self.header_ex = self._root.HeaderEx(self._io, self, self._root) - self.header_ex._read() - self._debug['header_ex']['end'] = self._io.pos() - - self._debug['frames']['start'] = self._io.pos() - self.frames = [] - i = 0 - while True: - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.Frame(self._io, self, self._root) - _t_frames._read() - _ = _t_frames - self.frames.append(_) - self._debug['frames']['arr'][len(self.frames) - 1]['end'] = self._io.pos() - if (((self._io.pos() + _.size.value) > self.header.size.value) or (_.is_invalid)) : - break - i += 1 - self._debug['frames']['end'] = self._io.pos() - if not (self.header.flags.flag_footer): - self._debug['padding']['start'] = self._io.pos() - self.padding = self._root.Padding(self._io, self, self._root) - self.padding._read() - self._debug['padding']['end'] = self._io.pos() - - if self.header.flags.flag_footer: - self._debug['footer']['start'] = self._io.pos() - self.footer = self._root.Footer(self._io, self, self._root) - self.footer._read() - self._debug['footer']['end'] = self._io.pos() - - - - class U4beSynchsafe(KaitaiStruct): - SEQ_FIELDS = ["short0", "short1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['short0']['start'] = self._io.pos() - self.short0 = self._root.U2beSynchsafe(self._io, self, self._root) - self.short0._read() - self._debug['short0']['end'] = self._io.pos() - self._debug['short1']['start'] = self._io.pos() - self.short1 = self._root.U2beSynchsafe(self._io, self, self._root) - self.short1._read() - self._debug['short1']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = ((self.short0.value << 14) | self.short1.value) - return self._m_value if hasattr(self, '_m_value') else None - - - class Frame(KaitaiStruct): - SEQ_FIELDS = ["id", "size", "flags_status", "flags_format", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['id']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._root.U4beSynchsafe(self._io, self, self._root) - self.size._read() - self._debug['size']['end'] = self._io.pos() - self._debug['flags_status']['start'] = self._io.pos() - self.flags_status = self._root.Frame.FlagsStatus(self._io, self, self._root) - self.flags_status._read() - self._debug['flags_status']['end'] = self._io.pos() - self._debug['flags_format']['start'] = self._io.pos() - self.flags_format = self._root.Frame.FlagsFormat(self._io, self, self._root) - self.flags_format._read() - self._debug['flags_format']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.size.value) - self._debug['data']['end'] = self._io.pos() - - class FlagsStatus(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "flag_discard_alter_tag", "flag_discard_alter_file", "flag_read_only", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(1) != 0 - self._debug['reserved1']['end'] = self._io.pos() - self._debug['flag_discard_alter_tag']['start'] = self._io.pos() - self.flag_discard_alter_tag = self._io.read_bits_int(1) != 0 - self._debug['flag_discard_alter_tag']['end'] = self._io.pos() - self._debug['flag_discard_alter_file']['start'] = self._io.pos() - self.flag_discard_alter_file = self._io.read_bits_int(1) != 0 - self._debug['flag_discard_alter_file']['end'] = self._io.pos() - self._debug['flag_read_only']['start'] = self._io.pos() - self.flag_read_only = self._io.read_bits_int(1) != 0 - self._debug['flag_read_only']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(4) - self._debug['reserved2']['end'] = self._io.pos() - - - class FlagsFormat(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "flag_grouping", "reserved2", "flag_compressed", "flag_encrypted", "flag_unsynchronisated", "flag_indicator"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(1) != 0 - self._debug['reserved1']['end'] = self._io.pos() - self._debug['flag_grouping']['start'] = self._io.pos() - self.flag_grouping = self._io.read_bits_int(1) != 0 - self._debug['flag_grouping']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(2) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['flag_compressed']['start'] = self._io.pos() - self.flag_compressed = self._io.read_bits_int(1) != 0 - self._debug['flag_compressed']['end'] = self._io.pos() - self._debug['flag_encrypted']['start'] = self._io.pos() - self.flag_encrypted = self._io.read_bits_int(1) != 0 - self._debug['flag_encrypted']['end'] = self._io.pos() - self._debug['flag_unsynchronisated']['start'] = self._io.pos() - self.flag_unsynchronisated = self._io.read_bits_int(1) != 0 - self._debug['flag_unsynchronisated']['end'] = self._io.pos() - self._debug['flag_indicator']['start'] = self._io.pos() - self.flag_indicator = self._io.read_bits_int(1) != 0 - self._debug['flag_indicator']['end'] = self._io.pos() - - - @property - def is_invalid(self): - if hasattr(self, '_m_is_invalid'): - return self._m_is_invalid if hasattr(self, '_m_is_invalid') else None - - self._m_is_invalid = self.id == u"\000\000\000\000" - return self._m_is_invalid if hasattr(self, '_m_is_invalid') else None - - - class HeaderEx(KaitaiStruct): - SEQ_FIELDS = ["size", "flags_ex", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._root.U4beSynchsafe(self._io, self, self._root) - self.size._read() - self._debug['size']['end'] = self._io.pos() - self._debug['flags_ex']['start'] = self._io.pos() - self.flags_ex = self._root.HeaderEx.FlagsEx(self._io, self, self._root) - self.flags_ex._read() - self._debug['flags_ex']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes((self.size.value - 5)) - self._debug['data']['end'] = self._io.pos() - - class FlagsEx(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "flag_update", "flag_crc", "flag_restrictions", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(1) != 0 - self._debug['reserved1']['end'] = self._io.pos() - self._debug['flag_update']['start'] = self._io.pos() - self.flag_update = self._io.read_bits_int(1) != 0 - self._debug['flag_update']['end'] = self._io.pos() - self._debug['flag_crc']['start'] = self._io.pos() - self.flag_crc = self._io.read_bits_int(1) != 0 - self._debug['flag_crc']['end'] = self._io.pos() - self._debug['flag_restrictions']['start'] = self._io.pos() - self.flag_restrictions = self._io.read_bits_int(1) != 0 - self._debug['flag_restrictions']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(4) - self._debug['reserved2']['end'] = self._io.pos() - - - - class Header(KaitaiStruct): - SEQ_FIELDS = ["magic", "version_major", "version_revision", "flags", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x49\x44\x33") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u1() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_revision']['start'] = self._io.pos() - self.version_revision = self._io.read_u1() - self._debug['version_revision']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Header.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._root.U4beSynchsafe(self._io, self, self._root) - self.size._read() - self._debug['size']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["flag_unsynchronization", "flag_headerex", "flag_experimental", "flag_footer", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag_unsynchronization']['start'] = self._io.pos() - self.flag_unsynchronization = self._io.read_bits_int(1) != 0 - self._debug['flag_unsynchronization']['end'] = self._io.pos() - self._debug['flag_headerex']['start'] = self._io.pos() - self.flag_headerex = self._io.read_bits_int(1) != 0 - self._debug['flag_headerex']['end'] = self._io.pos() - self._debug['flag_experimental']['start'] = self._io.pos() - self.flag_experimental = self._io.read_bits_int(1) != 0 - self._debug['flag_experimental']['end'] = self._io.pos() - self._debug['flag_footer']['start'] = self._io.pos() - self.flag_footer = self._io.read_bits_int(1) != 0 - self._debug['flag_footer']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(4) - self._debug['reserved']['end'] = self._io.pos() - - - - class Padding(KaitaiStruct): - SEQ_FIELDS = ["padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes((self._root.tag.header.size.value - self._io.pos())) - self._debug['padding']['end'] = self._io.pos() - - - class Footer(KaitaiStruct): - SEQ_FIELDS = ["magic", "version_major", "version_revision", "flags", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x33\x44\x49") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u1() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_revision']['start'] = self._io.pos() - self.version_revision = self._io.read_u1() - self._debug['version_revision']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Footer.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._root.U4beSynchsafe(self._io, self, self._root) - self.size._read() - self._debug['size']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["flag_unsynchronization", "flag_headerex", "flag_experimental", "flag_footer", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag_unsynchronization']['start'] = self._io.pos() - self.flag_unsynchronization = self._io.read_bits_int(1) != 0 - self._debug['flag_unsynchronization']['end'] = self._io.pos() - self._debug['flag_headerex']['start'] = self._io.pos() - self.flag_headerex = self._io.read_bits_int(1) != 0 - self._debug['flag_headerex']['end'] = self._io.pos() - self._debug['flag_experimental']['start'] = self._io.pos() - self.flag_experimental = self._io.read_bits_int(1) != 0 - self._debug['flag_experimental']['end'] = self._io.pos() - self._debug['flag_footer']['start'] = self._io.pos() - self.flag_footer = self._io.read_bits_int(1) != 0 - self._debug['flag_footer']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(4) - self._debug['reserved']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/ines.py b/python/examples/kaitai/ines.py deleted file mode 100644 index 7f58e105..00000000 --- a/python/examples/kaitai/ines.py +++ /dev/null @@ -1,277 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Ines(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/INES - """ - SEQ_FIELDS = ["header", "trainer", "prg_rom", "chr_rom", "playchoice10", "title"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes(16) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - if self.header.f6.trainer: - self._debug['trainer']['start'] = self._io.pos() - self.trainer = self._io.read_bytes(512) - self._debug['trainer']['end'] = self._io.pos() - - self._debug['prg_rom']['start'] = self._io.pos() - self.prg_rom = self._io.read_bytes((self.header.len_prg_rom * 16384)) - self._debug['prg_rom']['end'] = self._io.pos() - self._debug['chr_rom']['start'] = self._io.pos() - self.chr_rom = self._io.read_bytes((self.header.len_chr_rom * 8192)) - self._debug['chr_rom']['end'] = self._io.pos() - if self.header.f7.playchoice10: - self._debug['playchoice10']['start'] = self._io.pos() - self.playchoice10 = self._root.Playchoice10(self._io, self, self._root) - self.playchoice10._read() - self._debug['playchoice10']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['title']['start'] = self._io.pos() - self.title = (self._io.read_bytes_full()).decode(u"ASCII") - self._debug['title']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - SEQ_FIELDS = ["magic", "len_prg_rom", "len_chr_rom", "f6", "f7", "len_prg_ram", "f9", "f10", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4E\x45\x53\x1A") - self._debug['magic']['end'] = self._io.pos() - self._debug['len_prg_rom']['start'] = self._io.pos() - self.len_prg_rom = self._io.read_u1() - self._debug['len_prg_rom']['end'] = self._io.pos() - self._debug['len_chr_rom']['start'] = self._io.pos() - self.len_chr_rom = self._io.read_u1() - self._debug['len_chr_rom']['end'] = self._io.pos() - self._debug['f6']['start'] = self._io.pos() - self._raw_f6 = self._io.read_bytes(1) - io = KaitaiStream(BytesIO(self._raw_f6)) - self.f6 = self._root.Header.F6(io, self, self._root) - self.f6._read() - self._debug['f6']['end'] = self._io.pos() - self._debug['f7']['start'] = self._io.pos() - self._raw_f7 = self._io.read_bytes(1) - io = KaitaiStream(BytesIO(self._raw_f7)) - self.f7 = self._root.Header.F7(io, self, self._root) - self.f7._read() - self._debug['f7']['end'] = self._io.pos() - self._debug['len_prg_ram']['start'] = self._io.pos() - self.len_prg_ram = self._io.read_u1() - self._debug['len_prg_ram']['end'] = self._io.pos() - self._debug['f9']['start'] = self._io.pos() - self._raw_f9 = self._io.read_bytes(1) - io = KaitaiStream(BytesIO(self._raw_f9)) - self.f9 = self._root.Header.F9(io, self, self._root) - self.f9._read() - self._debug['f9']['end'] = self._io.pos() - self._debug['f10']['start'] = self._io.pos() - self._raw_f10 = self._io.read_bytes(1) - io = KaitaiStream(BytesIO(self._raw_f10)) - self.f10 = self._root.Header.F10(io, self, self._root) - self.f10._read() - self._debug['f10']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - - class F6(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/INES#Flags_6 - """ - - class Mirroring(Enum): - horizontal = 0 - vertical = 1 - SEQ_FIELDS = ["lower_mapper", "four_screen", "trainer", "has_battery_ram", "mirroring"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['lower_mapper']['start'] = self._io.pos() - self.lower_mapper = self._io.read_bits_int(4) - self._debug['lower_mapper']['end'] = self._io.pos() - self._debug['four_screen']['start'] = self._io.pos() - self.four_screen = self._io.read_bits_int(1) != 0 - self._debug['four_screen']['end'] = self._io.pos() - self._debug['trainer']['start'] = self._io.pos() - self.trainer = self._io.read_bits_int(1) != 0 - self._debug['trainer']['end'] = self._io.pos() - self._debug['has_battery_ram']['start'] = self._io.pos() - self.has_battery_ram = self._io.read_bits_int(1) != 0 - self._debug['has_battery_ram']['end'] = self._io.pos() - self._debug['mirroring']['start'] = self._io.pos() - self.mirroring = KaitaiStream.resolve_enum(self._root.Header.F6.Mirroring, self._io.read_bits_int(1)) - self._debug['mirroring']['end'] = self._io.pos() - - - class F7(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/INES#Flags_7 - """ - SEQ_FIELDS = ["upper_mapper", "format", "playchoice10", "vs_unisystem"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['upper_mapper']['start'] = self._io.pos() - self.upper_mapper = self._io.read_bits_int(4) - self._debug['upper_mapper']['end'] = self._io.pos() - self._debug['format']['start'] = self._io.pos() - self.format = self._io.read_bits_int(2) - self._debug['format']['end'] = self._io.pos() - self._debug['playchoice10']['start'] = self._io.pos() - self.playchoice10 = self._io.read_bits_int(1) != 0 - self._debug['playchoice10']['end'] = self._io.pos() - self._debug['vs_unisystem']['start'] = self._io.pos() - self.vs_unisystem = self._io.read_bits_int(1) != 0 - self._debug['vs_unisystem']['end'] = self._io.pos() - - - class F9(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/INES#Flags_9 - """ - - class TvSystem(Enum): - ntsc = 0 - pal = 1 - SEQ_FIELDS = ["reserved", "tv_system"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(7) - self._debug['reserved']['end'] = self._io.pos() - self._debug['tv_system']['start'] = self._io.pos() - self.tv_system = KaitaiStream.resolve_enum(self._root.Header.F9.TvSystem, self._io.read_bits_int(1)) - self._debug['tv_system']['end'] = self._io.pos() - - - class F10(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/INES#Flags_10 - """ - - class TvSystem(Enum): - ntsc = 0 - dual1 = 1 - pal = 2 - dual2 = 3 - SEQ_FIELDS = ["reserved1", "bus_conflict", "prg_ram", "reserved2", "tv_system"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(2) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['bus_conflict']['start'] = self._io.pos() - self.bus_conflict = self._io.read_bits_int(1) != 0 - self._debug['bus_conflict']['end'] = self._io.pos() - self._debug['prg_ram']['start'] = self._io.pos() - self.prg_ram = self._io.read_bits_int(1) != 0 - self._debug['prg_ram']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(2) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['tv_system']['start'] = self._io.pos() - self.tv_system = KaitaiStream.resolve_enum(self._root.Header.F10.TvSystem, self._io.read_bits_int(2)) - self._debug['tv_system']['end'] = self._io.pos() - - - @property - def mapper(self): - """ - .. seealso:: - Source - https://wiki.nesdev.com/w/index.php/Mapper - """ - if hasattr(self, '_m_mapper'): - return self._m_mapper if hasattr(self, '_m_mapper') else None - - self._m_mapper = (self.f6.lower_mapper | (self.f7.upper_mapper << 4)) - return self._m_mapper if hasattr(self, '_m_mapper') else None - - - class Playchoice10(KaitaiStruct): - """ - .. seealso:: - Source - http://wiki.nesdev.com/w/index.php/PC10_ROM-Images - """ - SEQ_FIELDS = ["inst_rom", "prom"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['inst_rom']['start'] = self._io.pos() - self.inst_rom = self._io.read_bytes(8192) - self._debug['inst_rom']['end'] = self._io.pos() - self._debug['prom']['start'] = self._io.pos() - self.prom = self._root.Playchoice10.Prom(self._io, self, self._root) - self.prom._read() - self._debug['prom']['end'] = self._io.pos() - - class Prom(KaitaiStruct): - SEQ_FIELDS = ["data", "counter_out"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(16) - self._debug['data']['end'] = self._io.pos() - self._debug['counter_out']['start'] = self._io.pos() - self.counter_out = self._io.read_bytes(16) - self._debug['counter_out']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/ipv4_packet.py b/python/examples/kaitai/ipv4_packet.py deleted file mode 100644 index 4ed02a64..00000000 --- a/python/examples/kaitai/ipv4_packet.py +++ /dev/null @@ -1,157 +0,0 @@ -# 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 -import collections - - -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)) - -from . import protocol_body -class Ipv4Packet(KaitaiStruct): - SEQ_FIELDS = ["b1", "b2", "total_length", "identification", "b67", "ttl", "protocol", "header_checksum", "src_ip_addr", "dst_ip_addr", "options", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - self._debug['b2']['start'] = self._io.pos() - self.b2 = self._io.read_u1() - self._debug['b2']['end'] = self._io.pos() - self._debug['total_length']['start'] = self._io.pos() - self.total_length = self._io.read_u2be() - self._debug['total_length']['end'] = self._io.pos() - self._debug['identification']['start'] = self._io.pos() - self.identification = self._io.read_u2be() - self._debug['identification']['end'] = self._io.pos() - self._debug['b67']['start'] = self._io.pos() - self.b67 = self._io.read_u2be() - self._debug['b67']['end'] = self._io.pos() - self._debug['ttl']['start'] = self._io.pos() - self.ttl = self._io.read_u1() - self._debug['ttl']['end'] = self._io.pos() - self._debug['protocol']['start'] = self._io.pos() - self.protocol = self._io.read_u1() - self._debug['protocol']['end'] = self._io.pos() - self._debug['header_checksum']['start'] = self._io.pos() - self.header_checksum = self._io.read_u2be() - self._debug['header_checksum']['end'] = self._io.pos() - self._debug['src_ip_addr']['start'] = self._io.pos() - self.src_ip_addr = self._io.read_bytes(4) - self._debug['src_ip_addr']['end'] = self._io.pos() - self._debug['dst_ip_addr']['start'] = self._io.pos() - self.dst_ip_addr = self._io.read_bytes(4) - self._debug['dst_ip_addr']['end'] = self._io.pos() - self._debug['options']['start'] = self._io.pos() - self._raw_options = self._io.read_bytes((self.ihl_bytes - 20)) - io = KaitaiStream(BytesIO(self._raw_options)) - self.options = self._root.Ipv4Options(io, self, self._root) - self.options._read() - self._debug['options']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self._raw_body = self._io.read_bytes((self.total_length - self.ihl_bytes)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = protocol_body.ProtocolBody(self.protocol, io) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - class Ipv4Options(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Ipv4Option(self._io, self, self._root) - _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() - - - class Ipv4Option(KaitaiStruct): - SEQ_FIELDS = ["b1", "len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u1() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(((self.len - 2) if self.len > 2 else 0)) - self._debug['body']['end'] = self._io.pos() - - @property - def copy(self): - if hasattr(self, '_m_copy'): - return self._m_copy if hasattr(self, '_m_copy') else None - - self._m_copy = ((self.b1 & 128) >> 7) - return self._m_copy if hasattr(self, '_m_copy') else None - - @property - def opt_class(self): - if hasattr(self, '_m_opt_class'): - return self._m_opt_class if hasattr(self, '_m_opt_class') else None - - self._m_opt_class = ((self.b1 & 96) >> 5) - return self._m_opt_class if hasattr(self, '_m_opt_class') else None - - @property - def number(self): - if hasattr(self, '_m_number'): - return self._m_number if hasattr(self, '_m_number') else None - - self._m_number = (self.b1 & 31) - return self._m_number if hasattr(self, '_m_number') else None - - - @property - def version(self): - if hasattr(self, '_m_version'): - return self._m_version if hasattr(self, '_m_version') else None - - self._m_version = ((self.b1 & 240) >> 4) - return self._m_version if hasattr(self, '_m_version') else None - - @property - def ihl(self): - if hasattr(self, '_m_ihl'): - return self._m_ihl if hasattr(self, '_m_ihl') else None - - self._m_ihl = (self.b1 & 15) - return self._m_ihl if hasattr(self, '_m_ihl') else None - - @property - def ihl_bytes(self): - if hasattr(self, '_m_ihl_bytes'): - return self._m_ihl_bytes if hasattr(self, '_m_ihl_bytes') else None - - self._m_ihl_bytes = (self.ihl * 4) - return self._m_ihl_bytes if hasattr(self, '_m_ihl_bytes') else None - - diff --git a/python/examples/kaitai/ipv6_packet.py b/python/examples/kaitai/ipv6_packet.py deleted file mode 100644 index 70bac74f..00000000 --- a/python/examples/kaitai/ipv6_packet.py +++ /dev/null @@ -1,54 +0,0 @@ -# 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 -import collections - - -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)) - -from . import protocol_body -class Ipv6Packet(KaitaiStruct): - SEQ_FIELDS = ["version", "traffic_class", "flow_label", "payload_length", "next_header_type", "hop_limit", "src_ipv6_addr", "dst_ipv6_addr", "next_header", "rest"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_bits_int(4) - self._debug['version']['end'] = self._io.pos() - self._debug['traffic_class']['start'] = self._io.pos() - self.traffic_class = self._io.read_bits_int(8) - self._debug['traffic_class']['end'] = self._io.pos() - self._debug['flow_label']['start'] = self._io.pos() - self.flow_label = self._io.read_bits_int(20) - self._debug['flow_label']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['payload_length']['start'] = self._io.pos() - self.payload_length = self._io.read_u2be() - self._debug['payload_length']['end'] = self._io.pos() - self._debug['next_header_type']['start'] = self._io.pos() - self.next_header_type = self._io.read_u1() - self._debug['next_header_type']['end'] = self._io.pos() - self._debug['hop_limit']['start'] = self._io.pos() - self.hop_limit = self._io.read_u1() - self._debug['hop_limit']['end'] = self._io.pos() - self._debug['src_ipv6_addr']['start'] = self._io.pos() - self.src_ipv6_addr = self._io.read_bytes(16) - self._debug['src_ipv6_addr']['end'] = self._io.pos() - self._debug['dst_ipv6_addr']['start'] = self._io.pos() - self.dst_ipv6_addr = self._io.read_bytes(16) - self._debug['dst_ipv6_addr']['end'] = self._io.pos() - self._debug['next_header']['start'] = self._io.pos() - self.next_header = protocol_body.ProtocolBody(self.next_header_type, self._io) - self.next_header._read() - self._debug['next_header']['end'] = self._io.pos() - self._debug['rest']['start'] = self._io.pos() - self.rest = self._io.read_bytes_full() - self._debug['rest']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/iso9660.py b/python/examples/kaitai/iso9660.py deleted file mode 100644 index dd8071a8..00000000 --- a/python/examples/kaitai/iso9660.py +++ /dev/null @@ -1,535 +0,0 @@ -# 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 -import collections - - -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 Iso9660(KaitaiStruct): - """ISO9660 is standard filesystem used on read-only optical discs - (mostly CD-ROM). The standard was based on earlier High Sierra - Format (HSF), proposed for CD-ROMs in 1985, and, after several - revisions, it was accepted as ISO9960:1998. - - The format emphasizes portability (thus having pretty minimal - features and very conservative file names standards) and sequential - access (which favors disc devices with relatively slow rotation - speed). - """ - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class VolDescPrimary(KaitaiStruct): - """ - .. seealso:: - Source - http://wiki.osdev.org/ISO_9660#The_Primary_Volume_Descriptor - """ - SEQ_FIELDS = ["unused1", "system_id", "volume_id", "unused2", "vol_space_size", "unused3", "vol_set_size", "vol_seq_num", "logical_block_size", "path_table_size", "lba_path_table_le", "lba_opt_path_table_le", "lba_path_table_be", "lba_opt_path_table_be", "root_dir", "vol_set_id", "publisher_id", "data_preparer_id", "application_id", "copyright_file_id", "abstract_file_id", "bibliographic_file_id", "vol_create_datetime", "vol_mod_datetime", "vol_expire_datetime", "vol_effective_datetime", "file_structure_version", "unused4", "application_area"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unused1']['start'] = self._io.pos() - self.unused1 = self._io.ensure_fixed_contents(b"\x00") - self._debug['unused1']['end'] = self._io.pos() - self._debug['system_id']['start'] = self._io.pos() - self.system_id = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['system_id']['end'] = self._io.pos() - self._debug['volume_id']['start'] = self._io.pos() - self.volume_id = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['volume_id']['end'] = self._io.pos() - self._debug['unused2']['start'] = self._io.pos() - self.unused2 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00\x00\x00\x00") - self._debug['unused2']['end'] = self._io.pos() - self._debug['vol_space_size']['start'] = self._io.pos() - self.vol_space_size = self._root.U4bi(self._io, self, self._root) - self.vol_space_size._read() - self._debug['vol_space_size']['end'] = self._io.pos() - self._debug['unused3']['start'] = self._io.pos() - self.unused3 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - self._debug['unused3']['end'] = self._io.pos() - self._debug['vol_set_size']['start'] = self._io.pos() - self.vol_set_size = self._root.U2bi(self._io, self, self._root) - self.vol_set_size._read() - self._debug['vol_set_size']['end'] = self._io.pos() - self._debug['vol_seq_num']['start'] = self._io.pos() - self.vol_seq_num = self._root.U2bi(self._io, self, self._root) - self.vol_seq_num._read() - self._debug['vol_seq_num']['end'] = self._io.pos() - self._debug['logical_block_size']['start'] = self._io.pos() - self.logical_block_size = self._root.U2bi(self._io, self, self._root) - self.logical_block_size._read() - self._debug['logical_block_size']['end'] = self._io.pos() - self._debug['path_table_size']['start'] = self._io.pos() - self.path_table_size = self._root.U4bi(self._io, self, self._root) - self.path_table_size._read() - self._debug['path_table_size']['end'] = self._io.pos() - self._debug['lba_path_table_le']['start'] = self._io.pos() - self.lba_path_table_le = self._io.read_u4le() - self._debug['lba_path_table_le']['end'] = self._io.pos() - self._debug['lba_opt_path_table_le']['start'] = self._io.pos() - self.lba_opt_path_table_le = self._io.read_u4le() - self._debug['lba_opt_path_table_le']['end'] = self._io.pos() - self._debug['lba_path_table_be']['start'] = self._io.pos() - self.lba_path_table_be = self._io.read_u4be() - self._debug['lba_path_table_be']['end'] = self._io.pos() - self._debug['lba_opt_path_table_be']['start'] = self._io.pos() - self.lba_opt_path_table_be = self._io.read_u4be() - self._debug['lba_opt_path_table_be']['end'] = self._io.pos() - self._debug['root_dir']['start'] = self._io.pos() - self._raw_root_dir = self._io.read_bytes(34) - io = KaitaiStream(BytesIO(self._raw_root_dir)) - self.root_dir = self._root.DirEntry(io, self, self._root) - self.root_dir._read() - self._debug['root_dir']['end'] = self._io.pos() - self._debug['vol_set_id']['start'] = self._io.pos() - self.vol_set_id = (self._io.read_bytes(128)).decode(u"UTF-8") - self._debug['vol_set_id']['end'] = self._io.pos() - self._debug['publisher_id']['start'] = self._io.pos() - self.publisher_id = (self._io.read_bytes(128)).decode(u"UTF-8") - self._debug['publisher_id']['end'] = self._io.pos() - self._debug['data_preparer_id']['start'] = self._io.pos() - self.data_preparer_id = (self._io.read_bytes(128)).decode(u"UTF-8") - self._debug['data_preparer_id']['end'] = self._io.pos() - self._debug['application_id']['start'] = self._io.pos() - self.application_id = (self._io.read_bytes(128)).decode(u"UTF-8") - self._debug['application_id']['end'] = self._io.pos() - self._debug['copyright_file_id']['start'] = self._io.pos() - self.copyright_file_id = (self._io.read_bytes(38)).decode(u"UTF-8") - self._debug['copyright_file_id']['end'] = self._io.pos() - self._debug['abstract_file_id']['start'] = self._io.pos() - self.abstract_file_id = (self._io.read_bytes(36)).decode(u"UTF-8") - self._debug['abstract_file_id']['end'] = self._io.pos() - self._debug['bibliographic_file_id']['start'] = self._io.pos() - self.bibliographic_file_id = (self._io.read_bytes(37)).decode(u"UTF-8") - self._debug['bibliographic_file_id']['end'] = self._io.pos() - self._debug['vol_create_datetime']['start'] = self._io.pos() - self.vol_create_datetime = self._root.DecDatetime(self._io, self, self._root) - self.vol_create_datetime._read() - self._debug['vol_create_datetime']['end'] = self._io.pos() - self._debug['vol_mod_datetime']['start'] = self._io.pos() - self.vol_mod_datetime = self._root.DecDatetime(self._io, self, self._root) - self.vol_mod_datetime._read() - self._debug['vol_mod_datetime']['end'] = self._io.pos() - self._debug['vol_expire_datetime']['start'] = self._io.pos() - self.vol_expire_datetime = self._root.DecDatetime(self._io, self, self._root) - self.vol_expire_datetime._read() - self._debug['vol_expire_datetime']['end'] = self._io.pos() - self._debug['vol_effective_datetime']['start'] = self._io.pos() - self.vol_effective_datetime = self._root.DecDatetime(self._io, self, self._root) - self.vol_effective_datetime._read() - self._debug['vol_effective_datetime']['end'] = self._io.pos() - self._debug['file_structure_version']['start'] = self._io.pos() - self.file_structure_version = self._io.read_u1() - self._debug['file_structure_version']['end'] = self._io.pos() - self._debug['unused4']['start'] = self._io.pos() - self.unused4 = self._io.read_u1() - self._debug['unused4']['end'] = self._io.pos() - self._debug['application_area']['start'] = self._io.pos() - self.application_area = self._io.read_bytes(512) - self._debug['application_area']['end'] = self._io.pos() - - @property - def path_table(self): - if hasattr(self, '_m_path_table'): - return self._m_path_table if hasattr(self, '_m_path_table') else None - - _pos = self._io.pos() - self._io.seek((self.lba_path_table_le * self._root.sector_size)) - self._debug['_m_path_table']['start'] = self._io.pos() - self._raw__m_path_table = self._io.read_bytes(self.path_table_size.le) - io = KaitaiStream(BytesIO(self._raw__m_path_table)) - self._m_path_table = self._root.PathTableLe(io, self, self._root) - self._m_path_table._read() - self._debug['_m_path_table']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_path_table if hasattr(self, '_m_path_table') else None - - - class VolDescBootRecord(KaitaiStruct): - SEQ_FIELDS = ["boot_system_id", "boot_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['boot_system_id']['start'] = self._io.pos() - self.boot_system_id = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['boot_system_id']['end'] = self._io.pos() - self._debug['boot_id']['start'] = self._io.pos() - self.boot_id = (self._io.read_bytes(32)).decode(u"UTF-8") - self._debug['boot_id']['end'] = self._io.pos() - - - class Datetime(KaitaiStruct): - SEQ_FIELDS = ["year", "month", "day", "hour", "minute", "sec", "timezone"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = self._io.read_u1() - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = self._io.read_u1() - self._debug['month']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = self._io.read_u1() - self._debug['day']['end'] = self._io.pos() - self._debug['hour']['start'] = self._io.pos() - self.hour = self._io.read_u1() - self._debug['hour']['end'] = self._io.pos() - self._debug['minute']['start'] = self._io.pos() - self.minute = self._io.read_u1() - self._debug['minute']['end'] = self._io.pos() - self._debug['sec']['start'] = self._io.pos() - self.sec = self._io.read_u1() - self._debug['sec']['end'] = self._io.pos() - self._debug['timezone']['start'] = self._io.pos() - self.timezone = self._io.read_u1() - self._debug['timezone']['end'] = self._io.pos() - - - class DirEntry(KaitaiStruct): - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u1() - self._debug['len']['end'] = self._io.pos() - if self.len > 0: - self._debug['body']['start'] = self._io.pos() - 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) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - - class VolDesc(KaitaiStruct): - SEQ_FIELDS = ["type", "magic", "version", "vol_desc_boot_record", "vol_desc_primary"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u1() - self._debug['type']['end'] = self._io.pos() - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x43\x44\x30\x30\x31") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - if self.type == 0: - self._debug['vol_desc_boot_record']['start'] = self._io.pos() - self.vol_desc_boot_record = self._root.VolDescBootRecord(self._io, self, self._root) - self.vol_desc_boot_record._read() - self._debug['vol_desc_boot_record']['end'] = self._io.pos() - - if self.type == 1: - self._debug['vol_desc_primary']['start'] = self._io.pos() - self.vol_desc_primary = self._root.VolDescPrimary(self._io, self, self._root) - self.vol_desc_primary._read() - self._debug['vol_desc_primary']['end'] = self._io.pos() - - - - class PathTableEntryLe(KaitaiStruct): - SEQ_FIELDS = ["len_dir_name", "len_ext_attr_rec", "lba_extent", "parent_dir_idx", "dir_name", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_dir_name']['start'] = self._io.pos() - self.len_dir_name = self._io.read_u1() - self._debug['len_dir_name']['end'] = self._io.pos() - self._debug['len_ext_attr_rec']['start'] = self._io.pos() - self.len_ext_attr_rec = self._io.read_u1() - self._debug['len_ext_attr_rec']['end'] = self._io.pos() - self._debug['lba_extent']['start'] = self._io.pos() - self.lba_extent = self._io.read_u4le() - self._debug['lba_extent']['end'] = self._io.pos() - self._debug['parent_dir_idx']['start'] = self._io.pos() - self.parent_dir_idx = self._io.read_u2le() - self._debug['parent_dir_idx']['end'] = self._io.pos() - self._debug['dir_name']['start'] = self._io.pos() - self.dir_name = (self._io.read_bytes(self.len_dir_name)).decode(u"UTF-8") - self._debug['dir_name']['end'] = self._io.pos() - if (self.len_dir_name % 2) == 1: - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_u1() - self._debug['padding']['end'] = self._io.pos() - - - - class DirEntries(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entries']['start'] = self._io.pos() - self.entries = [] - i = 0 - while True: - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.DirEntry(self._io, self, self._root) - _t_entries._read() - _ = _t_entries - self.entries.append(_) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - if _.len == 0: - break - i += 1 - self._debug['entries']['end'] = self._io.pos() - - - class U4bi(KaitaiStruct): - SEQ_FIELDS = ["le", "be"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['le']['start'] = self._io.pos() - self.le = self._io.read_u4le() - self._debug['le']['end'] = self._io.pos() - self._debug['be']['start'] = self._io.pos() - self.be = self._io.read_u4be() - self._debug['be']['end'] = self._io.pos() - - - class U2bi(KaitaiStruct): - SEQ_FIELDS = ["le", "be"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['le']['start'] = self._io.pos() - self.le = self._io.read_u2le() - self._debug['le']['end'] = self._io.pos() - self._debug['be']['start'] = self._io.pos() - self.be = self._io.read_u2be() - self._debug['be']['end'] = self._io.pos() - - - class PathTableLe(KaitaiStruct): - """ - .. seealso:: - Source - http://wiki.osdev.org/ISO_9660#The_Path_Table - """ - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.PathTableEntryLe(self._io, self, self._root) - _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() - - - class DecDatetime(KaitaiStruct): - """ - .. seealso:: - Source - http://wiki.osdev.org/ISO_9660#Date.2Ftime_format - """ - SEQ_FIELDS = ["year", "month", "day", "hour", "minute", "sec", "sec_hundreds", "timezone"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = (self._io.read_bytes(4)).decode(u"ASCII") - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['month']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['day']['end'] = self._io.pos() - self._debug['hour']['start'] = self._io.pos() - self.hour = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['hour']['end'] = self._io.pos() - self._debug['minute']['start'] = self._io.pos() - self.minute = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['minute']['end'] = self._io.pos() - self._debug['sec']['start'] = self._io.pos() - self.sec = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['sec']['end'] = self._io.pos() - self._debug['sec_hundreds']['start'] = self._io.pos() - self.sec_hundreds = (self._io.read_bytes(2)).decode(u"ASCII") - self._debug['sec_hundreds']['end'] = self._io.pos() - self._debug['timezone']['start'] = self._io.pos() - self.timezone = self._io.read_u1() - self._debug['timezone']['end'] = self._io.pos() - - - class DirEntryBody(KaitaiStruct): - SEQ_FIELDS = ["len_ext_attr_rec", "lba_extent", "size_extent", "datetime", "file_flags", "file_unit_size", "interleave_gap_size", "vol_seq_num", "len_file_name", "file_name", "padding", "rest"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_ext_attr_rec']['start'] = self._io.pos() - self.len_ext_attr_rec = self._io.read_u1() - self._debug['len_ext_attr_rec']['end'] = self._io.pos() - self._debug['lba_extent']['start'] = self._io.pos() - self.lba_extent = self._root.U4bi(self._io, self, self._root) - self.lba_extent._read() - self._debug['lba_extent']['end'] = self._io.pos() - self._debug['size_extent']['start'] = self._io.pos() - self.size_extent = self._root.U4bi(self._io, self, self._root) - self.size_extent._read() - self._debug['size_extent']['end'] = self._io.pos() - self._debug['datetime']['start'] = self._io.pos() - self.datetime = self._root.Datetime(self._io, self, self._root) - self.datetime._read() - self._debug['datetime']['end'] = self._io.pos() - self._debug['file_flags']['start'] = self._io.pos() - self.file_flags = self._io.read_u1() - self._debug['file_flags']['end'] = self._io.pos() - self._debug['file_unit_size']['start'] = self._io.pos() - self.file_unit_size = self._io.read_u1() - self._debug['file_unit_size']['end'] = self._io.pos() - self._debug['interleave_gap_size']['start'] = self._io.pos() - self.interleave_gap_size = self._io.read_u1() - self._debug['interleave_gap_size']['end'] = self._io.pos() - self._debug['vol_seq_num']['start'] = self._io.pos() - self.vol_seq_num = self._root.U2bi(self._io, self, self._root) - self.vol_seq_num._read() - self._debug['vol_seq_num']['end'] = self._io.pos() - self._debug['len_file_name']['start'] = self._io.pos() - self.len_file_name = self._io.read_u1() - self._debug['len_file_name']['end'] = self._io.pos() - self._debug['file_name']['start'] = self._io.pos() - self.file_name = (self._io.read_bytes(self.len_file_name)).decode(u"UTF-8") - self._debug['file_name']['end'] = self._io.pos() - if (self.len_file_name % 2) == 0: - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_u1() - self._debug['padding']['end'] = self._io.pos() - - self._debug['rest']['start'] = self._io.pos() - self.rest = self._io.read_bytes_full() - self._debug['rest']['end'] = self._io.pos() - - @property - def extent_as_dir(self): - if hasattr(self, '_m_extent_as_dir'): - return self._m_extent_as_dir if hasattr(self, '_m_extent_as_dir') else None - - if (self.file_flags & 2) != 0: - io = self._root._io - _pos = io.pos() - io.seek((self.lba_extent.le * self._root.sector_size)) - self._debug['_m_extent_as_dir']['start'] = io.pos() - self._raw__m_extent_as_dir = io.read_bytes(self.size_extent.le) - io = KaitaiStream(BytesIO(self._raw__m_extent_as_dir)) - self._m_extent_as_dir = self._root.DirEntries(io, self, self._root) - self._m_extent_as_dir._read() - self._debug['_m_extent_as_dir']['end'] = io.pos() - io.seek(_pos) - - return self._m_extent_as_dir if hasattr(self, '_m_extent_as_dir') else None - - @property - def extent_as_file(self): - if hasattr(self, '_m_extent_as_file'): - return self._m_extent_as_file if hasattr(self, '_m_extent_as_file') else None - - if (self.file_flags & 2) == 0: - io = self._root._io - _pos = io.pos() - io.seek((self.lba_extent.le * self._root.sector_size)) - self._debug['_m_extent_as_file']['start'] = io.pos() - self._m_extent_as_file = io.read_bytes(self.size_extent.le) - self._debug['_m_extent_as_file']['end'] = io.pos() - io.seek(_pos) - - return self._m_extent_as_file if hasattr(self, '_m_extent_as_file') else None - - - @property - def sector_size(self): - if hasattr(self, '_m_sector_size'): - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - self._m_sector_size = 2048 - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - @property - def primary_vol_desc(self): - if hasattr(self, '_m_primary_vol_desc'): - return self._m_primary_vol_desc if hasattr(self, '_m_primary_vol_desc') else None - - _pos = self._io.pos() - self._io.seek((16 * self.sector_size)) - self._debug['_m_primary_vol_desc']['start'] = self._io.pos() - self._m_primary_vol_desc = self._root.VolDesc(self._io, self, self._root) - self._m_primary_vol_desc._read() - self._debug['_m_primary_vol_desc']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_primary_vol_desc if hasattr(self, '_m_primary_vol_desc') else None - - diff --git a/python/examples/kaitai/java_class.py b/python/examples/kaitai/java_class.py deleted file mode 100644 index e492e83f..00000000 --- a/python/examples/kaitai/java_class.py +++ /dev/null @@ -1,951 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 JavaClass(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1 - """ - SEQ_FIELDS = ["magic", "version_minor", "version_major", "constant_pool_count", "constant_pool", "access_flags", "this_class", "super_class", "interfaces_count", "interfaces", "fields_count", "fields", "methods_count", "methods", "attributes_count", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\xCA\xFE\xBA\xBE") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u2be() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u2be() - self._debug['version_major']['end'] = self._io.pos() - self._debug['constant_pool_count']['start'] = self._io.pos() - self.constant_pool_count = self._io.read_u2be() - self._debug['constant_pool_count']['end'] = self._io.pos() - self._debug['constant_pool']['start'] = self._io.pos() - self.constant_pool = [None] * ((self.constant_pool_count - 1)) - for i in range((self.constant_pool_count - 1)): - if not 'arr' in self._debug['constant_pool']: - self._debug['constant_pool']['arr'] = [] - self._debug['constant_pool']['arr'].append({'start': self._io.pos()}) - _t_constant_pool = self._root.ConstantPoolEntry(self._io, self, self._root) - _t_constant_pool._read() - self.constant_pool[i] = _t_constant_pool - self._debug['constant_pool']['arr'][i]['end'] = self._io.pos() - - self._debug['constant_pool']['end'] = self._io.pos() - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = self._io.read_u2be() - self._debug['access_flags']['end'] = self._io.pos() - self._debug['this_class']['start'] = self._io.pos() - self.this_class = self._io.read_u2be() - self._debug['this_class']['end'] = self._io.pos() - self._debug['super_class']['start'] = self._io.pos() - self.super_class = self._io.read_u2be() - self._debug['super_class']['end'] = self._io.pos() - self._debug['interfaces_count']['start'] = self._io.pos() - self.interfaces_count = self._io.read_u2be() - self._debug['interfaces_count']['end'] = self._io.pos() - self._debug['interfaces']['start'] = self._io.pos() - self.interfaces = [None] * (self.interfaces_count) - for i in range(self.interfaces_count): - if not 'arr' in self._debug['interfaces']: - self._debug['interfaces']['arr'] = [] - self._debug['interfaces']['arr'].append({'start': self._io.pos()}) - self.interfaces[i] = self._io.read_u2be() - self._debug['interfaces']['arr'][i]['end'] = self._io.pos() - - self._debug['interfaces']['end'] = self._io.pos() - self._debug['fields_count']['start'] = self._io.pos() - self.fields_count = self._io.read_u2be() - self._debug['fields_count']['end'] = self._io.pos() - self._debug['fields']['start'] = self._io.pos() - self.fields = [None] * (self.fields_count) - for i in range(self.fields_count): - if not 'arr' in self._debug['fields']: - self._debug['fields']['arr'] = [] - self._debug['fields']['arr'].append({'start': self._io.pos()}) - _t_fields = self._root.FieldInfo(self._io, self, self._root) - _t_fields._read() - self.fields[i] = _t_fields - self._debug['fields']['arr'][i]['end'] = self._io.pos() - - self._debug['fields']['end'] = self._io.pos() - self._debug['methods_count']['start'] = self._io.pos() - self.methods_count = self._io.read_u2be() - self._debug['methods_count']['end'] = self._io.pos() - self._debug['methods']['start'] = self._io.pos() - self.methods = [None] * (self.methods_count) - for i in range(self.methods_count): - if not 'arr' in self._debug['methods']: - self._debug['methods']['arr'] = [] - self._debug['methods']['arr'].append({'start': self._io.pos()}) - _t_methods = self._root.MethodInfo(self._io, self, self._root) - _t_methods._read() - self.methods[i] = _t_methods - self._debug['methods']['arr'][i]['end'] = self._io.pos() - - self._debug['methods']['end'] = self._io.pos() - self._debug['attributes_count']['start'] = self._io.pos() - self.attributes_count = self._io.read_u2be() - self._debug['attributes_count']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = [None] * (self.attributes_count) - for i in range(self.attributes_count): - if not 'arr' in self._debug['attributes']: - self._debug['attributes']['arr'] = [] - self._debug['attributes']['arr'].append({'start': self._io.pos()}) - _t_attributes = self._root.AttributeInfo(self._io, self, self._root) - _t_attributes._read() - self.attributes[i] = _t_attributes - self._debug['attributes']['arr'][i]['end'] = self._io.pos() - - self._debug['attributes']['end'] = self._io.pos() - - class FloatCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.5 - """ - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_f4be() - self._debug['value']['end'] = self._io.pos() - - - class AttributeInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7 - """ - SEQ_FIELDS = ["name_index", "attribute_length", "info"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_index']['start'] = self._io.pos() - self.name_index = self._io.read_u2be() - self._debug['name_index']['end'] = self._io.pos() - self._debug['attribute_length']['start'] = self._io.pos() - self.attribute_length = self._io.read_u4be() - self._debug['attribute_length']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - _on = self.name_as_str - if _on == u"SourceFile": - self._raw_info = self._io.read_bytes(self.attribute_length) - io = KaitaiStream(BytesIO(self._raw_info)) - self.info = self._root.AttributeInfo.AttrBodySourceFile(io, self, self._root) - self.info._read() - elif _on == u"LineNumberTable": - self._raw_info = self._io.read_bytes(self.attribute_length) - io = KaitaiStream(BytesIO(self._raw_info)) - self.info = self._root.AttributeInfo.AttrBodyLineNumberTable(io, self, self._root) - self.info._read() - elif _on == u"Exceptions": - self._raw_info = self._io.read_bytes(self.attribute_length) - io = KaitaiStream(BytesIO(self._raw_info)) - self.info = self._root.AttributeInfo.AttrBodyExceptions(io, self, self._root) - self.info._read() - elif _on == u"Code": - self._raw_info = self._io.read_bytes(self.attribute_length) - io = KaitaiStream(BytesIO(self._raw_info)) - self.info = self._root.AttributeInfo.AttrBodyCode(io, self, self._root) - self.info._read() - else: - self.info = self._io.read_bytes(self.attribute_length) - self._debug['info']['end'] = self._io.pos() - - class AttrBodyCode(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 - """ - SEQ_FIELDS = ["max_stack", "max_locals", "code_length", "code", "exception_table_length", "exception_table", "attributes_count", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['max_stack']['start'] = self._io.pos() - self.max_stack = self._io.read_u2be() - self._debug['max_stack']['end'] = self._io.pos() - self._debug['max_locals']['start'] = self._io.pos() - self.max_locals = self._io.read_u2be() - self._debug['max_locals']['end'] = self._io.pos() - self._debug['code_length']['start'] = self._io.pos() - self.code_length = self._io.read_u4be() - self._debug['code_length']['end'] = self._io.pos() - self._debug['code']['start'] = self._io.pos() - self.code = self._io.read_bytes(self.code_length) - self._debug['code']['end'] = self._io.pos() - self._debug['exception_table_length']['start'] = self._io.pos() - self.exception_table_length = self._io.read_u2be() - self._debug['exception_table_length']['end'] = self._io.pos() - self._debug['exception_table']['start'] = self._io.pos() - self.exception_table = [None] * (self.exception_table_length) - for i in range(self.exception_table_length): - if not 'arr' in self._debug['exception_table']: - self._debug['exception_table']['arr'] = [] - self._debug['exception_table']['arr'].append({'start': self._io.pos()}) - _t_exception_table = self._root.AttributeInfo.AttrBodyCode.ExceptionEntry(self._io, self, self._root) - _t_exception_table._read() - self.exception_table[i] = _t_exception_table - self._debug['exception_table']['arr'][i]['end'] = self._io.pos() - - self._debug['exception_table']['end'] = self._io.pos() - self._debug['attributes_count']['start'] = self._io.pos() - self.attributes_count = self._io.read_u2be() - self._debug['attributes_count']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = [None] * (self.attributes_count) - for i in range(self.attributes_count): - if not 'arr' in self._debug['attributes']: - self._debug['attributes']['arr'] = [] - self._debug['attributes']['arr'].append({'start': self._io.pos()}) - _t_attributes = self._root.AttributeInfo(self._io, self, self._root) - _t_attributes._read() - self.attributes[i] = _t_attributes - self._debug['attributes']['arr'][i]['end'] = self._io.pos() - - self._debug['attributes']['end'] = self._io.pos() - - class ExceptionEntry(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3 - """ - SEQ_FIELDS = ["start_pc", "end_pc", "handler_pc", "catch_type"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['start_pc']['start'] = self._io.pos() - self.start_pc = self._io.read_u2be() - self._debug['start_pc']['end'] = self._io.pos() - self._debug['end_pc']['start'] = self._io.pos() - self.end_pc = self._io.read_u2be() - self._debug['end_pc']['end'] = self._io.pos() - self._debug['handler_pc']['start'] = self._io.pos() - self.handler_pc = self._io.read_u2be() - self._debug['handler_pc']['end'] = self._io.pos() - self._debug['catch_type']['start'] = self._io.pos() - self.catch_type = self._io.read_u2be() - self._debug['catch_type']['end'] = self._io.pos() - - @property - def catch_exception(self): - if hasattr(self, '_m_catch_exception'): - return self._m_catch_exception if hasattr(self, '_m_catch_exception') else None - - if self.catch_type != 0: - self._m_catch_exception = self._root.constant_pool[(self.catch_type - 1)] - - return self._m_catch_exception if hasattr(self, '_m_catch_exception') else None - - - - class AttrBodyExceptions(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.5 - """ - SEQ_FIELDS = ["number_of_exceptions", "exceptions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number_of_exceptions']['start'] = self._io.pos() - self.number_of_exceptions = self._io.read_u2be() - self._debug['number_of_exceptions']['end'] = self._io.pos() - self._debug['exceptions']['start'] = self._io.pos() - self.exceptions = [None] * (self.number_of_exceptions) - for i in range(self.number_of_exceptions): - if not 'arr' in self._debug['exceptions']: - self._debug['exceptions']['arr'] = [] - self._debug['exceptions']['arr'].append({'start': self._io.pos()}) - _t_exceptions = self._root.AttributeInfo.AttrBodyExceptions.ExceptionTableEntry(self._io, self, self._root) - _t_exceptions._read() - self.exceptions[i] = _t_exceptions - self._debug['exceptions']['arr'][i]['end'] = self._io.pos() - - self._debug['exceptions']['end'] = self._io.pos() - - class ExceptionTableEntry(KaitaiStruct): - SEQ_FIELDS = ["index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['index']['start'] = self._io.pos() - self.index = self._io.read_u2be() - self._debug['index']['end'] = self._io.pos() - - @property - def as_info(self): - if hasattr(self, '_m_as_info'): - return self._m_as_info if hasattr(self, '_m_as_info') else None - - self._m_as_info = self._root.constant_pool[(self.index - 1)].cp_info - return self._m_as_info if hasattr(self, '_m_as_info') else None - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self.as_info.name_as_str - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - - - class AttrBodySourceFile(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.10 - """ - SEQ_FIELDS = ["sourcefile_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sourcefile_index']['start'] = self._io.pos() - self.sourcefile_index = self._io.read_u2be() - self._debug['sourcefile_index']['end'] = self._io.pos() - - @property - def sourcefile_as_str(self): - if hasattr(self, '_m_sourcefile_as_str'): - return self._m_sourcefile_as_str if hasattr(self, '_m_sourcefile_as_str') else None - - self._m_sourcefile_as_str = self._root.constant_pool[(self.sourcefile_index - 1)].cp_info.value - return self._m_sourcefile_as_str if hasattr(self, '_m_sourcefile_as_str') else None - - - class AttrBodyLineNumberTable(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.12 - """ - SEQ_FIELDS = ["line_number_table_length", "line_number_table"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['line_number_table_length']['start'] = self._io.pos() - self.line_number_table_length = self._io.read_u2be() - self._debug['line_number_table_length']['end'] = self._io.pos() - self._debug['line_number_table']['start'] = self._io.pos() - self.line_number_table = [None] * (self.line_number_table_length) - for i in range(self.line_number_table_length): - if not 'arr' in self._debug['line_number_table']: - self._debug['line_number_table']['arr'] = [] - self._debug['line_number_table']['arr'].append({'start': self._io.pos()}) - _t_line_number_table = self._root.AttributeInfo.AttrBodyLineNumberTable.LineNumberTableEntry(self._io, self, self._root) - _t_line_number_table._read() - self.line_number_table[i] = _t_line_number_table - self._debug['line_number_table']['arr'][i]['end'] = self._io.pos() - - self._debug['line_number_table']['end'] = self._io.pos() - - class LineNumberTableEntry(KaitaiStruct): - SEQ_FIELDS = ["start_pc", "line_number"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['start_pc']['start'] = self._io.pos() - self.start_pc = self._io.read_u2be() - self._debug['start_pc']['end'] = self._io.pos() - self._debug['line_number']['start'] = self._io.pos() - self.line_number = self._io.read_u2be() - self._debug['line_number']['end'] = self._io.pos() - - - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self._root.constant_pool[(self.name_index - 1)].cp_info.value - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - - class MethodRefCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2 - """ - SEQ_FIELDS = ["class_index", "name_and_type_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_index']['start'] = self._io.pos() - self.class_index = self._io.read_u2be() - self._debug['class_index']['end'] = self._io.pos() - self._debug['name_and_type_index']['start'] = self._io.pos() - self.name_and_type_index = self._io.read_u2be() - self._debug['name_and_type_index']['end'] = self._io.pos() - - @property - def class_as_info(self): - if hasattr(self, '_m_class_as_info'): - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - self._m_class_as_info = self._root.constant_pool[(self.class_index - 1)].cp_info - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - @property - def name_and_type_as_info(self): - if hasattr(self, '_m_name_and_type_as_info'): - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - self._m_name_and_type_as_info = self._root.constant_pool[(self.name_and_type_index - 1)].cp_info - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - - class FieldInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5 - """ - SEQ_FIELDS = ["access_flags", "name_index", "descriptor_index", "attributes_count", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = self._io.read_u2be() - self._debug['access_flags']['end'] = self._io.pos() - self._debug['name_index']['start'] = self._io.pos() - self.name_index = self._io.read_u2be() - self._debug['name_index']['end'] = self._io.pos() - self._debug['descriptor_index']['start'] = self._io.pos() - self.descriptor_index = self._io.read_u2be() - self._debug['descriptor_index']['end'] = self._io.pos() - self._debug['attributes_count']['start'] = self._io.pos() - self.attributes_count = self._io.read_u2be() - self._debug['attributes_count']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = [None] * (self.attributes_count) - for i in range(self.attributes_count): - if not 'arr' in self._debug['attributes']: - self._debug['attributes']['arr'] = [] - self._debug['attributes']['arr'].append({'start': self._io.pos()}) - _t_attributes = self._root.AttributeInfo(self._io, self, self._root) - _t_attributes._read() - self.attributes[i] = _t_attributes - self._debug['attributes']['arr'][i]['end'] = self._io.pos() - - self._debug['attributes']['end'] = self._io.pos() - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self._root.constant_pool[(self.name_index - 1)].cp_info.value - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - - class DoubleCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.6 - """ - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_f8be() - self._debug['value']['end'] = self._io.pos() - - - class LongCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.5 - """ - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u8be() - self._debug['value']['end'] = self._io.pos() - - - class InvokeDynamicCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.10 - """ - SEQ_FIELDS = ["bootstrap_method_attr_index", "name_and_type_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bootstrap_method_attr_index']['start'] = self._io.pos() - self.bootstrap_method_attr_index = self._io.read_u2be() - self._debug['bootstrap_method_attr_index']['end'] = self._io.pos() - self._debug['name_and_type_index']['start'] = self._io.pos() - self.name_and_type_index = self._io.read_u2be() - self._debug['name_and_type_index']['end'] = self._io.pos() - - - class MethodHandleCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.8 - """ - - class ReferenceKindEnum(Enum): - get_field = 1 - get_static = 2 - put_field = 3 - put_static = 4 - invoke_virtual = 5 - invoke_static = 6 - invoke_special = 7 - new_invoke_special = 8 - invoke_interface = 9 - SEQ_FIELDS = ["reference_kind", "reference_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reference_kind']['start'] = self._io.pos() - self.reference_kind = KaitaiStream.resolve_enum(self._root.MethodHandleCpInfo.ReferenceKindEnum, self._io.read_u1()) - self._debug['reference_kind']['end'] = self._io.pos() - self._debug['reference_index']['start'] = self._io.pos() - self.reference_index = self._io.read_u2be() - self._debug['reference_index']['end'] = self._io.pos() - - - class NameAndTypeCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.6 - """ - SEQ_FIELDS = ["name_index", "descriptor_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_index']['start'] = self._io.pos() - self.name_index = self._io.read_u2be() - self._debug['name_index']['end'] = self._io.pos() - self._debug['descriptor_index']['start'] = self._io.pos() - self.descriptor_index = self._io.read_u2be() - self._debug['descriptor_index']['end'] = self._io.pos() - - @property - def name_as_info(self): - if hasattr(self, '_m_name_as_info'): - return self._m_name_as_info if hasattr(self, '_m_name_as_info') else None - - self._m_name_as_info = self._root.constant_pool[(self.name_index - 1)].cp_info - return self._m_name_as_info if hasattr(self, '_m_name_as_info') else None - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self.name_as_info.value - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - @property - def descriptor_as_info(self): - if hasattr(self, '_m_descriptor_as_info'): - return self._m_descriptor_as_info if hasattr(self, '_m_descriptor_as_info') else None - - self._m_descriptor_as_info = self._root.constant_pool[(self.descriptor_index - 1)].cp_info - return self._m_descriptor_as_info if hasattr(self, '_m_descriptor_as_info') else None - - @property - def descriptor_as_str(self): - if hasattr(self, '_m_descriptor_as_str'): - return self._m_descriptor_as_str if hasattr(self, '_m_descriptor_as_str') else None - - self._m_descriptor_as_str = self.descriptor_as_info.value - return self._m_descriptor_as_str if hasattr(self, '_m_descriptor_as_str') else None - - - class Utf8CpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.7 - """ - SEQ_FIELDS = ["str_len", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['str_len']['start'] = self._io.pos() - self.str_len = self._io.read_u2be() - self._debug['str_len']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = (self._io.read_bytes(self.str_len)).decode(u"UTF-8") - self._debug['value']['end'] = self._io.pos() - - - class StringCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.3 - """ - SEQ_FIELDS = ["string_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['string_index']['start'] = self._io.pos() - self.string_index = self._io.read_u2be() - self._debug['string_index']['end'] = self._io.pos() - - - class MethodTypeCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.9 - """ - SEQ_FIELDS = ["descriptor_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['descriptor_index']['start'] = self._io.pos() - self.descriptor_index = self._io.read_u2be() - self._debug['descriptor_index']['end'] = self._io.pos() - - - class InterfaceMethodRefCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2 - """ - SEQ_FIELDS = ["class_index", "name_and_type_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_index']['start'] = self._io.pos() - self.class_index = self._io.read_u2be() - self._debug['class_index']['end'] = self._io.pos() - self._debug['name_and_type_index']['start'] = self._io.pos() - self.name_and_type_index = self._io.read_u2be() - self._debug['name_and_type_index']['end'] = self._io.pos() - - @property - def class_as_info(self): - if hasattr(self, '_m_class_as_info'): - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - self._m_class_as_info = self._root.constant_pool[(self.class_index - 1)].cp_info - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - @property - def name_and_type_as_info(self): - if hasattr(self, '_m_name_and_type_as_info'): - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - self._m_name_and_type_as_info = self._root.constant_pool[(self.name_and_type_index - 1)].cp_info - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - - class ClassCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1 - """ - SEQ_FIELDS = ["name_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_index']['start'] = self._io.pos() - self.name_index = self._io.read_u2be() - self._debug['name_index']['end'] = self._io.pos() - - @property - def name_as_info(self): - if hasattr(self, '_m_name_as_info'): - return self._m_name_as_info if hasattr(self, '_m_name_as_info') else None - - self._m_name_as_info = self._root.constant_pool[(self.name_index - 1)].cp_info - return self._m_name_as_info if hasattr(self, '_m_name_as_info') else None - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self.name_as_info.value - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - - class ConstantPoolEntry(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4 - """ - - class TagEnum(Enum): - utf8 = 1 - integer = 3 - float = 4 - long = 5 - double = 6 - class_type = 7 - string = 8 - field_ref = 9 - method_ref = 10 - interface_method_ref = 11 - name_and_type = 12 - method_handle = 15 - method_type = 16 - invoke_dynamic = 18 - SEQ_FIELDS = ["tag", "cp_info"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = KaitaiStream.resolve_enum(self._root.ConstantPoolEntry.TagEnum, self._io.read_u1()) - self._debug['tag']['end'] = self._io.pos() - self._debug['cp_info']['start'] = self._io.pos() - _on = self.tag - if _on == self._root.ConstantPoolEntry.TagEnum.interface_method_ref: - self.cp_info = self._root.InterfaceMethodRefCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.class_type: - self.cp_info = self._root.ClassCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.utf8: - self.cp_info = self._root.Utf8CpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.method_type: - self.cp_info = self._root.MethodTypeCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.integer: - self.cp_info = self._root.IntegerCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.string: - self.cp_info = self._root.StringCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.float: - self.cp_info = self._root.FloatCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.long: - self.cp_info = self._root.LongCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.method_ref: - self.cp_info = self._root.MethodRefCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.double: - self.cp_info = self._root.DoubleCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.invoke_dynamic: - self.cp_info = self._root.InvokeDynamicCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.field_ref: - self.cp_info = self._root.FieldRefCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.method_handle: - self.cp_info = self._root.MethodHandleCpInfo(self._io, self, self._root) - self.cp_info._read() - elif _on == self._root.ConstantPoolEntry.TagEnum.name_and_type: - self.cp_info = self._root.NameAndTypeCpInfo(self._io, self, self._root) - self.cp_info._read() - self._debug['cp_info']['end'] = self._io.pos() - - - class MethodInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6 - """ - SEQ_FIELDS = ["access_flags", "name_index", "descriptor_index", "attributes_count", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['access_flags']['start'] = self._io.pos() - self.access_flags = self._io.read_u2be() - self._debug['access_flags']['end'] = self._io.pos() - self._debug['name_index']['start'] = self._io.pos() - self.name_index = self._io.read_u2be() - self._debug['name_index']['end'] = self._io.pos() - self._debug['descriptor_index']['start'] = self._io.pos() - self.descriptor_index = self._io.read_u2be() - self._debug['descriptor_index']['end'] = self._io.pos() - self._debug['attributes_count']['start'] = self._io.pos() - self.attributes_count = self._io.read_u2be() - self._debug['attributes_count']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = [None] * (self.attributes_count) - for i in range(self.attributes_count): - if not 'arr' in self._debug['attributes']: - self._debug['attributes']['arr'] = [] - self._debug['attributes']['arr'].append({'start': self._io.pos()}) - _t_attributes = self._root.AttributeInfo(self._io, self, self._root) - _t_attributes._read() - self.attributes[i] = _t_attributes - self._debug['attributes']['arr'][i]['end'] = self._io.pos() - - self._debug['attributes']['end'] = self._io.pos() - - @property - def name_as_str(self): - if hasattr(self, '_m_name_as_str'): - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - self._m_name_as_str = self._root.constant_pool[(self.name_index - 1)].cp_info.value - return self._m_name_as_str if hasattr(self, '_m_name_as_str') else None - - - class IntegerCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.4 - """ - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u4be() - self._debug['value']['end'] = self._io.pos() - - - class FieldRefCpInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.2 - """ - SEQ_FIELDS = ["class_index", "name_and_type_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_index']['start'] = self._io.pos() - self.class_index = self._io.read_u2be() - self._debug['class_index']['end'] = self._io.pos() - self._debug['name_and_type_index']['start'] = self._io.pos() - self.name_and_type_index = self._io.read_u2be() - self._debug['name_and_type_index']['end'] = self._io.pos() - - @property - def class_as_info(self): - if hasattr(self, '_m_class_as_info'): - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - self._m_class_as_info = self._root.constant_pool[(self.class_index - 1)].cp_info - return self._m_class_as_info if hasattr(self, '_m_class_as_info') else None - - @property - def name_and_type_as_info(self): - if hasattr(self, '_m_name_and_type_as_info'): - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - self._m_name_and_type_as_info = self._root.constant_pool[(self.name_and_type_index - 1)].cp_info - return self._m_name_and_type_as_info if hasattr(self, '_m_name_and_type_as_info') else None - - - diff --git a/python/examples/kaitai/jpeg.py b/python/examples/kaitai/jpeg.py deleted file mode 100644 index 54c28bb6..00000000 --- a/python/examples/kaitai/jpeg.py +++ /dev/null @@ -1,339 +0,0 @@ -# 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 -import collections - - -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)) - -from .exif import Exif -class Jpeg(KaitaiStruct): - - class ComponentId(Enum): - y = 1 - cb = 2 - cr = 3 - i = 4 - q = 5 - SEQ_FIELDS = ["segments"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['segments']['start'] = self._io.pos() - self.segments = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['segments']: - self._debug['segments']['arr'] = [] - self._debug['segments']['arr'].append({'start': self._io.pos()}) - _t_segments = self._root.Segment(self._io, self, self._root) - _t_segments._read() - self.segments.append(_t_segments) - self._debug['segments']['arr'][len(self.segments) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['segments']['end'] = self._io.pos() - - class Segment(KaitaiStruct): - - class MarkerEnum(Enum): - tem = 1 - sof0 = 192 - sof1 = 193 - sof2 = 194 - sof3 = 195 - dht = 196 - sof5 = 197 - sof6 = 198 - sof7 = 199 - soi = 216 - eoi = 217 - sos = 218 - dqt = 219 - dnl = 220 - dri = 221 - dhp = 222 - app0 = 224 - app1 = 225 - app2 = 226 - app3 = 227 - app4 = 228 - app5 = 229 - app6 = 230 - app7 = 231 - app8 = 232 - app9 = 233 - app10 = 234 - app11 = 235 - app12 = 236 - app13 = 237 - app14 = 238 - app15 = 239 - com = 254 - SEQ_FIELDS = ["magic", "marker", "length", "data", "image_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\xFF") - self._debug['magic']['end'] = self._io.pos() - self._debug['marker']['start'] = self._io.pos() - self.marker = KaitaiStream.resolve_enum(self._root.Segment.MarkerEnum, self._io.read_u1()) - self._debug['marker']['end'] = self._io.pos() - if ((self.marker != self._root.Segment.MarkerEnum.soi) and (self.marker != self._root.Segment.MarkerEnum.eoi)) : - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - - if ((self.marker != self._root.Segment.MarkerEnum.soi) and (self.marker != self._root.Segment.MarkerEnum.eoi)) : - self._debug['data']['start'] = self._io.pos() - _on = self.marker - if _on == self._root.Segment.MarkerEnum.app1: - self._raw_data = self._io.read_bytes((self.length - 2)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.SegmentApp1(io, self, self._root) - self.data._read() - elif _on == self._root.Segment.MarkerEnum.app0: - self._raw_data = self._io.read_bytes((self.length - 2)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.SegmentApp0(io, self, self._root) - self.data._read() - elif _on == self._root.Segment.MarkerEnum.sof0: - self._raw_data = self._io.read_bytes((self.length - 2)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.SegmentSof0(io, self, self._root) - self.data._read() - elif _on == self._root.Segment.MarkerEnum.sos: - self._raw_data = self._io.read_bytes((self.length - 2)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.SegmentSos(io, self, self._root) - self.data._read() - else: - self.data = self._io.read_bytes((self.length - 2)) - self._debug['data']['end'] = self._io.pos() - - if self.marker == self._root.Segment.MarkerEnum.sos: - self._debug['image_data']['start'] = self._io.pos() - self.image_data = self._io.read_bytes_full() - self._debug['image_data']['end'] = self._io.pos() - - - - class SegmentSos(KaitaiStruct): - SEQ_FIELDS = ["num_components", "components", "start_spectral_selection", "end_spectral", "appr_bit_pos"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_components']['start'] = self._io.pos() - self.num_components = self._io.read_u1() - self._debug['num_components']['end'] = self._io.pos() - self._debug['components']['start'] = self._io.pos() - self.components = [None] * (self.num_components) - for i in range(self.num_components): - if not 'arr' in self._debug['components']: - self._debug['components']['arr'] = [] - self._debug['components']['arr'].append({'start': self._io.pos()}) - _t_components = self._root.SegmentSos.Component(self._io, self, self._root) - _t_components._read() - self.components[i] = _t_components - self._debug['components']['arr'][i]['end'] = self._io.pos() - - self._debug['components']['end'] = self._io.pos() - self._debug['start_spectral_selection']['start'] = self._io.pos() - self.start_spectral_selection = self._io.read_u1() - self._debug['start_spectral_selection']['end'] = self._io.pos() - self._debug['end_spectral']['start'] = self._io.pos() - self.end_spectral = self._io.read_u1() - self._debug['end_spectral']['end'] = self._io.pos() - self._debug['appr_bit_pos']['start'] = self._io.pos() - self.appr_bit_pos = self._io.read_u1() - self._debug['appr_bit_pos']['end'] = self._io.pos() - - class Component(KaitaiStruct): - SEQ_FIELDS = ["id", "huffman_table"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = KaitaiStream.resolve_enum(self._root.ComponentId, self._io.read_u1()) - self._debug['id']['end'] = self._io.pos() - self._debug['huffman_table']['start'] = self._io.pos() - self.huffman_table = self._io.read_u1() - self._debug['huffman_table']['end'] = self._io.pos() - - - - class SegmentApp1(KaitaiStruct): - SEQ_FIELDS = ["magic", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['magic']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.magic - if _on == u"Exif": - self.body = self._root.ExifInJpeg(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class SegmentSof0(KaitaiStruct): - SEQ_FIELDS = ["bits_per_sample", "image_height", "image_width", "num_components", "components"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bits_per_sample']['start'] = self._io.pos() - self.bits_per_sample = self._io.read_u1() - self._debug['bits_per_sample']['end'] = self._io.pos() - self._debug['image_height']['start'] = self._io.pos() - self.image_height = self._io.read_u2be() - self._debug['image_height']['end'] = self._io.pos() - self._debug['image_width']['start'] = self._io.pos() - self.image_width = self._io.read_u2be() - self._debug['image_width']['end'] = self._io.pos() - self._debug['num_components']['start'] = self._io.pos() - self.num_components = self._io.read_u1() - self._debug['num_components']['end'] = self._io.pos() - self._debug['components']['start'] = self._io.pos() - self.components = [None] * (self.num_components) - for i in range(self.num_components): - if not 'arr' in self._debug['components']: - self._debug['components']['arr'] = [] - self._debug['components']['arr'].append({'start': self._io.pos()}) - _t_components = self._root.SegmentSof0.Component(self._io, self, self._root) - _t_components._read() - self.components[i] = _t_components - self._debug['components']['arr'][i]['end'] = self._io.pos() - - self._debug['components']['end'] = self._io.pos() - - class Component(KaitaiStruct): - SEQ_FIELDS = ["id", "sampling_factors", "quantization_table_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = KaitaiStream.resolve_enum(self._root.ComponentId, self._io.read_u1()) - self._debug['id']['end'] = self._io.pos() - self._debug['sampling_factors']['start'] = self._io.pos() - self.sampling_factors = self._io.read_u1() - self._debug['sampling_factors']['end'] = self._io.pos() - self._debug['quantization_table_id']['start'] = self._io.pos() - self.quantization_table_id = self._io.read_u1() - self._debug['quantization_table_id']['end'] = self._io.pos() - - @property - def sampling_x(self): - if hasattr(self, '_m_sampling_x'): - return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None - - self._m_sampling_x = ((self.sampling_factors & 240) >> 4) - return self._m_sampling_x if hasattr(self, '_m_sampling_x') else None - - @property - def sampling_y(self): - if hasattr(self, '_m_sampling_y'): - return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None - - self._m_sampling_y = (self.sampling_factors & 15) - return self._m_sampling_y if hasattr(self, '_m_sampling_y') else None - - - - class ExifInJpeg(KaitaiStruct): - SEQ_FIELDS = ["extra_zero", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['extra_zero']['start'] = self._io.pos() - self.extra_zero = self._io.ensure_fixed_contents(b"\x00") - self._debug['extra_zero']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self._raw_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = Exif(io) - self.data._read() - self._debug['data']['end'] = self._io.pos() - - - class SegmentApp0(KaitaiStruct): - - class DensityUnit(Enum): - no_units = 0 - pixels_per_inch = 1 - pixels_per_cm = 2 - SEQ_FIELDS = ["magic", "version_major", "version_minor", "density_units", "density_x", "density_y", "thumbnail_x", "thumbnail_y", "thumbnail"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = (self._io.read_bytes(5)).decode(u"ASCII") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u1() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u1() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['density_units']['start'] = self._io.pos() - self.density_units = KaitaiStream.resolve_enum(self._root.SegmentApp0.DensityUnit, self._io.read_u1()) - self._debug['density_units']['end'] = self._io.pos() - self._debug['density_x']['start'] = self._io.pos() - self.density_x = self._io.read_u2be() - self._debug['density_x']['end'] = self._io.pos() - self._debug['density_y']['start'] = self._io.pos() - self.density_y = self._io.read_u2be() - self._debug['density_y']['end'] = self._io.pos() - self._debug['thumbnail_x']['start'] = self._io.pos() - self.thumbnail_x = self._io.read_u1() - self._debug['thumbnail_x']['end'] = self._io.pos() - self._debug['thumbnail_y']['start'] = self._io.pos() - self.thumbnail_y = self._io.read_u1() - self._debug['thumbnail_y']['end'] = self._io.pos() - self._debug['thumbnail']['start'] = self._io.pos() - self.thumbnail = self._io.read_bytes(((self.thumbnail_x * self.thumbnail_y) * 3)) - self._debug['thumbnail']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/kaitaistruct.py b/python/examples/kaitai/kaitaistruct.py deleted file mode 100644 index 1bcc31f1..00000000 --- a/python/examples/kaitai/kaitaistruct.py +++ /dev/null @@ -1,379 +0,0 @@ -import itertools -import sys -import struct -from io import BytesIO, SEEK_CUR, SEEK_END # noqa - -PY2 = sys.version_info[0] == 2 - -# Kaitai Struct runtime streaming API version, defined as per PEP-0396 -# standard. Used for two purposes: -# -# * .py files generated by ksc from .ksy check that they import proper -# KS runtime library by this version number; -# * distribution utils (setup.py) use this when packaging for PyPI -# -__version__ = '0.8' - - -class KaitaiStruct(object): - def __init__(self, stream): - self._io = stream - - def __enter__(self): - return self - - def __exit__(self, *args, **kwargs): - self.close() - - def close(self): - self._io.close() - - @classmethod - def from_file(cls, filename): - f = open(filename, 'rb') - try: - return cls(KaitaiStream(f)) - except Exception as e: - # close file descriptor, then reraise the exception - f.close() - raise - - @classmethod - def from_bytes(cls, buf): - return cls(KaitaiStream(BytesIO(buf))) - - @classmethod - def from_io(cls, io): - return cls(KaitaiStream(io)) - - -class KaitaiStream(object): - def __init__(self, io): - self._io = io - self.align_to_byte() - - def __enter__(self): - return self - - def __exit__(self, *args, **kwargs): - self.close() - - def close(self): - self._io.close() - - # ======================================================================== - # Stream positioning - # ======================================================================== - - def is_eof(self): - io = self._io - t = io.read(1) - if t == b'': - return True - else: - io.seek(-1, SEEK_CUR) - return False - - def seek(self, n): - self._io.seek(n) - - def pos(self): - return self._io.tell() - - def size(self): - # Python has no internal File object API function to get - # current file / StringIO size, thus we use the following - # trick. - io = self._io - # Remember our current position - cur_pos = io.tell() - # Seek to the end of the File object - io.seek(0, SEEK_END) - # Remember position, which is equal to the full length - full_size = io.tell() - # Seek back to the current position - io.seek(cur_pos) - return full_size - - # ======================================================================== - # Integer numbers - # ======================================================================== - - packer_s1 = struct.Struct('b') - packer_s2be = struct.Struct('>h') - packer_s4be = struct.Struct('>i') - packer_s8be = struct.Struct('>q') - packer_s2le = struct.Struct('H') - packer_u4be = struct.Struct('>I') - packer_u8be = struct.Struct('>Q') - packer_u2le = struct.Struct('f') - packer_f8be = struct.Struct('>d') - packer_f4le = struct.Struct(' 0: - # 1 bit => 1 byte - # 8 bits => 1 byte - # 9 bits => 2 bytes - bytes_needed = ((bits_needed - 1) // 8) + 1 - buf = self.read_bytes(bytes_needed) - for byte in buf: - # Python 2 will get "byte" as one-character str, thus - # we need to convert it to integer manually; Python 3 - # is fine as is. - if isinstance(byte, str): - byte = ord(byte) - self.bits <<= 8 - self.bits |= byte - self.bits_left += 8 - - # raw mask with required number of 1s, starting from lowest bit - mask = (1 << n) - 1 - # shift mask to align with highest bits available in self.bits - shift_bits = self.bits_left - n - mask <<= shift_bits - # derive reading result - res = (self.bits & mask) >> shift_bits - # clear top bits that we've just read => AND with 1s - self.bits_left -= n - mask = (1 << self.bits_left) - 1 - self.bits &= mask - - return res - - # ======================================================================== - # Byte arrays - # ======================================================================== - - def read_bytes(self, n): - if n < 0: - raise ValueError( - "requested invalid %d amount of bytes" % - (n,) - ) - r = self._io.read(n) - if len(r) < n: - raise EOFError( - "requested %d bytes, but got only %d bytes" % - (n, len(r)) - ) - return r - - def read_bytes_full(self): - return self._io.read() - - def read_bytes_term(self, term, include_term, consume_term, eos_error): - r = b'' - while True: - c = self._io.read(1) - if c == b'': - if eos_error: - raise Exception( - "end of stream reached, but no terminator %d found" % - (term,) - ) - else: - return r - elif ord(c) == term: - if include_term: - r += c - if not consume_term: - self._io.seek(-1, SEEK_CUR) - return r - else: - r += c - - def ensure_fixed_contents(self, expected): - actual = self._io.read(len(expected)) - if actual != expected: - raise Exception( - "unexpected fixed contents: got %r, was waiting for %r" % - (actual, expected) - ) - return actual - - @staticmethod - def bytes_strip_right(data, pad_byte): - new_len = len(data) - if PY2: - # data[...] must yield an integer, to compare with integer pad_byte - data = bytearray(data) - - while new_len > 0 and data[new_len - 1] == pad_byte: - new_len -= 1 - - return data[:new_len] - - @staticmethod - def bytes_terminate(data, term, include_term): - new_len = 0 - max_len = len(data) - if PY2: - # data[...] must yield an integer, to compare with integer term - data = bytearray(data) - - while new_len < max_len and data[new_len] != term: - new_len += 1 - - if include_term and new_len < max_len: - new_len += 1 - - return data[:new_len] - - # ======================================================================== - # Byte array processing - # ======================================================================== - - @staticmethod - def process_xor_one(data, key): - if PY2: - return bytes(bytearray(v ^ key for v in bytearray(data))) - else: - return bytes(v ^ key for v in data) - - @staticmethod - def process_xor_many(data, key): - if PY2: - return bytes(bytearray(a ^ b for a, b in zip(bytearray(data), itertools.cycle(bytearray(key))))) - else: - return bytes(a ^ b for a, b in zip(data, itertools.cycle(key))) - - @staticmethod - def process_rotate_left(data, amount, group_size): - if group_size != 1: - raise Exception( - "unable to rotate group of %d bytes yet" % - (group_size,) - ) - - mask = group_size * 8 - 1 - anti_amount = -amount & mask - - r = bytearray(data) - for i in range(len(r)): - r[i] = (r[i] << amount) & 0xff | (r[i] >> anti_amount) - return bytes(r) - - # ======================================================================== - # Misc - # ======================================================================== - - @staticmethod - def resolve_enum(enum_obj, value): - """Resolves value using enum: if the value is not found in the map, - we'll just use literal value per se. Works around problem with Python - enums throwing an exception when encountering unknown value. - """ - try: - return enum_obj(value) - except ValueError as e: - return value diff --git a/python/examples/kaitai/kshelpers.py b/python/examples/kaitai/kshelpers.py deleted file mode 100644 index 40a6320e..00000000 --- a/python/examples/kaitai/kshelpers.py +++ /dev/null @@ -1,771 +0,0 @@ -#!/usr/bin/env python - -import traceback - -import io -import os -import re -import sys -import types -import struct -import binascii -import importlib -import collections - -from binaryninja import log - -from PySide2.QtCore import Qt -from PySide2.QtWidgets import QTreeWidgetItem - -if sys.version_info[0] == 2: - import kaitaistruct -else: - from . import kaitaistruct - -#------------------------------------------------------------------------------ -# id and parse -#------------------------------------------------------------------------------ - -# return the name of the kaitai module to service this data -# -# dsample: str data sample -# length: int total length of data -def idData(dataSample, length): - result = None - #log.log_debug('idData() here with sample: %s' % repr(dataSample)) - - if len(dataSample) < 16: - return result - - if dataSample[0:4] == b'\x7fELF': - result = 'elf' - if dataSample[0:4] in [b'\xfe\xed\xfa\xce', b'\xce\xfa\xed\xfe', b'\xfe\xed\xfa\xcf', b'\xcf\xfa\xed\xfe']: - result = 'mach_o' - if dataSample[0:2] == b'MZ': - result = 'microsoft_pe' - if dataSample[0:8] == b'\x89PNG\x0d\x0a\x1a\x0a': - result = 'png' - if dataSample[2:11] == b'\xFF\xe0\x00\x10JFIF\x00': - result = 'jpeg' - if dataSample[0:4] == b'GIF8': - result = 'gif' - if dataSample[0:2] in [b'BM', b'BA', b'CI', b'CP', b'IC', b'PT'] and struct.unpack(' 8: - result = '%s...%s (0x%X==%d chars total)' % \ - (repr(obj[0:8]), repr(obj[-1]), len(obj), len(obj)) - else: - result = repr(obj) - elif isinstance(obj, bytes): - if len(obj) > 8: - result = binascii.hexlify(obj[0:8]).decode('utf-8') + '...' + \ - ('%02X' % obj[-1]) + ' (0x%X==%d bytes total)' % (len(obj), len(obj)) - else: - result = binascii.hexlify(obj).decode('utf-8') - # note: bool needs to appear before int (else int determination will dominate) - elif isinstance(obj, bool): - result = '%s' % (obj) - elif isinstance(obj, int): - result = '0x%X (%d)' % (obj, obj) - elif str(objType).startswith('0 and isinstance(subobj[0], kaitaistruct.KaitaiStruct): - result += [fieldName] - except Exception: - pass - - return result - -# compute all kaitai objects linked to from the given object -# -# IN: kaitai object -# OUT: [obj0, obj1, obj2, ...] -# -def getLinkedKaitaiObjects(ksobj): - result = set() - - for fieldName in getFieldNamesDescend(ksobj): - subobj = getattr(ksobj, fieldName, False) - if isinstance(subobj, list): - for tmp in subobj: - result.add(tmp) - else: - result.add(subobj) - - return result - -# compute all kaitai objects linked to from the given object, and from its -# descendents, and so on... -def getLinkedKaitaiObjectsAll(ksobj, depth=0): - #if depth > 2: - # return [] - - exercise(ksobj) - - result = set([ksobj]) - - linkedObjects = getLinkedKaitaiObjects(ksobj) - for subobj in linkedObjects: - subResult = getLinkedKaitaiObjectsAll(subobj, depth+1) - result = result.union(subResult) - - return result - -def getDepth(ksobj, depth=0): - result = depth - - exercise(ksobj) - for subObj in getLinkedKaitaiObjects(ksobj): - result = max(result, getDepth(subObj, depth+1)) - - return result - -#------------------------------------------------------------------------------ -# Kaitai IO Wrapper -#------------------------------------------------------------------------------ - -# wraps a BinaryView into an "IO" that KaitaiStream can use -# -# now Kaitai can parse directly from the BinaryView and we can avoid making a -# potentially giant copy of the file contents just for kaitai parsing -# -class KaitaiBinaryViewIO: - def __init__(self, binaryView): - self.binaryView = binaryView - self.position = 0 - - def seek(self, offs, whence=io.SEEK_SET): - #log.log_debug('seek(0x%X, %d)' % (offs, whence)) - if whence == io.SEEK_SET: - self.position = offs - elif whence == io.SEEK_CUR: - self.position += offs - elif whence == io.SEEK_END: - self.position = len(self.binaryView) - else: - raise Exception('unknown whence in seek(): %d' % whence) - - def tell(self): - #log.log_debug('tell() returning 0x%X' % (self.position)) - return self.position - - def read(self, length=None): - # if no length is given (eg: see read_bytes_full() in kaitaistruct.py) - if length == None: - length = len(self.binaryView) - self.position - - #log.log_debug('read(%d) (starting at position: 0x%X)' % (length, self.position)) - data = self.binaryView.read(self.position, length) - self.position += length - return data - - def close(self): - pass - -#------------------------------------------------------------------------------ -# Qt/Kaitai OOP -#------------------------------------------------------------------------------ - -# why subclass? -# - override "<" to get sorting to work right -# - setLabel(), setValue(), etc. conveniences -# - centralized location to modify field names and labels (eg: remove '_m_') - -class KaitaiTreeWidgetItem(QTreeWidgetItem): - def __init__(self, parent=None, data=[None,None,None,None]): - QTreeWidgetItem.__init__(self, parent, data) - - self.label = None # string - self.value = None # string - self.start = None # int - self.end = None # int - self.ksobj = None # KaitaiStruct - - def __lt__(self, otherItem): - column = self.treeWidget().sortColumn() - - lhsText = self.text(column) - rhsText = otherItem.text(column) - - if not lhsText: - return False - if not rhsText: - return True - - try: - return int(lhsText,16) < int(rhsText, 16) - except: - return lhsText.__lt__(rhsText) - - def setLabel(self, label): - self.label = label - if label.startswith('_m_'): - label = label[3:] - self.setData(0, Qt.DisplayRole, label) - - def setValue(self, value): - self.value = value - if isinstance(value, int): - value = '%X'%value - self.setData(1, Qt.DisplayRole, value) - - def setStart(self, start): - if start == None: - self.start = None - elif isinstance(start, int): - self.start = start - start = '%X'%start - elif (sys.version_info[0] == 2) and type(start) == types.LongType: - self.start = start - start = '%X'%start - else: - self.start = int(start,16) - - self.setData(2, Qt.DisplayRole, start) - - def setEnd(self, end): - if end == None: - self.end = None - - if isinstance(end, int): - self.end = end - end = '%X'%end - elif (sys.version_info[0] == 2) and type(end) == types.LongType: - self.end = end - end = '%X'%end - else: - self.end = int(end,16) - self.setData(3, Qt.DisplayRole, end) - - def setKaitaiObject(self, ksobj): - self.ksobj = ksobj - self.setData(0, Qt.UserRole, ksobj) - - def __str__(self): - result = 'label=%s: value=%s range=[%s,%s)' % \ - (self.label, self.value, self.start, self.end) - - result += ' ksobj=%s' % self.ksobj - - if self.ksobj: - result += ' io=%s' % self.ksobj._io - - #if self.parent: - # result += ' parent=%s' % self.ksobj.parent - - return result - - def __str_short__(self): - return '[%s,%s) %s' % (repr(self.start), repr(self.end), repr(self.label)) - -#------------------------------------------------------------------------------ -# build QTree and helpers -#------------------------------------------------------------------------------ - -# ARGS: -# obj: KaitaiStruct -# RETURNS: -# KaitaiTreeWidgetItem (QTreeWidgetItem) -# -def buildQtree(ksobj): - if not isinstance(ksobj, kaitaistruct.KaitaiStruct): - return None - - exceptions = ['_root', '_parent', '_io', 'SEQ_FIELDS', '_debug'] - - qwi = KaitaiTreeWidgetItem() - qwi.setKaitaiObject(ksobj) - - fieldNames = set() - - # first pass: access fields that may be properties, which could compute - # internal results (often '_m_XXX' fields) - for candidate in dir(ksobj): - if candidate.startswith('_') and (not candidate.startswith('_m_')): - continue - if candidate in exceptions: - continue - try: - getattr(ksobj, candidate) - fieldNames.add(candidate) - except Exception: - pass - - # second pass: collect the '_m_XXX' fields which have the debug start/end - # marks, remove the 'XXX' counterpart, if it exists - for candidate in filter(lambda x: x.startswith('_m_'), dir(ksobj)): - try: - if not getattr(ksobj, candidate, False): - continue - - fieldNames.add(candidate) - if candidate[3:] in fieldNames: - fieldNames.remove(candidate[3:]) - - except Exception: - pass - - for fieldName in fieldNames: - subObj = getattr(ksobj, fieldName) - - child = None - if isinstance(subObj, kaitaistruct.KaitaiStruct): - fieldLabel = fieldName - child = buildQtree(subObj) - if child: - populateChild(ksobj, fieldName, fieldName, None, child) - qwi.addChild(child) - - elif isinstance(subObj, list): - if len(subObj)<=0: - continue - - # CASE: is list of KaitaiObjects -> recurse! - if isinstance(subObj[0], kaitaistruct.KaitaiStruct): - child = KaitaiTreeWidgetItem() - populateChild(ksobj, fieldName, fieldName, None, child) - - # does _debug have an array version of start/end? - startsEnds = None - if hasattr(ksobj, '_debug'): - if fieldName in ksobj._debug: - if 'arr' in ksobj._debug[fieldName]: - startsEnds = ksobj._debug[fieldName]['arr'] - - for i in range(len(subObj)): - grandchild = buildQtree(subObj[i]) - fieldLabel = '%s[%d]' % (fieldName, i) - grandchild.setLabel(fieldLabel) - - if startsEnds: - grandchild.setStart(startsEnds[i]['start']) - grandchild.setEnd(startsEnds[i]['end']) - - child.addChild(grandchild) - - qwi.addChild(child) - - # CASE: is list of primitive objects -> create leaves - else: - child = KaitaiTreeWidgetItem() - populateChild(ksobj, fieldName, fieldName, None, child) - - # TODO: explain this hack - kstmp = kaitaistruct.KaitaiStruct(ksobj._io) - kstmp._parent = ksobj - child.setKaitaiObject(kstmp) - - # does _debug have an array version of start/end? - startsEnds = None - if hasattr(ksobj, '_debug'): - if fieldName in ksobj._debug: - if 'arr' in ksobj._debug[fieldName]: - startsEnds = ksobj._debug[fieldName]['arr'] - - for i in range(len(subObj)): - grandchild = createLeaf('%s[%d]'%(fieldName,i), subObj[i]) - if not grandchild: - continue - - if startsEnds: - grandchild.setStart(startsEnds[i]['start']) - grandchild.setEnd(startsEnds[i]['end']) - - child.addChild(grandchild) - - qwi.addChild(child) - else: - child = createLeaf(fieldName, subObj) - if child: - # don't override createLeaf()'s work on label, value - populateChild(ksobj, fieldName, None, None, child) - qwi.addChild(child) - - return qwi - -def createLeaf(fieldName, obj): - objtype = type(obj) - - if objtype == types.FunctionType: - #log.log_debug('reject %s because its a function' % fieldName) - return None - elif isinstance(obj, type): - #log.log_debug('reject %s because its a type' % fieldName) - return None - elif sys.version_info[0] == 2 and callable(obj): - #log.log_debug('reject %s because its a callable' % fieldName) - return None - elif sys.version_info[0] == 3 and hasattr(obj, '__call__'): - #log.log_debug('reject %s because its a callable' % fieldName) - return None - - fieldValue = None - - if isinstance(obj, str) or isinstance(obj, bytes): - if len(obj) > 8: - fieldValue = str(repr(obj[0:8])) + '...' - else: - fieldValue = repr(obj) - elif sys.version_info[0] == 2 and objtype == types.UnicodeType: - fieldValue = repr(obj) - elif isinstance(obj, int): - fieldValue = '0x%X (%d)' % (obj, obj) - elif isinstance(obj, bool): - fieldValue = '%s' % (obj) - elif str(objtype).startswith(' 0: - self._debug['file_record']['start'] = self._io.pos() - self.file_record = self._root.FileRecord(self._io, self, self._root) - self.file_record._read() - self._debug['file_record']['end'] = self._io.pos() - - - - class FileRecord(KaitaiStruct): - SEQ_FIELDS = ["header", "file_uncompr_crc16", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes((self._parent.header_len - 1)) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - if self.header.header1.lha_level == 0: - self._debug['file_uncompr_crc16']['start'] = self._io.pos() - self.file_uncompr_crc16 = self._io.read_u2le() - self._debug['file_uncompr_crc16']['end'] = self._io.pos() - - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.header.header1.file_size_compr) - self._debug['body']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - SEQ_FIELDS = ["header1", "filename_len", "filename", "file_uncompr_crc16", "os", "ext_header_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header1']['start'] = self._io.pos() - self.header1 = self._root.Header1(self._io, self, self._root) - self.header1._read() - self._debug['header1']['end'] = self._io.pos() - if self.header1.lha_level == 0: - self._debug['filename_len']['start'] = self._io.pos() - self.filename_len = self._io.read_u1() - self._debug['filename_len']['end'] = self._io.pos() - - if self.header1.lha_level == 0: - self._debug['filename']['start'] = self._io.pos() - self.filename = (self._io.read_bytes(self.filename_len)).decode(u"ASCII") - self._debug['filename']['end'] = self._io.pos() - - if self.header1.lha_level == 2: - self._debug['file_uncompr_crc16']['start'] = self._io.pos() - self.file_uncompr_crc16 = self._io.read_u2le() - self._debug['file_uncompr_crc16']['end'] = self._io.pos() - - if self.header1.lha_level == 2: - self._debug['os']['start'] = self._io.pos() - self.os = self._io.read_u1() - self._debug['os']['end'] = self._io.pos() - - if self.header1.lha_level == 2: - self._debug['ext_header_size']['start'] = self._io.pos() - self.ext_header_size = self._io.read_u2le() - self._debug['ext_header_size']['end'] = self._io.pos() - - - - class Header1(KaitaiStruct): - SEQ_FIELDS = ["header_checksum", "method_id", "file_size_compr", "file_size_uncompr", "file_timestamp", "attr", "lha_level"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header_checksum']['start'] = self._io.pos() - self.header_checksum = self._io.read_u1() - self._debug['header_checksum']['end'] = self._io.pos() - self._debug['method_id']['start'] = self._io.pos() - self.method_id = (self._io.read_bytes(5)).decode(u"ASCII") - self._debug['method_id']['end'] = self._io.pos() - self._debug['file_size_compr']['start'] = self._io.pos() - self.file_size_compr = self._io.read_u4le() - self._debug['file_size_compr']['end'] = self._io.pos() - self._debug['file_size_uncompr']['start'] = self._io.pos() - self.file_size_uncompr = self._io.read_u4le() - self._debug['file_size_uncompr']['end'] = self._io.pos() - self._debug['file_timestamp']['start'] = self._io.pos() - self.file_timestamp = self._io.read_u4le() - self._debug['file_timestamp']['end'] = self._io.pos() - self._debug['attr']['start'] = self._io.pos() - self.attr = self._io.read_u1() - self._debug['attr']['end'] = self._io.pos() - self._debug['lha_level']['start'] = self._io.pos() - self.lha_level = self._io.read_u1() - self._debug['lha_level']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/mach_o.py b/python/examples/kaitai/mach_o.py deleted file mode 100644 index 5ce46a75..00000000 --- a/python/examples/kaitai/mach_o.py +++ /dev/null @@ -1,2739 +0,0 @@ -# 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 -import collections - - -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 MachO(KaitaiStruct): - - class MagicType(Enum): - fat_le = 3199925962 - fat_be = 3405691582 - macho_le_x86 = 3472551422 - macho_le_x64 = 3489328638 - macho_be_x86 = 4277009102 - macho_be_x64 = 4277009103 - - class CpuType(Enum): - vax = 1 - romp = 2 - ns32032 = 4 - ns32332 = 5 - i386 = 7 - mips = 8 - ns32532 = 9 - hppa = 11 - arm = 12 - mc88000 = 13 - sparc = 14 - i860 = 15 - i860_little = 16 - rs6000 = 17 - powerpc = 18 - abi64 = 16777216 - x86_64 = 16777223 - arm64 = 16777228 - powerpc64 = 16777234 - any = 4294967295 - - class FileType(Enum): - object = 1 - execute = 2 - fvmlib = 3 - core = 4 - preload = 5 - dylib = 6 - dylinker = 7 - bundle = 8 - dylib_stub = 9 - dsym = 10 - kext_bundle = 11 - - class LoadCommandType(Enum): - segment = 1 - symtab = 2 - symseg = 3 - thread = 4 - unix_thread = 5 - load_fvm_lib = 6 - id_fvm_lib = 7 - ident = 8 - fvm_file = 9 - prepage = 10 - dysymtab = 11 - load_dylib = 12 - id_dylib = 13 - load_dylinker = 14 - id_dylinker = 15 - prebound_dylib = 16 - routines = 17 - sub_framework = 18 - sub_umbrella = 19 - sub_client = 20 - sub_library = 21 - twolevel_hints = 22 - prebind_cksum = 23 - segment_64 = 25 - routines_64 = 26 - uuid = 27 - code_signature = 29 - segment_split_info = 30 - lazy_load_dylib = 32 - encryption_info = 33 - dyld_info = 34 - version_min_macosx = 36 - version_min_iphoneos = 37 - function_starts = 38 - dyld_environment = 39 - data_in_code = 41 - source_version = 42 - dylib_code_sign_drs = 43 - encryption_info_64 = 44 - linker_option = 45 - linker_optimization_hint = 46 - version_min_tvos = 47 - version_min_watchos = 48 - req_dyld = 2147483648 - load_weak_dylib = 2147483672 - rpath = 2147483676 - reexport_dylib = 2147483679 - dyld_info_only = 2147483682 - load_upward_dylib = 2147483683 - main = 2147483688 - SEQ_FIELDS = ["magic", "header", "load_commands"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = KaitaiStream.resolve_enum(self._root.MagicType, self._io.read_u4be()) - self._debug['magic']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self.header = self._root.MachHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['load_commands']['start'] = self._io.pos() - self.load_commands = [None] * (self.header.ncmds) - for i in range(self.header.ncmds): - if not 'arr' in self._debug['load_commands']: - self._debug['load_commands']['arr'] = [] - self._debug['load_commands']['arr'].append({'start': self._io.pos()}) - _t_load_commands = self._root.LoadCommand(self._io, self, self._root) - _t_load_commands._read() - self.load_commands[i] = _t_load_commands - self._debug['load_commands']['arr'][i]['end'] = self._io.pos() - - self._debug['load_commands']['end'] = self._io.pos() - - class RpathCommand(KaitaiStruct): - SEQ_FIELDS = ["path_offset", "path"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['path_offset']['start'] = self._io.pos() - self.path_offset = self._io.read_u4le() - self._debug['path_offset']['end'] = self._io.pos() - self._debug['path']['start'] = self._io.pos() - self.path = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8") - self._debug['path']['end'] = self._io.pos() - - - class Uleb128(KaitaiStruct): - SEQ_FIELDS = ["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - if (self.b1 & 128) != 0: - self._debug['b2']['start'] = self._io.pos() - self.b2 = self._io.read_u1() - self._debug['b2']['end'] = self._io.pos() - - if (self.b2 & 128) != 0: - self._debug['b3']['start'] = self._io.pos() - self.b3 = self._io.read_u1() - self._debug['b3']['end'] = self._io.pos() - - if (self.b3 & 128) != 0: - self._debug['b4']['start'] = self._io.pos() - self.b4 = self._io.read_u1() - self._debug['b4']['end'] = self._io.pos() - - if (self.b4 & 128) != 0: - self._debug['b5']['start'] = self._io.pos() - self.b5 = self._io.read_u1() - self._debug['b5']['end'] = self._io.pos() - - if (self.b5 & 128) != 0: - self._debug['b6']['start'] = self._io.pos() - self.b6 = self._io.read_u1() - self._debug['b6']['end'] = self._io.pos() - - if (self.b6 & 128) != 0: - self._debug['b7']['start'] = self._io.pos() - self.b7 = self._io.read_u1() - self._debug['b7']['end'] = self._io.pos() - - if (self.b7 & 128) != 0: - self._debug['b8']['start'] = self._io.pos() - self.b8 = self._io.read_u1() - self._debug['b8']['end'] = self._io.pos() - - if (self.b8 & 128) != 0: - self._debug['b9']['start'] = self._io.pos() - self.b9 = self._io.read_u1() - self._debug['b9']['end'] = self._io.pos() - - if (self.b9 & 128) != 0: - self._debug['b10']['start'] = self._io.pos() - self.b10 = self._io.read_u1() - self._debug['b10']['end'] = self._io.pos() - - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (((self.b1 % 128) << 0) + (0 if (self.b1 & 128) == 0 else (((self.b2 % 128) << 7) + (0 if (self.b2 & 128) == 0 else (((self.b3 % 128) << 14) + (0 if (self.b3 & 128) == 0 else (((self.b4 % 128) << 21) + (0 if (self.b4 & 128) == 0 else (((self.b5 % 128) << 28) + (0 if (self.b5 & 128) == 0 else (((self.b6 % 128) << 35) + (0 if (self.b6 & 128) == 0 else (((self.b7 % 128) << 42) + (0 if (self.b7 & 128) == 0 else (((self.b8 % 128) << 49) + (0 if (self.b8 & 128) == 0 else (((self.b9 % 128) << 56) + (0 if (self.b8 & 128) == 0 else ((self.b10 % 128) << 63))))))))))))))))))) - return self._m_value if hasattr(self, '_m_value') else None - - - class SourceVersionCommand(KaitaiStruct): - SEQ_FIELDS = ["version"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u8le() - self._debug['version']['end'] = self._io.pos() - - - class CsBlob(KaitaiStruct): - - class CsMagic(Enum): - blob_wrapper = 4208855809 - requirement = 4208856064 - requirements = 4208856065 - code_directory = 4208856066 - embedded_signature = 4208856256 - detached_signature = 4208856257 - entitlement = 4208882033 - SEQ_FIELDS = ["magic", "length", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = KaitaiStream.resolve_enum(self._root.CsBlob.CsMagic, self._io.read_u4be()) - self._debug['magic']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4be() - self._debug['length']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.magic - if _on == self._root.CsBlob.CsMagic.requirement: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.Requirement(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.code_directory: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.CodeDirectory(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.entitlement: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.Entitlement(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.requirements: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.Requirements(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.blob_wrapper: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.BlobWrapper(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.embedded_signature: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.SuperBlob(io, self, self._root) - self.body._read() - elif _on == self._root.CsBlob.CsMagic.detached_signature: - self._raw_body = self._io.read_bytes((self.length - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CsBlob.SuperBlob(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes((self.length - 8)) - self._debug['body']['end'] = self._io.pos() - - class Entitlement(KaitaiStruct): - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class CodeDirectory(KaitaiStruct): - SEQ_FIELDS = ["version", "flags", "hash_offset", "ident_offset", "n_special_slots", "n_code_slots", "code_limit", "hash_size", "hash_type", "spare1", "page_size", "spare2", "scatter_offset", "team_id_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u4be() - self._debug['version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4be() - self._debug['flags']['end'] = self._io.pos() - self._debug['hash_offset']['start'] = self._io.pos() - self.hash_offset = self._io.read_u4be() - self._debug['hash_offset']['end'] = self._io.pos() - self._debug['ident_offset']['start'] = self._io.pos() - self.ident_offset = self._io.read_u4be() - self._debug['ident_offset']['end'] = self._io.pos() - self._debug['n_special_slots']['start'] = self._io.pos() - self.n_special_slots = self._io.read_u4be() - self._debug['n_special_slots']['end'] = self._io.pos() - self._debug['n_code_slots']['start'] = self._io.pos() - self.n_code_slots = self._io.read_u4be() - self._debug['n_code_slots']['end'] = self._io.pos() - self._debug['code_limit']['start'] = self._io.pos() - self.code_limit = self._io.read_u4be() - self._debug['code_limit']['end'] = self._io.pos() - self._debug['hash_size']['start'] = self._io.pos() - self.hash_size = self._io.read_u1() - self._debug['hash_size']['end'] = self._io.pos() - self._debug['hash_type']['start'] = self._io.pos() - self.hash_type = self._io.read_u1() - self._debug['hash_type']['end'] = self._io.pos() - self._debug['spare1']['start'] = self._io.pos() - self.spare1 = self._io.read_u1() - self._debug['spare1']['end'] = self._io.pos() - self._debug['page_size']['start'] = self._io.pos() - self.page_size = self._io.read_u1() - self._debug['page_size']['end'] = self._io.pos() - self._debug['spare2']['start'] = self._io.pos() - self.spare2 = self._io.read_u4be() - self._debug['spare2']['end'] = self._io.pos() - if self.version >= 131328: - self._debug['scatter_offset']['start'] = self._io.pos() - self.scatter_offset = self._io.read_u4be() - self._debug['scatter_offset']['end'] = self._io.pos() - - if self.version >= 131584: - self._debug['team_id_offset']['start'] = self._io.pos() - self.team_id_offset = self._io.read_u4be() - self._debug['team_id_offset']['end'] = self._io.pos() - - - @property - def ident(self): - if hasattr(self, '_m_ident'): - return self._m_ident if hasattr(self, '_m_ident') else None - - _pos = self._io.pos() - self._io.seek((self.ident_offset - 8)) - self._debug['_m_ident']['start'] = self._io.pos() - self._m_ident = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8") - self._debug['_m_ident']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_ident if hasattr(self, '_m_ident') else None - - @property - def team_id(self): - if hasattr(self, '_m_team_id'): - return self._m_team_id if hasattr(self, '_m_team_id') else None - - _pos = self._io.pos() - self._io.seek((self.team_id_offset - 8)) - self._debug['_m_team_id']['start'] = self._io.pos() - self._m_team_id = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8") - self._debug['_m_team_id']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_team_id if hasattr(self, '_m_team_id') else None - - @property - def hashes(self): - if hasattr(self, '_m_hashes'): - return self._m_hashes if hasattr(self, '_m_hashes') else None - - _pos = self._io.pos() - self._io.seek(((self.hash_offset - 8) - (self.hash_size * self.n_special_slots))) - self._debug['_m_hashes']['start'] = self._io.pos() - self._m_hashes = [None] * ((self.n_special_slots + self.n_code_slots)) - for i in range((self.n_special_slots + self.n_code_slots)): - if not 'arr' in self._debug['_m_hashes']: - self._debug['_m_hashes']['arr'] = [] - self._debug['_m_hashes']['arr'].append({'start': self._io.pos()}) - self._m_hashes[i] = self._io.read_bytes(self.hash_size) - self._debug['_m_hashes']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_hashes']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_hashes if hasattr(self, '_m_hashes') else None - - - class Data(KaitaiStruct): - SEQ_FIELDS = ["length", "value", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4be() - self._debug['length']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.length) - self._debug['value']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes((4 - (self.length & 3))) - self._debug['padding']['end'] = self._io.pos() - - - class SuperBlob(KaitaiStruct): - SEQ_FIELDS = ["count", "blobs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u4be() - self._debug['count']['end'] = self._io.pos() - self._debug['blobs']['start'] = self._io.pos() - self.blobs = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['blobs']: - self._debug['blobs']['arr'] = [] - self._debug['blobs']['arr'].append({'start': self._io.pos()}) - _t_blobs = self._root.CsBlob.BlobIndex(self._io, self, self._root) - _t_blobs._read() - self.blobs[i] = _t_blobs - self._debug['blobs']['arr'][i]['end'] = self._io.pos() - - self._debug['blobs']['end'] = self._io.pos() - - - class Expr(KaitaiStruct): - - class OpEnum(Enum): - false = 0 - true = 1 - ident = 2 - apple_anchor = 3 - anchor_hash = 4 - info_key_value = 5 - and_op = 6 - or_op = 7 - cd_hash = 8 - not_op = 9 - info_key_field = 10 - cert_field = 11 - trusted_cert = 12 - trusted_certs = 13 - cert_generic = 14 - apple_generic_anchor = 15 - entitlement_field = 16 - - class CertSlot(Enum): - left_cert = 0 - anchor_cert = 4294967295 - SEQ_FIELDS = ["op", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['op']['start'] = self._io.pos() - self.op = KaitaiStream.resolve_enum(self._root.CsBlob.Expr.OpEnum, self._io.read_u4be()) - self._debug['op']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - _on = self.op - if _on == self._root.CsBlob.Expr.OpEnum.ident: - self.data = self._root.CsBlob.Expr.IdentExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.or_op: - self.data = self._root.CsBlob.Expr.OrExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.info_key_value: - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.anchor_hash: - self.data = self._root.CsBlob.Expr.AnchorHashExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.info_key_field: - self.data = self._root.CsBlob.Expr.InfoKeyFieldExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.not_op: - self.data = self._root.CsBlob.Expr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.entitlement_field: - self.data = self._root.CsBlob.Expr.EntitlementFieldExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.trusted_cert: - self.data = self._root.CsBlob.Expr.CertSlotExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.and_op: - self.data = self._root.CsBlob.Expr.AndExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.cert_generic: - self.data = self._root.CsBlob.Expr.CertGenericExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.cert_field: - self.data = self._root.CsBlob.Expr.CertFieldExpr(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.cd_hash: - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - elif _on == self._root.CsBlob.Expr.OpEnum.apple_generic_anchor: - self.data = self._root.CsBlob.Expr.AppleGenericAnchorExpr(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - - class InfoKeyFieldExpr(KaitaiStruct): - SEQ_FIELDS = ["data", "match"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - self._debug['match']['start'] = self._io.pos() - self.match = self._root.CsBlob.Match(self._io, self, self._root) - self.match._read() - self._debug['match']['end'] = self._io.pos() - - - class CertSlotExpr(KaitaiStruct): - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = KaitaiStream.resolve_enum(self._root.CsBlob.Expr.CertSlot, self._io.read_u4be()) - self._debug['value']['end'] = self._io.pos() - - - class CertGenericExpr(KaitaiStruct): - SEQ_FIELDS = ["cert_slot", "data", "match"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cert_slot']['start'] = self._io.pos() - self.cert_slot = KaitaiStream.resolve_enum(self._root.CsBlob.Expr.CertSlot, self._io.read_u4be()) - self._debug['cert_slot']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - self._debug['match']['start'] = self._io.pos() - self.match = self._root.CsBlob.Match(self._io, self, self._root) - self.match._read() - self._debug['match']['end'] = self._io.pos() - - - class IdentExpr(KaitaiStruct): - SEQ_FIELDS = ["identifier"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['identifier']['start'] = self._io.pos() - self.identifier = self._root.CsBlob.Data(self._io, self, self._root) - self.identifier._read() - self._debug['identifier']['end'] = self._io.pos() - - - class CertFieldExpr(KaitaiStruct): - SEQ_FIELDS = ["cert_slot", "data", "match"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cert_slot']['start'] = self._io.pos() - self.cert_slot = KaitaiStream.resolve_enum(self._root.CsBlob.Expr.CertSlot, self._io.read_u4be()) - self._debug['cert_slot']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - self._debug['match']['start'] = self._io.pos() - self.match = self._root.CsBlob.Match(self._io, self, self._root) - self.match._read() - self._debug['match']['end'] = self._io.pos() - - - class AnchorHashExpr(KaitaiStruct): - SEQ_FIELDS = ["cert_slot", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cert_slot']['start'] = self._io.pos() - self.cert_slot = KaitaiStream.resolve_enum(self._root.CsBlob.Expr.CertSlot, self._io.read_u4be()) - self._debug['cert_slot']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - - - class AppleGenericAnchorExpr(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = u"anchor apple generic" - return self._m_value if hasattr(self, '_m_value') else None - - - class EntitlementFieldExpr(KaitaiStruct): - SEQ_FIELDS = ["data", "match"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - self._debug['match']['start'] = self._io.pos() - self.match = self._root.CsBlob.Match(self._io, self, self._root) - self.match._read() - self._debug['match']['end'] = self._io.pos() - - - class AndExpr(KaitaiStruct): - SEQ_FIELDS = ["left", "right"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left']['start'] = self._io.pos() - self.left = self._root.CsBlob.Expr(self._io, self, self._root) - self.left._read() - self._debug['left']['end'] = self._io.pos() - self._debug['right']['start'] = self._io.pos() - self.right = self._root.CsBlob.Expr(self._io, self, self._root) - self.right._read() - self._debug['right']['end'] = self._io.pos() - - - class OrExpr(KaitaiStruct): - SEQ_FIELDS = ["left", "right"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left']['start'] = self._io.pos() - self.left = self._root.CsBlob.Expr(self._io, self, self._root) - self.left._read() - self._debug['left']['end'] = self._io.pos() - self._debug['right']['start'] = self._io.pos() - self.right = self._root.CsBlob.Expr(self._io, self, self._root) - self.right._read() - self._debug['right']['end'] = self._io.pos() - - - - class BlobIndex(KaitaiStruct): - - class CsslotType(Enum): - code_directory = 0 - info_slot = 1 - requirements = 2 - resource_dir = 3 - application = 4 - entitlements = 5 - alternate_code_directories = 4096 - signature_slot = 65536 - SEQ_FIELDS = ["type", "offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.CsBlob.BlobIndex.CsslotType, self._io.read_u4be()) - self._debug['type']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4be() - self._debug['offset']['end'] = self._io.pos() - - @property - def blob(self): - if hasattr(self, '_m_blob'): - return self._m_blob if hasattr(self, '_m_blob') else None - - io = self._parent._io - _pos = io.pos() - io.seek((self.offset - 8)) - self._debug['_m_blob']['start'] = io.pos() - self._raw__m_blob = io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw__m_blob)) - self._m_blob = self._root.CsBlob(io, self, self._root) - self._m_blob._read() - self._debug['_m_blob']['end'] = io.pos() - io.seek(_pos) - return self._m_blob if hasattr(self, '_m_blob') else None - - - class Match(KaitaiStruct): - - class Op(Enum): - exists = 0 - equal = 1 - contains = 2 - begins_with = 3 - ends_with = 4 - less_than = 5 - greater_than = 6 - less_equal = 7 - greater_equal = 8 - SEQ_FIELDS = ["match_op", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['match_op']['start'] = self._io.pos() - self.match_op = KaitaiStream.resolve_enum(self._root.CsBlob.Match.Op, self._io.read_u4be()) - self._debug['match_op']['end'] = self._io.pos() - if self.match_op != self._root.CsBlob.Match.Op.exists: - self._debug['data']['start'] = self._io.pos() - self.data = self._root.CsBlob.Data(self._io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - - - - class Requirement(KaitaiStruct): - SEQ_FIELDS = ["kind", "expr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['kind']['start'] = self._io.pos() - self.kind = self._io.read_u4be() - self._debug['kind']['end'] = self._io.pos() - self._debug['expr']['start'] = self._io.pos() - self.expr = self._root.CsBlob.Expr(self._io, self, self._root) - self.expr._read() - self._debug['expr']['end'] = self._io.pos() - - - class Requirements(KaitaiStruct): - SEQ_FIELDS = ["count", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u4be() - self._debug['count']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.CsBlob.RequirementsBlobIndex(self._io, self, self._root) - _t_items._read() - self.items[i] = _t_items - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - - class BlobWrapper(KaitaiStruct): - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class RequirementsBlobIndex(KaitaiStruct): - - class RequirementType(Enum): - host = 1 - guest = 2 - designated = 3 - library = 4 - SEQ_FIELDS = ["type", "offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.CsBlob.RequirementsBlobIndex.RequirementType, self._io.read_u4be()) - self._debug['type']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4be() - self._debug['offset']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - _pos = self._io.pos() - self._io.seek((self.offset - 8)) - self._debug['_m_value']['start'] = self._io.pos() - self._m_value = self._root.CsBlob(self._io, self, self._root) - self._m_value._read() - self._debug['_m_value']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_value if hasattr(self, '_m_value') else None - - - - class RoutinesCommand(KaitaiStruct): - SEQ_FIELDS = ["init_address", "init_module", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['init_address']['start'] = self._io.pos() - self.init_address = self._io.read_u4le() - self._debug['init_address']['end'] = self._io.pos() - self._debug['init_module']['start'] = self._io.pos() - self.init_module = self._io.read_u4le() - self._debug['init_module']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(24) - self._debug['reserved']['end'] = self._io.pos() - - - class MachoFlags(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, value, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.value = value - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def subsections_via_symbols(self): - """safe to divide up the sections into sub-sections via symbols for dead code stripping.""" - if hasattr(self, '_m_subsections_via_symbols'): - return self._m_subsections_via_symbols if hasattr(self, '_m_subsections_via_symbols') else None - - self._m_subsections_via_symbols = (self.value & 8192) != 0 - return self._m_subsections_via_symbols if hasattr(self, '_m_subsections_via_symbols') else None - - @property - def dead_strippable_dylib(self): - if hasattr(self, '_m_dead_strippable_dylib'): - return self._m_dead_strippable_dylib if hasattr(self, '_m_dead_strippable_dylib') else None - - self._m_dead_strippable_dylib = (self.value & 4194304) != 0 - return self._m_dead_strippable_dylib if hasattr(self, '_m_dead_strippable_dylib') else None - - @property - def weak_defines(self): - """the final linked image contains external weak symbols.""" - if hasattr(self, '_m_weak_defines'): - return self._m_weak_defines if hasattr(self, '_m_weak_defines') else None - - self._m_weak_defines = (self.value & 32768) != 0 - return self._m_weak_defines if hasattr(self, '_m_weak_defines') else None - - @property - def prebound(self): - """the file has its dynamic undefined references prebound.""" - if hasattr(self, '_m_prebound'): - return self._m_prebound if hasattr(self, '_m_prebound') else None - - self._m_prebound = (self.value & 16) != 0 - return self._m_prebound if hasattr(self, '_m_prebound') else None - - @property - def all_mods_bound(self): - """indicates that this binary binds to all two-level namespace modules of its dependent libraries. only used when MH_PREBINDABLE and MH_TWOLEVEL are both set.""" - if hasattr(self, '_m_all_mods_bound'): - return self._m_all_mods_bound if hasattr(self, '_m_all_mods_bound') else None - - self._m_all_mods_bound = (self.value & 4096) != 0 - return self._m_all_mods_bound if hasattr(self, '_m_all_mods_bound') else None - - @property - def has_tlv_descriptors(self): - if hasattr(self, '_m_has_tlv_descriptors'): - return self._m_has_tlv_descriptors if hasattr(self, '_m_has_tlv_descriptors') else None - - self._m_has_tlv_descriptors = (self.value & 8388608) != 0 - return self._m_has_tlv_descriptors if hasattr(self, '_m_has_tlv_descriptors') else None - - @property - def force_flat(self): - """the executable is forcing all images to use flat name space bindings.""" - if hasattr(self, '_m_force_flat'): - return self._m_force_flat if hasattr(self, '_m_force_flat') else None - - self._m_force_flat = (self.value & 256) != 0 - return self._m_force_flat if hasattr(self, '_m_force_flat') else None - - @property - def root_safe(self): - """When this bit is set, the binary declares it is safe for use in processes with uid zero.""" - if hasattr(self, '_m_root_safe'): - return self._m_root_safe if hasattr(self, '_m_root_safe') else None - - self._m_root_safe = (self.value & 262144) != 0 - return self._m_root_safe if hasattr(self, '_m_root_safe') else None - - @property - def no_undefs(self): - """the object file has no undefined references.""" - if hasattr(self, '_m_no_undefs'): - return self._m_no_undefs if hasattr(self, '_m_no_undefs') else None - - self._m_no_undefs = (self.value & 1) != 0 - return self._m_no_undefs if hasattr(self, '_m_no_undefs') else None - - @property - def setuid_safe(self): - """When this bit is set, the binary declares it is safe for use in processes when issetugid() is true.""" - if hasattr(self, '_m_setuid_safe'): - return self._m_setuid_safe if hasattr(self, '_m_setuid_safe') else None - - self._m_setuid_safe = (self.value & 524288) != 0 - return self._m_setuid_safe if hasattr(self, '_m_setuid_safe') else None - - @property - def no_heap_execution(self): - if hasattr(self, '_m_no_heap_execution'): - return self._m_no_heap_execution if hasattr(self, '_m_no_heap_execution') else None - - self._m_no_heap_execution = (self.value & 16777216) != 0 - return self._m_no_heap_execution if hasattr(self, '_m_no_heap_execution') else None - - @property - def no_reexported_dylibs(self): - """When this bit is set on a dylib, the static linker does not need to examine dependent dylibs to see if any are re-exported.""" - if hasattr(self, '_m_no_reexported_dylibs'): - return self._m_no_reexported_dylibs if hasattr(self, '_m_no_reexported_dylibs') else None - - self._m_no_reexported_dylibs = (self.value & 1048576) != 0 - return self._m_no_reexported_dylibs if hasattr(self, '_m_no_reexported_dylibs') else None - - @property - def no_multi_defs(self): - """this umbrella guarantees no multiple defintions of symbols in its sub-images so the two-level namespace hints can always be used.""" - if hasattr(self, '_m_no_multi_defs'): - return self._m_no_multi_defs if hasattr(self, '_m_no_multi_defs') else None - - self._m_no_multi_defs = (self.value & 512) != 0 - return self._m_no_multi_defs if hasattr(self, '_m_no_multi_defs') else None - - @property - def app_extension_safe(self): - if hasattr(self, '_m_app_extension_safe'): - return self._m_app_extension_safe if hasattr(self, '_m_app_extension_safe') else None - - self._m_app_extension_safe = (self.value & 33554432) != 0 - return self._m_app_extension_safe if hasattr(self, '_m_app_extension_safe') else None - - @property - def prebindable(self): - """the binary is not prebound but can have its prebinding redone. only used when MH_PREBOUND is not set.""" - if hasattr(self, '_m_prebindable'): - return self._m_prebindable if hasattr(self, '_m_prebindable') else None - - self._m_prebindable = (self.value & 2048) != 0 - return self._m_prebindable if hasattr(self, '_m_prebindable') else None - - @property - def incr_link(self): - """the object file is the output of an incremental link against a base file and can't be link edited again.""" - if hasattr(self, '_m_incr_link'): - return self._m_incr_link if hasattr(self, '_m_incr_link') else None - - self._m_incr_link = (self.value & 2) != 0 - return self._m_incr_link if hasattr(self, '_m_incr_link') else None - - @property - def bind_at_load(self): - """the object file's undefined references are bound by the dynamic linker when loaded.""" - if hasattr(self, '_m_bind_at_load'): - return self._m_bind_at_load if hasattr(self, '_m_bind_at_load') else None - - self._m_bind_at_load = (self.value & 8) != 0 - return self._m_bind_at_load if hasattr(self, '_m_bind_at_load') else None - - @property - def canonical(self): - """the binary has been canonicalized via the unprebind operation.""" - if hasattr(self, '_m_canonical'): - return self._m_canonical if hasattr(self, '_m_canonical') else None - - self._m_canonical = (self.value & 16384) != 0 - return self._m_canonical if hasattr(self, '_m_canonical') else None - - @property - def two_level(self): - """the image is using two-level name space bindings.""" - if hasattr(self, '_m_two_level'): - return self._m_two_level if hasattr(self, '_m_two_level') else None - - self._m_two_level = (self.value & 128) != 0 - return self._m_two_level if hasattr(self, '_m_two_level') else None - - @property - def split_segs(self): - """the file has its read-only and read-write segments split.""" - if hasattr(self, '_m_split_segs'): - return self._m_split_segs if hasattr(self, '_m_split_segs') else None - - self._m_split_segs = (self.value & 32) != 0 - return self._m_split_segs if hasattr(self, '_m_split_segs') else None - - @property - def lazy_init(self): - """the shared library init routine is to be run lazily via catching memory faults to its writeable segments (obsolete).""" - if hasattr(self, '_m_lazy_init'): - return self._m_lazy_init if hasattr(self, '_m_lazy_init') else None - - self._m_lazy_init = (self.value & 64) != 0 - return self._m_lazy_init if hasattr(self, '_m_lazy_init') else None - - @property - def allow_stack_execution(self): - """When this bit is set, all stacks in the task will be given stack execution privilege. Only used in MH_EXECUTE filetypes.""" - if hasattr(self, '_m_allow_stack_execution'): - return self._m_allow_stack_execution if hasattr(self, '_m_allow_stack_execution') else None - - self._m_allow_stack_execution = (self.value & 131072) != 0 - return self._m_allow_stack_execution if hasattr(self, '_m_allow_stack_execution') else None - - @property - def binds_to_weak(self): - """the final linked image uses weak symbols.""" - if hasattr(self, '_m_binds_to_weak'): - return self._m_binds_to_weak if hasattr(self, '_m_binds_to_weak') else None - - self._m_binds_to_weak = (self.value & 65536) != 0 - return self._m_binds_to_weak if hasattr(self, '_m_binds_to_weak') else None - - @property - def no_fix_prebinding(self): - """do not have dyld notify the prebinding agent about this executable.""" - if hasattr(self, '_m_no_fix_prebinding'): - return self._m_no_fix_prebinding if hasattr(self, '_m_no_fix_prebinding') else None - - self._m_no_fix_prebinding = (self.value & 1024) != 0 - return self._m_no_fix_prebinding if hasattr(self, '_m_no_fix_prebinding') else None - - @property - def dyld_link(self): - """the object file is input for the dynamic linker and can't be staticly link edited again.""" - if hasattr(self, '_m_dyld_link'): - return self._m_dyld_link if hasattr(self, '_m_dyld_link') else None - - self._m_dyld_link = (self.value & 4) != 0 - return self._m_dyld_link if hasattr(self, '_m_dyld_link') else None - - @property - def pie(self): - """When this bit is set, the OS will load the main executable at a random address. Only used in MH_EXECUTE filetypes.""" - if hasattr(self, '_m_pie'): - return self._m_pie if hasattr(self, '_m_pie') else None - - self._m_pie = (self.value & 2097152) != 0 - return self._m_pie if hasattr(self, '_m_pie') else None - - - class RoutinesCommand64(KaitaiStruct): - SEQ_FIELDS = ["init_address", "init_module", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['init_address']['start'] = self._io.pos() - self.init_address = self._io.read_u8le() - self._debug['init_address']['end'] = self._io.pos() - self._debug['init_module']['start'] = self._io.pos() - self.init_module = self._io.read_u8le() - self._debug['init_module']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(48) - self._debug['reserved']['end'] = self._io.pos() - - - class LinkerOptionCommand(KaitaiStruct): - SEQ_FIELDS = ["num_strings", "strings"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_strings']['start'] = self._io.pos() - self.num_strings = self._io.read_u4le() - self._debug['num_strings']['end'] = self._io.pos() - self._debug['strings']['start'] = self._io.pos() - self.strings = [None] * (self.num_strings) - for i in range(self.num_strings): - if not 'arr' in self._debug['strings']: - self._debug['strings']['arr'] = [] - self._debug['strings']['arr'].append({'start': self._io.pos()}) - self.strings[i] = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8") - self._debug['strings']['arr'][i]['end'] = self._io.pos() - - self._debug['strings']['end'] = self._io.pos() - - - class SegmentCommand64(KaitaiStruct): - SEQ_FIELDS = ["segname", "vmaddr", "vmsize", "fileoff", "filesize", "maxprot", "initprot", "nsects", "flags", "sections"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['segname']['start'] = self._io.pos() - self.segname = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii") - self._debug['segname']['end'] = self._io.pos() - self._debug['vmaddr']['start'] = self._io.pos() - self.vmaddr = self._io.read_u8le() - self._debug['vmaddr']['end'] = self._io.pos() - self._debug['vmsize']['start'] = self._io.pos() - self.vmsize = self._io.read_u8le() - self._debug['vmsize']['end'] = self._io.pos() - self._debug['fileoff']['start'] = self._io.pos() - self.fileoff = self._io.read_u8le() - self._debug['fileoff']['end'] = self._io.pos() - self._debug['filesize']['start'] = self._io.pos() - self.filesize = self._io.read_u8le() - self._debug['filesize']['end'] = self._io.pos() - self._debug['maxprot']['start'] = self._io.pos() - self.maxprot = self._root.VmProt(self._io, self, self._root) - self.maxprot._read() - self._debug['maxprot']['end'] = self._io.pos() - self._debug['initprot']['start'] = self._io.pos() - self.initprot = self._root.VmProt(self._io, self, self._root) - self.initprot._read() - self._debug['initprot']['end'] = self._io.pos() - self._debug['nsects']['start'] = self._io.pos() - self.nsects = self._io.read_u4le() - self._debug['nsects']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['sections']['start'] = self._io.pos() - self.sections = [None] * (self.nsects) - for i in range(self.nsects): - if not 'arr' in self._debug['sections']: - self._debug['sections']['arr'] = [] - self._debug['sections']['arr'].append({'start': self._io.pos()}) - _t_sections = self._root.SegmentCommand64.Section64(self._io, self, self._root) - _t_sections._read() - self.sections[i] = _t_sections - self._debug['sections']['arr'][i]['end'] = self._io.pos() - - self._debug['sections']['end'] = self._io.pos() - - class Section64(KaitaiStruct): - SEQ_FIELDS = ["sect_name", "seg_name", "addr", "size", "offset", "align", "reloff", "nreloc", "flags", "reserved1", "reserved2", "reserved3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sect_name']['start'] = self._io.pos() - self.sect_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii") - self._debug['sect_name']['end'] = self._io.pos() - self._debug['seg_name']['start'] = self._io.pos() - self.seg_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii") - self._debug['seg_name']['end'] = self._io.pos() - self._debug['addr']['start'] = self._io.pos() - self.addr = self._io.read_u8le() - self._debug['addr']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u8le() - self._debug['size']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['end'] = self._io.pos() - self._debug['align']['start'] = self._io.pos() - self.align = self._io.read_u4le() - self._debug['align']['end'] = self._io.pos() - self._debug['reloff']['start'] = self._io.pos() - self.reloff = self._io.read_u4le() - self._debug['reloff']['end'] = self._io.pos() - self._debug['nreloc']['start'] = self._io.pos() - self.nreloc = self._io.read_u4le() - self._debug['nreloc']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_u4le() - self._debug['reserved1']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_u4le() - self._debug['reserved2']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_u4le() - self._debug['reserved3']['end'] = self._io.pos() - - class CfStringList(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.SegmentCommand64.Section64.CfString(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - class CfString(KaitaiStruct): - SEQ_FIELDS = ["isa", "info", "data", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['isa']['start'] = self._io.pos() - self.isa = self._io.read_u8le() - self._debug['isa']['end'] = self._io.pos() - self._debug['info']['start'] = self._io.pos() - self.info = self._io.read_u8le() - self._debug['info']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_u8le() - self._debug['data']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u8le() - self._debug['length']['end'] = self._io.pos() - - - class EhFrameItem(KaitaiStruct): - SEQ_FIELDS = ["length", "length64", "id", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - if self.length == 4294967295: - self._debug['length64']['start'] = self._io.pos() - self.length64 = self._io.read_u8le() - self._debug['length64']['end'] = self._io.pos() - - self._debug['id']['start'] = self._io.pos() - self.id = self._io.read_u4le() - self._debug['id']['end'] = self._io.pos() - if self.length > 0: - self._debug['body']['start'] = self._io.pos() - _on = self.id - if _on == 0: - self._raw_body = self._io.read_bytes((self.length - 4)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SegmentCommand64.Section64.EhFrameItem.Cie(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes((self.length - 4)) - self._debug['body']['end'] = self._io.pos() - - - class CharChain(KaitaiStruct): - SEQ_FIELDS = ["chr", "next"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['chr']['start'] = self._io.pos() - self.chr = self._io.read_u1() - self._debug['chr']['end'] = self._io.pos() - if self.chr != 0: - self._debug['next']['start'] = self._io.pos() - self.next = self._root.SegmentCommand64.Section64.EhFrameItem.CharChain(self._io, self, self._root) - self.next._read() - self._debug['next']['end'] = self._io.pos() - - - - class Cie(KaitaiStruct): - SEQ_FIELDS = ["version", "aug_str", "code_alignment_factor", "data_alignment_factor", "return_address_register", "augmentation"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['aug_str']['start'] = self._io.pos() - self.aug_str = self._root.SegmentCommand64.Section64.EhFrameItem.CharChain(self._io, self, self._root) - self.aug_str._read() - self._debug['aug_str']['end'] = self._io.pos() - self._debug['code_alignment_factor']['start'] = self._io.pos() - self.code_alignment_factor = self._root.Uleb128(self._io, self, self._root) - self.code_alignment_factor._read() - self._debug['code_alignment_factor']['end'] = self._io.pos() - self._debug['data_alignment_factor']['start'] = self._io.pos() - self.data_alignment_factor = self._root.Uleb128(self._io, self, self._root) - self.data_alignment_factor._read() - self._debug['data_alignment_factor']['end'] = self._io.pos() - self._debug['return_address_register']['start'] = self._io.pos() - self.return_address_register = self._io.read_u1() - self._debug['return_address_register']['end'] = self._io.pos() - if self.aug_str.chr == 122: - self._debug['augmentation']['start'] = self._io.pos() - self.augmentation = self._root.SegmentCommand64.Section64.EhFrameItem.AugmentationEntry(self._io, self, self._root) - self.augmentation._read() - self._debug['augmentation']['end'] = self._io.pos() - - - - class AugmentationEntry(KaitaiStruct): - SEQ_FIELDS = ["length", "fde_pointer_encoding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._root.Uleb128(self._io, self, self._root) - self.length._read() - self._debug['length']['end'] = self._io.pos() - if self._parent.aug_str.next.chr == 82: - self._debug['fde_pointer_encoding']['start'] = self._io.pos() - self.fde_pointer_encoding = self._io.read_u1() - self._debug['fde_pointer_encoding']['end'] = self._io.pos() - - - - - class EhFrame(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.SegmentCommand64.Section64.EhFrameItem(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - class PointerList(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items.append(self._io.read_u8le()) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - class StringList(KaitaiStruct): - SEQ_FIELDS = ["strings"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['strings']['start'] = self._io.pos() - self.strings = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['strings']: - self._debug['strings']['arr'] = [] - self._debug['strings']['arr'].append({'start': self._io.pos()}) - self.strings.append((self._io.read_bytes_term(0, False, True, True)).decode(u"ascii")) - self._debug['strings']['arr'][len(self.strings) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['strings']['end'] = self._io.pos() - - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_data']['start'] = io.pos() - _on = self.sect_name - if _on == u"__objc_nlclslist": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_methname": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.StringList(io, self, self._root) - self._m_data._read() - elif _on == u"__nl_symbol_ptr": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__la_symbol_ptr": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_selrefs": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__cstring": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.StringList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_classlist": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_protolist": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_imageinfo": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_methtype": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.StringList(io, self, self._root) - self._m_data._read() - elif _on == u"__cfstring": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.CfStringList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_classrefs": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_protorefs": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_classname": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.StringList(io, self, self._root) - self._m_data._read() - elif _on == u"__got": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - elif _on == u"__eh_frame": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.EhFrame(io, self, self._root) - self._m_data._read() - elif _on == u"__objc_superrefs": - self._raw__m_data = io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SegmentCommand64.Section64.PointerList(io, self, self._root) - self._m_data._read() - else: - self._m_data = io.read_bytes(self.size) - self._debug['_m_data']['end'] = io.pos() - io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - - class VmProt(KaitaiStruct): - SEQ_FIELDS = ["strip_read", "is_mask", "reserved0", "copy", "no_change", "execute", "write", "read", "reserved1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['strip_read']['start'] = self._io.pos() - self.strip_read = self._io.read_bits_int(1) != 0 - self._debug['strip_read']['end'] = self._io.pos() - self._debug['is_mask']['start'] = self._io.pos() - self.is_mask = self._io.read_bits_int(1) != 0 - self._debug['is_mask']['end'] = self._io.pos() - self._debug['reserved0']['start'] = self._io.pos() - self.reserved0 = self._io.read_bits_int(1) != 0 - self._debug['reserved0']['end'] = self._io.pos() - self._debug['copy']['start'] = self._io.pos() - self.copy = self._io.read_bits_int(1) != 0 - self._debug['copy']['end'] = self._io.pos() - self._debug['no_change']['start'] = self._io.pos() - self.no_change = self._io.read_bits_int(1) != 0 - self._debug['no_change']['end'] = self._io.pos() - self._debug['execute']['start'] = self._io.pos() - self.execute = self._io.read_bits_int(1) != 0 - self._debug['execute']['end'] = self._io.pos() - self._debug['write']['start'] = self._io.pos() - self.write = self._io.read_bits_int(1) != 0 - self._debug['write']['end'] = self._io.pos() - self._debug['read']['start'] = self._io.pos() - self.read = self._io.read_bits_int(1) != 0 - self._debug['read']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(24) - self._debug['reserved1']['end'] = self._io.pos() - - - class DysymtabCommand(KaitaiStruct): - SEQ_FIELDS = ["i_local_sym", "n_local_sym", "i_ext_def_sym", "n_ext_def_sym", "i_undef_sym", "n_undef_sym", "toc_off", "n_toc", "mod_tab_off", "n_mod_tab", "ext_ref_sym_off", "n_ext_ref_syms", "indirect_sym_off", "n_indirect_syms", "ext_rel_off", "n_ext_rel", "loc_rel_off", "n_loc_rel"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['i_local_sym']['start'] = self._io.pos() - self.i_local_sym = self._io.read_u4le() - self._debug['i_local_sym']['end'] = self._io.pos() - self._debug['n_local_sym']['start'] = self._io.pos() - self.n_local_sym = self._io.read_u4le() - self._debug['n_local_sym']['end'] = self._io.pos() - self._debug['i_ext_def_sym']['start'] = self._io.pos() - self.i_ext_def_sym = self._io.read_u4le() - self._debug['i_ext_def_sym']['end'] = self._io.pos() - self._debug['n_ext_def_sym']['start'] = self._io.pos() - self.n_ext_def_sym = self._io.read_u4le() - self._debug['n_ext_def_sym']['end'] = self._io.pos() - self._debug['i_undef_sym']['start'] = self._io.pos() - self.i_undef_sym = self._io.read_u4le() - self._debug['i_undef_sym']['end'] = self._io.pos() - self._debug['n_undef_sym']['start'] = self._io.pos() - self.n_undef_sym = self._io.read_u4le() - self._debug['n_undef_sym']['end'] = self._io.pos() - self._debug['toc_off']['start'] = self._io.pos() - self.toc_off = self._io.read_u4le() - self._debug['toc_off']['end'] = self._io.pos() - self._debug['n_toc']['start'] = self._io.pos() - self.n_toc = self._io.read_u4le() - self._debug['n_toc']['end'] = self._io.pos() - self._debug['mod_tab_off']['start'] = self._io.pos() - self.mod_tab_off = self._io.read_u4le() - self._debug['mod_tab_off']['end'] = self._io.pos() - self._debug['n_mod_tab']['start'] = self._io.pos() - self.n_mod_tab = self._io.read_u4le() - self._debug['n_mod_tab']['end'] = self._io.pos() - self._debug['ext_ref_sym_off']['start'] = self._io.pos() - self.ext_ref_sym_off = self._io.read_u4le() - self._debug['ext_ref_sym_off']['end'] = self._io.pos() - self._debug['n_ext_ref_syms']['start'] = self._io.pos() - self.n_ext_ref_syms = self._io.read_u4le() - self._debug['n_ext_ref_syms']['end'] = self._io.pos() - self._debug['indirect_sym_off']['start'] = self._io.pos() - self.indirect_sym_off = self._io.read_u4le() - self._debug['indirect_sym_off']['end'] = self._io.pos() - self._debug['n_indirect_syms']['start'] = self._io.pos() - self.n_indirect_syms = self._io.read_u4le() - self._debug['n_indirect_syms']['end'] = self._io.pos() - self._debug['ext_rel_off']['start'] = self._io.pos() - self.ext_rel_off = self._io.read_u4le() - self._debug['ext_rel_off']['end'] = self._io.pos() - self._debug['n_ext_rel']['start'] = self._io.pos() - self.n_ext_rel = self._io.read_u4le() - self._debug['n_ext_rel']['end'] = self._io.pos() - self._debug['loc_rel_off']['start'] = self._io.pos() - self.loc_rel_off = self._io.read_u4le() - self._debug['loc_rel_off']['end'] = self._io.pos() - self._debug['n_loc_rel']['start'] = self._io.pos() - self.n_loc_rel = self._io.read_u4le() - self._debug['n_loc_rel']['end'] = self._io.pos() - - @property - def indirect_symbols(self): - if hasattr(self, '_m_indirect_symbols'): - return self._m_indirect_symbols if hasattr(self, '_m_indirect_symbols') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.indirect_sym_off) - self._debug['_m_indirect_symbols']['start'] = io.pos() - self._m_indirect_symbols = [None] * (self.n_indirect_syms) - for i in range(self.n_indirect_syms): - if not 'arr' in self._debug['_m_indirect_symbols']: - self._debug['_m_indirect_symbols']['arr'] = [] - self._debug['_m_indirect_symbols']['arr'].append({'start': io.pos()}) - self._m_indirect_symbols[i] = io.read_u4le() - self._debug['_m_indirect_symbols']['arr'][i]['end'] = io.pos() - - self._debug['_m_indirect_symbols']['end'] = io.pos() - io.seek(_pos) - return self._m_indirect_symbols if hasattr(self, '_m_indirect_symbols') else None - - - class MachHeader(KaitaiStruct): - SEQ_FIELDS = ["cputype", "cpusubtype", "filetype", "ncmds", "sizeofcmds", "flags", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cputype']['start'] = self._io.pos() - self.cputype = KaitaiStream.resolve_enum(self._root.CpuType, self._io.read_u4le()) - self._debug['cputype']['end'] = self._io.pos() - self._debug['cpusubtype']['start'] = self._io.pos() - self.cpusubtype = self._io.read_u4le() - self._debug['cpusubtype']['end'] = self._io.pos() - self._debug['filetype']['start'] = self._io.pos() - self.filetype = KaitaiStream.resolve_enum(self._root.FileType, self._io.read_u4le()) - self._debug['filetype']['end'] = self._io.pos() - self._debug['ncmds']['start'] = self._io.pos() - self.ncmds = self._io.read_u4le() - self._debug['ncmds']['end'] = self._io.pos() - self._debug['sizeofcmds']['start'] = self._io.pos() - self.sizeofcmds = self._io.read_u4le() - self._debug['sizeofcmds']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - if ((self._root.magic == self._root.MagicType.macho_be_x64) or (self._root.magic == self._root.MagicType.macho_le_x64)) : - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u4le() - self._debug['reserved']['end'] = self._io.pos() - - - @property - def flags_obj(self): - if hasattr(self, '_m_flags_obj'): - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - self._debug['_m_flags_obj']['start'] = self._io.pos() - self._m_flags_obj = self._root.MachoFlags(self.flags, self._io, self, self._root) - self._m_flags_obj._read() - self._debug['_m_flags_obj']['end'] = self._io.pos() - return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None - - - class LinkeditDataCommand(KaitaiStruct): - SEQ_FIELDS = ["data_off", "data_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data_off']['start'] = self._io.pos() - self.data_off = self._io.read_u4le() - self._debug['data_off']['end'] = self._io.pos() - self._debug['data_size']['start'] = self._io.pos() - self.data_size = self._io.read_u4le() - self._debug['data_size']['end'] = self._io.pos() - - - class SubCommand(KaitaiStruct): - SEQ_FIELDS = ["name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.LcStr(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - - - class TwolevelHintsCommand(KaitaiStruct): - SEQ_FIELDS = ["offset", "num_hints"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['end'] = self._io.pos() - self._debug['num_hints']['start'] = self._io.pos() - self.num_hints = self._io.read_u4le() - self._debug['num_hints']['end'] = self._io.pos() - - - class Version(KaitaiStruct): - SEQ_FIELDS = ["p1", "minor", "major", "release"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['p1']['start'] = self._io.pos() - self.p1 = self._io.read_u1() - self._debug['p1']['end'] = self._io.pos() - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u1() - self._debug['minor']['end'] = self._io.pos() - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u1() - self._debug['major']['end'] = self._io.pos() - self._debug['release']['start'] = self._io.pos() - self.release = self._io.read_u1() - self._debug['release']['end'] = self._io.pos() - - - class EncryptionInfoCommand(KaitaiStruct): - SEQ_FIELDS = ["cryptoff", "cryptsize", "cryptid", "pad"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cryptoff']['start'] = self._io.pos() - self.cryptoff = self._io.read_u4le() - self._debug['cryptoff']['end'] = self._io.pos() - self._debug['cryptsize']['start'] = self._io.pos() - self.cryptsize = self._io.read_u4le() - self._debug['cryptsize']['end'] = self._io.pos() - self._debug['cryptid']['start'] = self._io.pos() - self.cryptid = self._io.read_u4le() - self._debug['cryptid']['end'] = self._io.pos() - if ((self._root.magic == self._root.MagicType.macho_be_x64) or (self._root.magic == self._root.MagicType.macho_le_x64)) : - self._debug['pad']['start'] = self._io.pos() - self.pad = self._io.read_u4le() - self._debug['pad']['end'] = self._io.pos() - - - - class CodeSignatureCommand(KaitaiStruct): - SEQ_FIELDS = ["data_off", "data_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data_off']['start'] = self._io.pos() - self.data_off = self._io.read_u4le() - self._debug['data_off']['end'] = self._io.pos() - self._debug['data_size']['start'] = self._io.pos() - self.data_size = self._io.read_u4le() - self._debug['data_size']['end'] = self._io.pos() - - @property - def code_signature(self): - if hasattr(self, '_m_code_signature'): - return self._m_code_signature if hasattr(self, '_m_code_signature') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.data_off) - self._debug['_m_code_signature']['start'] = io.pos() - self._raw__m_code_signature = io.read_bytes(self.data_size) - io = KaitaiStream(BytesIO(self._raw__m_code_signature)) - self._m_code_signature = self._root.CsBlob(io, self, self._root) - self._m_code_signature._read() - self._debug['_m_code_signature']['end'] = io.pos() - io.seek(_pos) - return self._m_code_signature if hasattr(self, '_m_code_signature') else None - - - class DyldInfoCommand(KaitaiStruct): - - class BindOpcode(Enum): - done = 0 - set_dylib_ordinal_immediate = 16 - set_dylib_ordinal_uleb = 32 - set_dylib_special_immediate = 48 - set_symbol_trailing_flags_immediate = 64 - set_type_immediate = 80 - set_append_sleb = 96 - set_segment_and_offset_uleb = 112 - add_address_uleb = 128 - do_bind = 144 - do_bind_add_address_uleb = 160 - do_bind_add_address_immediate_scaled = 176 - do_bind_uleb_times_skipping_uleb = 192 - SEQ_FIELDS = ["rebase_off", "rebase_size", "bind_off", "bind_size", "weak_bind_off", "weak_bind_size", "lazy_bind_off", "lazy_bind_size", "export_off", "export_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['rebase_off']['start'] = self._io.pos() - self.rebase_off = self._io.read_u4le() - self._debug['rebase_off']['end'] = self._io.pos() - self._debug['rebase_size']['start'] = self._io.pos() - self.rebase_size = self._io.read_u4le() - self._debug['rebase_size']['end'] = self._io.pos() - self._debug['bind_off']['start'] = self._io.pos() - self.bind_off = self._io.read_u4le() - self._debug['bind_off']['end'] = self._io.pos() - self._debug['bind_size']['start'] = self._io.pos() - self.bind_size = self._io.read_u4le() - self._debug['bind_size']['end'] = self._io.pos() - self._debug['weak_bind_off']['start'] = self._io.pos() - self.weak_bind_off = self._io.read_u4le() - self._debug['weak_bind_off']['end'] = self._io.pos() - self._debug['weak_bind_size']['start'] = self._io.pos() - self.weak_bind_size = self._io.read_u4le() - self._debug['weak_bind_size']['end'] = self._io.pos() - self._debug['lazy_bind_off']['start'] = self._io.pos() - self.lazy_bind_off = self._io.read_u4le() - self._debug['lazy_bind_off']['end'] = self._io.pos() - self._debug['lazy_bind_size']['start'] = self._io.pos() - self.lazy_bind_size = self._io.read_u4le() - self._debug['lazy_bind_size']['end'] = self._io.pos() - self._debug['export_off']['start'] = self._io.pos() - self.export_off = self._io.read_u4le() - self._debug['export_off']['end'] = self._io.pos() - self._debug['export_size']['start'] = self._io.pos() - self.export_size = self._io.read_u4le() - self._debug['export_size']['end'] = self._io.pos() - - class BindItem(KaitaiStruct): - SEQ_FIELDS = ["opcode_and_immediate", "uleb", "skip", "symbol"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['opcode_and_immediate']['start'] = self._io.pos() - self.opcode_and_immediate = self._io.read_u1() - self._debug['opcode_and_immediate']['end'] = self._io.pos() - if ((self.opcode == self._root.DyldInfoCommand.BindOpcode.set_dylib_ordinal_uleb) or (self.opcode == self._root.DyldInfoCommand.BindOpcode.set_append_sleb) or (self.opcode == self._root.DyldInfoCommand.BindOpcode.set_segment_and_offset_uleb) or (self.opcode == self._root.DyldInfoCommand.BindOpcode.add_address_uleb) or (self.opcode == self._root.DyldInfoCommand.BindOpcode.do_bind_add_address_uleb) or (self.opcode == self._root.DyldInfoCommand.BindOpcode.do_bind_uleb_times_skipping_uleb)) : - self._debug['uleb']['start'] = self._io.pos() - self.uleb = self._root.Uleb128(self._io, self, self._root) - self.uleb._read() - self._debug['uleb']['end'] = self._io.pos() - - if self.opcode == self._root.DyldInfoCommand.BindOpcode.do_bind_uleb_times_skipping_uleb: - self._debug['skip']['start'] = self._io.pos() - self.skip = self._root.Uleb128(self._io, self, self._root) - self.skip._read() - self._debug['skip']['end'] = self._io.pos() - - if self.opcode == self._root.DyldInfoCommand.BindOpcode.set_symbol_trailing_flags_immediate: - self._debug['symbol']['start'] = self._io.pos() - self.symbol = (self._io.read_bytes_term(0, False, True, True)).decode(u"ascii") - self._debug['symbol']['end'] = self._io.pos() - - - @property - def opcode(self): - if hasattr(self, '_m_opcode'): - return self._m_opcode if hasattr(self, '_m_opcode') else None - - self._m_opcode = KaitaiStream.resolve_enum(self._root.DyldInfoCommand.BindOpcode, (self.opcode_and_immediate & 240)) - return self._m_opcode if hasattr(self, '_m_opcode') else None - - @property - def immediate(self): - if hasattr(self, '_m_immediate'): - return self._m_immediate if hasattr(self, '_m_immediate') else None - - self._m_immediate = (self.opcode_and_immediate & 15) - return self._m_immediate if hasattr(self, '_m_immediate') else None - - - class RebaseData(KaitaiStruct): - - class Opcode(Enum): - done = 0 - set_type_immediate = 16 - set_segment_and_offset_uleb = 32 - add_address_uleb = 48 - add_address_immediate_scaled = 64 - do_rebase_immediate_times = 80 - do_rebase_uleb_times = 96 - do_rebase_add_address_uleb = 112 - do_rebase_uleb_times_skipping_uleb = 128 - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.DyldInfoCommand.RebaseData.RebaseItem(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.done: - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - class RebaseItem(KaitaiStruct): - SEQ_FIELDS = ["opcode_and_immediate", "uleb", "skip"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['opcode_and_immediate']['start'] = self._io.pos() - self.opcode_and_immediate = self._io.read_u1() - self._debug['opcode_and_immediate']['end'] = self._io.pos() - if ((self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.set_segment_and_offset_uleb) or (self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.add_address_uleb) or (self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times) or (self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.do_rebase_add_address_uleb) or (self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times_skipping_uleb)) : - self._debug['uleb']['start'] = self._io.pos() - self.uleb = self._root.Uleb128(self._io, self, self._root) - self.uleb._read() - self._debug['uleb']['end'] = self._io.pos() - - if self.opcode == self._root.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times_skipping_uleb: - self._debug['skip']['start'] = self._io.pos() - self.skip = self._root.Uleb128(self._io, self, self._root) - self.skip._read() - self._debug['skip']['end'] = self._io.pos() - - - @property - def opcode(self): - if hasattr(self, '_m_opcode'): - return self._m_opcode if hasattr(self, '_m_opcode') else None - - self._m_opcode = KaitaiStream.resolve_enum(self._root.DyldInfoCommand.RebaseData.Opcode, (self.opcode_and_immediate & 240)) - return self._m_opcode if hasattr(self, '_m_opcode') else None - - @property - def immediate(self): - if hasattr(self, '_m_immediate'): - return self._m_immediate if hasattr(self, '_m_immediate') else None - - self._m_immediate = (self.opcode_and_immediate & 15) - return self._m_immediate if hasattr(self, '_m_immediate') else None - - - - class ExportNode(KaitaiStruct): - SEQ_FIELDS = ["terminal_size", "children_count", "children", "terminal"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['terminal_size']['start'] = self._io.pos() - self.terminal_size = self._root.Uleb128(self._io, self, self._root) - self.terminal_size._read() - self._debug['terminal_size']['end'] = self._io.pos() - self._debug['children_count']['start'] = self._io.pos() - self.children_count = self._io.read_u1() - self._debug['children_count']['end'] = self._io.pos() - self._debug['children']['start'] = self._io.pos() - self.children = [None] * (self.children_count) - for i in range(self.children_count): - if not 'arr' in self._debug['children']: - self._debug['children']['arr'] = [] - self._debug['children']['arr'].append({'start': self._io.pos()}) - _t_children = self._root.DyldInfoCommand.ExportNode.Child(self._io, self, self._root) - _t_children._read() - self.children[i] = _t_children - self._debug['children']['arr'][i]['end'] = self._io.pos() - - self._debug['children']['end'] = self._io.pos() - self._debug['terminal']['start'] = self._io.pos() - self.terminal = self._io.read_bytes(self.terminal_size.value) - self._debug['terminal']['end'] = self._io.pos() - - class Child(KaitaiStruct): - SEQ_FIELDS = ["name", "node_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ascii") - self._debug['name']['end'] = self._io.pos() - self._debug['node_offset']['start'] = self._io.pos() - self.node_offset = self._root.Uleb128(self._io, self, self._root) - self.node_offset._read() - self._debug['node_offset']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - _pos = self._io.pos() - self._io.seek(self.node_offset.value) - self._debug['_m_value']['start'] = self._io.pos() - self._m_value = self._root.DyldInfoCommand.ExportNode(self._io, self, self._root) - self._m_value._read() - self._debug['_m_value']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_value if hasattr(self, '_m_value') else None - - - - class BindData(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.DyldInfoCommand.BindItem(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _.opcode == self._root.DyldInfoCommand.BindOpcode.done: - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - - class LazyBindData(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.DyldInfoCommand.BindItem(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - @property - def rebase(self): - if hasattr(self, '_m_rebase'): - return self._m_rebase if hasattr(self, '_m_rebase') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.rebase_off) - self._debug['_m_rebase']['start'] = io.pos() - self._raw__m_rebase = io.read_bytes(self.rebase_size) - io = KaitaiStream(BytesIO(self._raw__m_rebase)) - self._m_rebase = self._root.DyldInfoCommand.RebaseData(io, self, self._root) - self._m_rebase._read() - self._debug['_m_rebase']['end'] = io.pos() - io.seek(_pos) - return self._m_rebase if hasattr(self, '_m_rebase') else None - - @property - def bind(self): - if hasattr(self, '_m_bind'): - return self._m_bind if hasattr(self, '_m_bind') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.bind_off) - self._debug['_m_bind']['start'] = io.pos() - self._raw__m_bind = io.read_bytes(self.bind_size) - io = KaitaiStream(BytesIO(self._raw__m_bind)) - self._m_bind = self._root.DyldInfoCommand.BindData(io, self, self._root) - self._m_bind._read() - self._debug['_m_bind']['end'] = io.pos() - io.seek(_pos) - return self._m_bind if hasattr(self, '_m_bind') else None - - @property - def lazy_bind(self): - if hasattr(self, '_m_lazy_bind'): - return self._m_lazy_bind if hasattr(self, '_m_lazy_bind') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.lazy_bind_off) - self._debug['_m_lazy_bind']['start'] = io.pos() - self._raw__m_lazy_bind = io.read_bytes(self.lazy_bind_size) - io = KaitaiStream(BytesIO(self._raw__m_lazy_bind)) - self._m_lazy_bind = self._root.DyldInfoCommand.LazyBindData(io, self, self._root) - self._m_lazy_bind._read() - self._debug['_m_lazy_bind']['end'] = io.pos() - io.seek(_pos) - return self._m_lazy_bind if hasattr(self, '_m_lazy_bind') else None - - @property - def exports(self): - if hasattr(self, '_m_exports'): - return self._m_exports if hasattr(self, '_m_exports') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.export_off) - self._debug['_m_exports']['start'] = io.pos() - self._raw__m_exports = io.read_bytes(self.export_size) - io = KaitaiStream(BytesIO(self._raw__m_exports)) - self._m_exports = self._root.DyldInfoCommand.ExportNode(io, self, self._root) - self._m_exports._read() - self._debug['_m_exports']['end'] = io.pos() - io.seek(_pos) - return self._m_exports if hasattr(self, '_m_exports') else None - - - class DylinkerCommand(KaitaiStruct): - SEQ_FIELDS = ["name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.LcStr(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - - - class DylibCommand(KaitaiStruct): - SEQ_FIELDS = ["name_offset", "timestamp", "current_version", "compatibility_version", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_offset']['start'] = self._io.pos() - self.name_offset = self._io.read_u4le() - self._debug['name_offset']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4le() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['current_version']['start'] = self._io.pos() - self.current_version = self._io.read_u4le() - self._debug['current_version']['end'] = self._io.pos() - self._debug['compatibility_version']['start'] = self._io.pos() - self.compatibility_version = self._io.read_u4le() - self._debug['compatibility_version']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8") - self._debug['name']['end'] = self._io.pos() - - - class LcStr(KaitaiStruct): - SEQ_FIELDS = ["length", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['value']['end'] = self._io.pos() - - - class LoadCommand(KaitaiStruct): - SEQ_FIELDS = ["type", "size", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.LoadCommandType, self._io.read_u4le()) - self._debug['type']['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.type - if _on == self._root.LoadCommandType.id_dylinker: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylinkerCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.reexport_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.source_version: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SourceVersionCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.function_starts: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkeditDataCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.rpath: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RpathCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.sub_framework: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SubCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.routines: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RoutinesCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.sub_library: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SubCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.dyld_info_only: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DyldInfoCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.dyld_environment: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylinkerCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.load_dylinker: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylinkerCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.segment_split_info: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkeditDataCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.main: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.EntryPointCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.load_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.encryption_info: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.EncryptionInfoCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.dysymtab: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DysymtabCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.twolevel_hints: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.TwolevelHintsCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.encryption_info_64: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.EncryptionInfoCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.linker_option: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkerOptionCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.dyld_info: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DyldInfoCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.version_min_tvos: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.VersionMinCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.load_upward_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.segment_64: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SegmentCommand64(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.sub_umbrella: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SubCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.version_min_watchos: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.VersionMinCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.routines_64: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RoutinesCommand64(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.id_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.sub_client: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SubCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.dylib_code_sign_drs: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkeditDataCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.symtab: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SymtabCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.linker_optimization_hint: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkeditDataCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.data_in_code: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkeditDataCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.code_signature: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CodeSignatureCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.version_min_iphoneos: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.VersionMinCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.load_weak_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.lazy_load_dylib: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.DylibCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.uuid: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.UuidCommand(io, self, self._root) - self.body._read() - elif _on == self._root.LoadCommandType.version_min_macosx: - self._raw_body = self._io.read_bytes((self.size - 8)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.VersionMinCommand(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes((self.size - 8)) - self._debug['body']['end'] = self._io.pos() - - - class UuidCommand(KaitaiStruct): - SEQ_FIELDS = ["uuid"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['uuid']['start'] = self._io.pos() - self.uuid = self._io.read_bytes(16) - self._debug['uuid']['end'] = self._io.pos() - - - class SymtabCommand(KaitaiStruct): - SEQ_FIELDS = ["sym_off", "n_syms", "str_off", "str_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sym_off']['start'] = self._io.pos() - self.sym_off = self._io.read_u4le() - self._debug['sym_off']['end'] = self._io.pos() - self._debug['n_syms']['start'] = self._io.pos() - self.n_syms = self._io.read_u4le() - self._debug['n_syms']['end'] = self._io.pos() - self._debug['str_off']['start'] = self._io.pos() - self.str_off = self._io.read_u4le() - self._debug['str_off']['end'] = self._io.pos() - self._debug['str_size']['start'] = self._io.pos() - self.str_size = self._io.read_u4le() - self._debug['str_size']['end'] = self._io.pos() - - class StrTable(KaitaiStruct): - SEQ_FIELDS = ["unknown", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unknown']['start'] = self._io.pos() - self.unknown = self._io.read_u4le() - self._debug['unknown']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _ = (self._io.read_bytes_term(0, False, True, True)).decode(u"ascii") - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _ == u"": - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - - class Nlist64(KaitaiStruct): - SEQ_FIELDS = ["un", "type", "sect", "desc", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['un']['start'] = self._io.pos() - self.un = self._io.read_u4le() - self._debug['un']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u1() - self._debug['type']['end'] = self._io.pos() - self._debug['sect']['start'] = self._io.pos() - self.sect = self._io.read_u1() - self._debug['sect']['end'] = self._io.pos() - self._debug['desc']['start'] = self._io.pos() - self.desc = self._io.read_u2le() - self._debug['desc']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u8le() - self._debug['value']['end'] = self._io.pos() - - - @property - def symbols(self): - if hasattr(self, '_m_symbols'): - return self._m_symbols if hasattr(self, '_m_symbols') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.sym_off) - self._debug['_m_symbols']['start'] = io.pos() - self._m_symbols = [None] * (self.n_syms) - for i in range(self.n_syms): - if not 'arr' in self._debug['_m_symbols']: - self._debug['_m_symbols']['arr'] = [] - self._debug['_m_symbols']['arr'].append({'start': io.pos()}) - _t__m_symbols = self._root.SymtabCommand.Nlist64(io, self, self._root) - _t__m_symbols._read() - self._m_symbols[i] = _t__m_symbols - self._debug['_m_symbols']['arr'][i]['end'] = io.pos() - - self._debug['_m_symbols']['end'] = io.pos() - io.seek(_pos) - return self._m_symbols if hasattr(self, '_m_symbols') else None - - @property - def strs(self): - if hasattr(self, '_m_strs'): - return self._m_strs if hasattr(self, '_m_strs') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.str_off) - self._debug['_m_strs']['start'] = io.pos() - self._raw__m_strs = io.read_bytes(self.str_size) - io = KaitaiStream(BytesIO(self._raw__m_strs)) - self._m_strs = self._root.SymtabCommand.StrTable(io, self, self._root) - self._m_strs._read() - self._debug['_m_strs']['end'] = io.pos() - io.seek(_pos) - return self._m_strs if hasattr(self, '_m_strs') else None - - - class VersionMinCommand(KaitaiStruct): - SEQ_FIELDS = ["version", "sdk"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Version(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['sdk']['start'] = self._io.pos() - self.sdk = self._root.Version(self._io, self, self._root) - self.sdk._read() - self._debug['sdk']['end'] = self._io.pos() - - - class EntryPointCommand(KaitaiStruct): - SEQ_FIELDS = ["entry_off", "stack_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entry_off']['start'] = self._io.pos() - self.entry_off = self._io.read_u8le() - self._debug['entry_off']['end'] = self._io.pos() - self._debug['stack_size']['start'] = self._io.pos() - self.stack_size = self._io.read_u8le() - self._debug['stack_size']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/magicavoxel_vox.py b/python/examples/kaitai/magicavoxel_vox.py deleted file mode 100644 index 0fc3faaa..00000000 --- a/python/examples/kaitai/magicavoxel_vox.py +++ /dev/null @@ -1,384 +0,0 @@ -# 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 -import collections - - -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 MagicavoxelVox(KaitaiStruct): - """ - .. seealso:: - Format Description - https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt - """ - - class ChunkType(Enum): - main = 1296124238 - matt = 1296127060 - pack = 1346454347 - rgba = 1380401729 - size = 1397316165 - xyzi = 1482250825 - - class MaterialType(Enum): - diffuse = 0 - metal = 1 - glass = 2 - emissive = 3 - - class PropertyBitsType(Enum): - plastic = 1 - roughness = 2 - specular = 4 - ior = 8 - attenuation = 16 - power = 32 - glow = 64 - is_total_power = 128 - SEQ_FIELDS = ["magic", "version", "main"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x56\x4F\x58\x20") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u4le() - self._debug['version']['end'] = self._io.pos() - self._debug['main']['start'] = self._io.pos() - self.main = self._root.Chunk(self._io, self, self._root) - self.main._read() - self._debug['main']['end'] = self._io.pos() - - class Chunk(KaitaiStruct): - SEQ_FIELDS = ["chunk_id", "num_bytes_of_chunk_content", "num_bytes_of_children_chunks", "chunk_content", "children_chunks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['chunk_id']['start'] = self._io.pos() - self.chunk_id = KaitaiStream.resolve_enum(self._root.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 == self._root.ChunkType.size: - self._raw_chunk_content = self._io.read_bytes(self.num_bytes_of_chunk_content) - io = KaitaiStream(BytesIO(self._raw_chunk_content)) - self.chunk_content = self._root.Size(io, self, self._root) - self.chunk_content._read() - elif _on == self._root.ChunkType.matt: - self._raw_chunk_content = self._io.read_bytes(self.num_bytes_of_chunk_content) - io = KaitaiStream(BytesIO(self._raw_chunk_content)) - self.chunk_content = self._root.Matt(io, self, self._root) - self.chunk_content._read() - elif _on == self._root.ChunkType.rgba: - self._raw_chunk_content = self._io.read_bytes(self.num_bytes_of_chunk_content) - io = KaitaiStream(BytesIO(self._raw_chunk_content)) - self.chunk_content = self._root.Rgba(io, self, self._root) - self.chunk_content._read() - elif _on == self._root.ChunkType.xyzi: - self._raw_chunk_content = self._io.read_bytes(self.num_bytes_of_chunk_content) - io = KaitaiStream(BytesIO(self._raw_chunk_content)) - self.chunk_content = self._root.Xyzi(io, self, self._root) - self.chunk_content._read() - elif _on == self._root.ChunkType.pack: - self._raw_chunk_content = self._io.read_bytes(self.num_bytes_of_chunk_content) - io = KaitaiStream(BytesIO(self._raw_chunk_content)) - self.chunk_content = self._root.Pack(io, 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 = self._root.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() - - - - class Size(KaitaiStruct): - SEQ_FIELDS = ["size_x", "size_y", "size_z"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size_x']['start'] = self._io.pos() - self.size_x = self._io.read_u4le() - self._debug['size_x']['end'] = self._io.pos() - self._debug['size_y']['start'] = self._io.pos() - self.size_y = self._io.read_u4le() - self._debug['size_y']['end'] = self._io.pos() - self._debug['size_z']['start'] = self._io.pos() - self.size_z = self._io.read_u4le() - self._debug['size_z']['end'] = self._io.pos() - - - class Rgba(KaitaiStruct): - SEQ_FIELDS = ["colors"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['colors']['start'] = self._io.pos() - self.colors = [None] * (256) - for i in range(256): - if not 'arr' in self._debug['colors']: - self._debug['colors']['arr'] = [] - self._debug['colors']['arr'].append({'start': self._io.pos()}) - _t_colors = self._root.Color(self._io, self, self._root) - _t_colors._read() - self.colors[i] = _t_colors - self._debug['colors']['arr'][i]['end'] = self._io.pos() - - self._debug['colors']['end'] = self._io.pos() - - - class Pack(KaitaiStruct): - SEQ_FIELDS = ["num_models"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_models']['start'] = self._io.pos() - self.num_models = self._io.read_u4le() - self._debug['num_models']['end'] = self._io.pos() - - - class Matt(KaitaiStruct): - SEQ_FIELDS = ["id", "material_type", "material_weight", "property_bits", "plastic", "roughness", "specular", "ior", "attenuation", "power", "glow", "is_total_power"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = self._io.read_u4le() - self._debug['id']['end'] = self._io.pos() - self._debug['material_type']['start'] = self._io.pos() - self.material_type = KaitaiStream.resolve_enum(self._root.MaterialType, self._io.read_u4le()) - self._debug['material_type']['end'] = self._io.pos() - self._debug['material_weight']['start'] = self._io.pos() - self.material_weight = self._io.read_f4le() - self._debug['material_weight']['end'] = self._io.pos() - self._debug['property_bits']['start'] = self._io.pos() - self.property_bits = self._io.read_u4le() - self._debug['property_bits']['end'] = self._io.pos() - if self.has_plastic: - self._debug['plastic']['start'] = self._io.pos() - self.plastic = self._io.read_f4le() - self._debug['plastic']['end'] = self._io.pos() - - if self.has_roughness: - self._debug['roughness']['start'] = self._io.pos() - self.roughness = self._io.read_f4le() - self._debug['roughness']['end'] = self._io.pos() - - if self.has_specular: - self._debug['specular']['start'] = self._io.pos() - self.specular = self._io.read_f4le() - self._debug['specular']['end'] = self._io.pos() - - if self.has_ior: - self._debug['ior']['start'] = self._io.pos() - self.ior = self._io.read_f4le() - self._debug['ior']['end'] = self._io.pos() - - if self.has_attenuation: - self._debug['attenuation']['start'] = self._io.pos() - self.attenuation = self._io.read_f4le() - self._debug['attenuation']['end'] = self._io.pos() - - if self.has_power: - self._debug['power']['start'] = self._io.pos() - self.power = self._io.read_f4le() - self._debug['power']['end'] = self._io.pos() - - if self.has_glow: - self._debug['glow']['start'] = self._io.pos() - self.glow = self._io.read_f4le() - self._debug['glow']['end'] = self._io.pos() - - if self.has_is_total_power: - self._debug['is_total_power']['start'] = self._io.pos() - self.is_total_power = self._io.read_f4le() - self._debug['is_total_power']['end'] = self._io.pos() - - - @property - def has_is_total_power(self): - if hasattr(self, '_m_has_is_total_power'): - return self._m_has_is_total_power if hasattr(self, '_m_has_is_total_power') else None - - self._m_has_is_total_power = (self.property_bits & 128) != 0 - return self._m_has_is_total_power if hasattr(self, '_m_has_is_total_power') else None - - @property - def has_plastic(self): - if hasattr(self, '_m_has_plastic'): - return self._m_has_plastic if hasattr(self, '_m_has_plastic') else None - - self._m_has_plastic = (self.property_bits & 1) != 0 - return self._m_has_plastic if hasattr(self, '_m_has_plastic') else None - - @property - def has_attenuation(self): - if hasattr(self, '_m_has_attenuation'): - return self._m_has_attenuation if hasattr(self, '_m_has_attenuation') else None - - self._m_has_attenuation = (self.property_bits & 16) != 0 - return self._m_has_attenuation if hasattr(self, '_m_has_attenuation') else None - - @property - def has_power(self): - if hasattr(self, '_m_has_power'): - return self._m_has_power if hasattr(self, '_m_has_power') else None - - self._m_has_power = (self.property_bits & 32) != 0 - return self._m_has_power if hasattr(self, '_m_has_power') else None - - @property - def has_roughness(self): - if hasattr(self, '_m_has_roughness'): - return self._m_has_roughness if hasattr(self, '_m_has_roughness') else None - - self._m_has_roughness = (self.property_bits & 2) != 0 - return self._m_has_roughness if hasattr(self, '_m_has_roughness') else None - - @property - def has_specular(self): - if hasattr(self, '_m_has_specular'): - return self._m_has_specular if hasattr(self, '_m_has_specular') else None - - self._m_has_specular = (self.property_bits & 4) != 0 - return self._m_has_specular if hasattr(self, '_m_has_specular') else None - - @property - def has_ior(self): - if hasattr(self, '_m_has_ior'): - return self._m_has_ior if hasattr(self, '_m_has_ior') else None - - self._m_has_ior = (self.property_bits & 8) != 0 - return self._m_has_ior if hasattr(self, '_m_has_ior') else None - - @property - def has_glow(self): - if hasattr(self, '_m_has_glow'): - return self._m_has_glow if hasattr(self, '_m_has_glow') else None - - self._m_has_glow = (self.property_bits & 64) != 0 - return self._m_has_glow if hasattr(self, '_m_has_glow') else None - - - class Xyzi(KaitaiStruct): - SEQ_FIELDS = ["num_voxels", "voxels"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_voxels']['start'] = self._io.pos() - self.num_voxels = self._io.read_u4le() - self._debug['num_voxels']['end'] = self._io.pos() - self._debug['voxels']['start'] = self._io.pos() - self.voxels = [None] * (self.num_voxels) - for i in range(self.num_voxels): - if not 'arr' in self._debug['voxels']: - self._debug['voxels']['arr'] = [] - self._debug['voxels']['arr'].append({'start': self._io.pos()}) - _t_voxels = self._root.Voxel(self._io, self, self._root) - _t_voxels._read() - self.voxels[i] = _t_voxels - self._debug['voxels']['arr'][i]['end'] = self._io.pos() - - self._debug['voxels']['end'] = self._io.pos() - - - class Color(KaitaiStruct): - SEQ_FIELDS = ["r", "g", "b", "a"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['r']['start'] = self._io.pos() - self.r = self._io.read_u1() - self._debug['r']['end'] = self._io.pos() - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_u1() - self._debug['g']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_u1() - self._debug['a']['end'] = self._io.pos() - - - class Voxel(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z", "color_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_u1() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_u1() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_u1() - self._debug['z']['end'] = self._io.pos() - self._debug['color_index']['start'] = self._io.pos() - self.color_index = self._io.read_u1() - self._debug['color_index']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/mbr_partition_table.py b/python/examples/kaitai/mbr_partition_table.py deleted file mode 100644 index 710fa3d7..00000000 --- a/python/examples/kaitai/mbr_partition_table.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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 -import collections - - -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 MbrPartitionTable(KaitaiStruct): - """MBR (Master Boot Record) partition table is a traditional way of - MS-DOS to partition larger hard disc drives into distinct - partitions. - - This table is stored in the end of the boot sector (first sector) of - the drive, after the bootstrap code. Original DOS 2.0 specification - allowed only 4 partitions per disc, but DOS 3.2 introduced concept - of "extended partitions", which work as nested extra "boot records" - which are pointed to by original ("primary") partitions in MBR. - """ - SEQ_FIELDS = ["bootstrap_code", "partitions", "boot_signature"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bootstrap_code']['start'] = self._io.pos() - self.bootstrap_code = self._io.read_bytes(446) - self._debug['bootstrap_code']['end'] = self._io.pos() - self._debug['partitions']['start'] = self._io.pos() - self.partitions = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['partitions']: - self._debug['partitions']['arr'] = [] - self._debug['partitions']['arr'].append({'start': self._io.pos()}) - _t_partitions = self._root.PartitionEntry(self._io, self, self._root) - _t_partitions._read() - self.partitions[i] = _t_partitions - self._debug['partitions']['arr'][i]['end'] = self._io.pos() - - self._debug['partitions']['end'] = self._io.pos() - self._debug['boot_signature']['start'] = self._io.pos() - self.boot_signature = self._io.ensure_fixed_contents(b"\x55\xAA") - self._debug['boot_signature']['end'] = self._io.pos() - - class PartitionEntry(KaitaiStruct): - SEQ_FIELDS = ["status", "chs_start", "partition_type", "chs_end", "lba_start", "num_sectors"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['status']['start'] = self._io.pos() - self.status = self._io.read_u1() - self._debug['status']['end'] = self._io.pos() - self._debug['chs_start']['start'] = self._io.pos() - self.chs_start = self._root.Chs(self._io, self, self._root) - self.chs_start._read() - self._debug['chs_start']['end'] = self._io.pos() - self._debug['partition_type']['start'] = self._io.pos() - self.partition_type = self._io.read_u1() - self._debug['partition_type']['end'] = self._io.pos() - self._debug['chs_end']['start'] = self._io.pos() - self.chs_end = self._root.Chs(self._io, self, self._root) - self.chs_end._read() - self._debug['chs_end']['end'] = self._io.pos() - self._debug['lba_start']['start'] = self._io.pos() - self.lba_start = self._io.read_u4le() - self._debug['lba_start']['end'] = self._io.pos() - self._debug['num_sectors']['start'] = self._io.pos() - self.num_sectors = self._io.read_u4le() - self._debug['num_sectors']['end'] = self._io.pos() - - - class Chs(KaitaiStruct): - SEQ_FIELDS = ["head", "b2", "b3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['head']['start'] = self._io.pos() - self.head = self._io.read_u1() - self._debug['head']['end'] = self._io.pos() - self._debug['b2']['start'] = self._io.pos() - self.b2 = self._io.read_u1() - self._debug['b2']['end'] = self._io.pos() - self._debug['b3']['start'] = self._io.pos() - self.b3 = self._io.read_u1() - self._debug['b3']['end'] = self._io.pos() - - @property - def sector(self): - if hasattr(self, '_m_sector'): - return self._m_sector if hasattr(self, '_m_sector') else None - - self._m_sector = (self.b2 & 63) - return self._m_sector if hasattr(self, '_m_sector') else None - - @property - def cylinder(self): - if hasattr(self, '_m_cylinder'): - return self._m_cylinder if hasattr(self, '_m_cylinder') else None - - self._m_cylinder = (self.b3 + ((self.b2 & 192) << 2)) - return self._m_cylinder if hasattr(self, '_m_cylinder') else None - - - diff --git a/python/examples/kaitai/menu.py b/python/examples/kaitai/menu.py deleted file mode 100644 index b32e7746..00000000 --- a/python/examples/kaitai/menu.py +++ /dev/null @@ -1,847 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys - -# binja stuff -from binaryninjaui import StatusBarWidget, ContextMenuManager, Menu, UIActionHandler, UIAction - -# pyside stuff -from PySide2.QtCore import Qt -from PySide2.QtGui import QPalette -from PySide2.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QGroupBox, QTreeWidget, QTreeWidgetItem, QLineEdit, QHeaderView, QLabel, QMenu, QHBoxLayout - -class KaitaiOptionsWidget(QLabel): - def __init__(self, parent): - QLabel.__init__(self, parent) - - self.statusBarWidget = parent - - self.setBackgroundRole(QPalette.Highlight) - self.setForegroundRole(QPalette.WindowText) - self.setText(" Formats â–¾ ") - - # see api/ui/menus.h - self.contextMenuManager = ContextMenuManager(self) - - self.menu = Menu() - self.actionHandler = UIActionHandler() - self.registerActions() - self.addActions() - self.bindActions() - - def registerActions(self): - # add all action handlers - UIAction.registerAction("archive\\cpio_old_le") - UIAction.registerAction("archive\\gzip") - UIAction.registerAction("archive\\lzh") - UIAction.registerAction("archive\\rar") - UIAction.registerAction("archive\\zip") - UIAction.registerAction("cad\\monomakh_sapr_chg") - UIAction.registerAction("common\\bcd") - UIAction.registerAction("database\\dbf") - UIAction.registerAction("database\\gettext_mo") - UIAction.registerAction("database\\sqlite3") - UIAction.registerAction("database\\tsm") - UIAction.registerAction("executable\\dex") - UIAction.registerAction("executable\\dos_mz") - UIAction.registerAction("executable\\elf") - UIAction.registerAction("executable\\java_class") - UIAction.registerAction("executable\\mach_o") - UIAction.registerAction("executable\\microsoft_pe") - UIAction.registerAction("executable\\python_pyc_27") - UIAction.registerAction("executable\\swf") - UIAction.registerAction("filesystem\\apm_partition_table") - UIAction.registerAction("filesystem\\apple_single_double") - UIAction.registerAction("filesystem\\cramfs") - UIAction.registerAction("filesystem\\ext2") - UIAction.registerAction("filesystem\\gpt_partition_table") - UIAction.registerAction("filesystem\\iso9660") - UIAction.registerAction("filesystem\\luks") - UIAction.registerAction("filesystem\\lvm2") - UIAction.registerAction("filesystem\\mbr_partition_table") - UIAction.registerAction("filesystem\\tr_dos_image") - UIAction.registerAction("filesystem\\vdi") - UIAction.registerAction("filesystem\\vfat") - UIAction.registerAction("filesystem\\vmware_vmdk") - UIAction.registerAction("firmware\\andes_firmware") - UIAction.registerAction("firmware\\ines") - UIAction.registerAction("firmware\\uimage") - UIAction.registerAction("font\\ttf") - UIAction.registerAction("game\\allegro_dat") - UIAction.registerAction("game\\doom_wad") - UIAction.registerAction("game\\dune_2_pak") - UIAction.registerAction("game\\fallout2_dat") - UIAction.registerAction("game\\fallout_dat") - UIAction.registerAction("game\\ftl_dat") - UIAction.registerAction("game\\gran_turismo_vol") - UIAction.registerAction("game\\heaps_pak") - UIAction.registerAction("game\\heroes_of_might_and_magic_agg") - UIAction.registerAction("game\\heroes_of_might_and_magic_bmp") - UIAction.registerAction("game\\quake_mdl") - UIAction.registerAction("game\\quake_pak") - UIAction.registerAction("game\\renderware_binary_stream") - UIAction.registerAction("game\\saints_row_2_vpp_pc") - UIAction.registerAction("game\\warcraft_2_pud") - UIAction.registerAction("geospatial\\shapefile_index") - UIAction.registerAction("geospatial\\shapefile_main") - UIAction.registerAction("hardware\\edid") - UIAction.registerAction("hardware\\mifare\\mifare_classic") - UIAction.registerAction("image\\bmp") - UIAction.registerAction("image\\dicom") - UIAction.registerAction("image\\exif") - UIAction.registerAction("image\\exif_be") - UIAction.registerAction("image\\exif_le") - UIAction.registerAction("image\\gif") - UIAction.registerAction("image\\icc_4") - UIAction.registerAction("image\\ico") - UIAction.registerAction("image\\jpeg") - UIAction.registerAction("image\\pcx") - UIAction.registerAction("image\\pcx_dcx") - UIAction.registerAction("image\\png") - UIAction.registerAction("image\\psx_tim") - UIAction.registerAction("image\\tga") - UIAction.registerAction("image\\wmf") - UIAction.registerAction("image\\xwd") - UIAction.registerAction("log\\aix_utmp") - UIAction.registerAction("log\\glibc_utmp") - UIAction.registerAction("log\\systemd_journal") - UIAction.registerAction("log\\windows_evt_log") - UIAction.registerAction("machine_code\\code_6502") - UIAction.registerAction("media\\avi") - UIAction.registerAction("media\\blender_blend") - UIAction.registerAction("media\\creative_voice_file") - UIAction.registerAction("media\\genmidi_op2") - UIAction.registerAction("media\\id3v1_1") - UIAction.registerAction("media\\id3v2_3") - UIAction.registerAction("media\\id3v2_4") - UIAction.registerAction("media\\magicavoxel_vox") - UIAction.registerAction("media\\ogg") - UIAction.registerAction("media\\quicktime_mov") - UIAction.registerAction("media\\standard_midi_file") - UIAction.registerAction("media\\stl") - UIAction.registerAction("media\\tracker_modules\\fasttracker_xm_module") - UIAction.registerAction("media\\tracker_modules\\s3m") - UIAction.registerAction("media\\vp8_ivf") - UIAction.registerAction("media\\wav") - UIAction.registerAction("network\\bitcoin_transaction") - UIAction.registerAction("network\\dns_packet") - UIAction.registerAction("network\\hccap") - UIAction.registerAction("network\\hccapx") - UIAction.registerAction("network\\icmp_packet") - - # currently on py3 can handle the circular dependency hell - if sys.version_info[0] == 3: - UIAction.registerAction("network\\ethernet_frame") - UIAction.registerAction("network\\ipv4_packet") - UIAction.registerAction("network\\ipv6_packet") - UIAction.registerAction("network\\microsoft_network_monitor_v2") - UIAction.registerAction("network\\packet_ppi") - UIAction.registerAction("network\\pcap") - UIAction.registerAction("network\\protocol_body") - - UIAction.registerAction("network\\rtcp_payload") - UIAction.registerAction("network\\rtp_packet") - UIAction.registerAction("network\\tcp_segment") - UIAction.registerAction("network\\tls_client_hello") - UIAction.registerAction("network\\udp_datagram") - UIAction.registerAction("network\\windows_systemtime") - UIAction.registerAction("scientific\\nt_mdt\\nt_mdt") - UIAction.registerAction("scientific\\nt_mdt\\nt_mdt_pal") - UIAction.registerAction("scientific\\spectroscopy\\avantes_roh60") - UIAction.registerAction("scientific\\spectroscopy\\specpr") - UIAction.registerAction("security\\openpgp_message") - UIAction.registerAction("security\\ssh_public_key") - UIAction.registerAction("serialization\\asn1\\asn1_der") - UIAction.registerAction("serialization\\bson") - UIAction.registerAction("serialization\\google_protobuf") - UIAction.registerAction("serialization\\microsoft_cfb") - UIAction.registerAction("serialization\\msgpack") - UIAction.registerAction("serialization\\ruby_marshal") - UIAction.registerAction("windows\\regf") - UIAction.registerAction("windows\\windows_lnk_file") - UIAction.registerAction("windows\\windows_minidump") - UIAction.registerAction("windows\\windows_resource_file") - UIAction.registerAction("windows\\windows_shell_items") - UIAction.registerAction("windows\\windows_systemtime") - - def addActions(self): - self.menu.addAction("archive\\cpio_old_le", "formats") - self.menu.addAction("archive\\gzip", "formats") - self.menu.addAction("archive\\lzh", "formats") - self.menu.addAction("archive\\rar", "formats") - self.menu.addAction("archive\\zip", "formats") - self.menu.addAction("cad\\monomakh_sapr_chg", "formats") - self.menu.addAction("common\\bcd", "formats") - self.menu.addAction("database\\dbf", "formats") - self.menu.addAction("database\\gettext_mo", "formats") - self.menu.addAction("database\\sqlite3", "formats") - self.menu.addAction("database\\tsm", "formats") - self.menu.addAction("executable\\dex", "formats") - self.menu.addAction("executable\\dos_mz", "formats") - self.menu.addAction("executable\\elf", "formats") - self.menu.addAction("executable\\java_class", "formats") - self.menu.addAction("executable\\mach_o", "formats") - self.menu.addAction("executable\\microsoft_pe", "formats") - self.menu.addAction("executable\\python_pyc_27", "formats") - self.menu.addAction("executable\\swf", "formats") - self.menu.addAction("filesystem\\apm_partition_table", "formats") - self.menu.addAction("filesystem\\apple_single_double", "formats") - self.menu.addAction("filesystem\\cramfs", "formats") - self.menu.addAction("filesystem\\ext2", "formats") - self.menu.addAction("filesystem\\gpt_partition_table", "formats") - self.menu.addAction("filesystem\\iso9660", "formats") - self.menu.addAction("filesystem\\luks", "formats") - self.menu.addAction("filesystem\\lvm2", "formats") - self.menu.addAction("filesystem\\mbr_partition_table", "formats") - self.menu.addAction("filesystem\\tr_dos_image", "formats") - self.menu.addAction("filesystem\\vdi", "formats") - self.menu.addAction("filesystem\\vfat", "formats") - self.menu.addAction("filesystem\\vmware_vmdk", "formats") - self.menu.addAction("firmware\\andes_firmware", "formats") - self.menu.addAction("firmware\\ines", "formats") - self.menu.addAction("firmware\\uimage", "formats") - self.menu.addAction("font\\ttf", "formats") - self.menu.addAction("game\\allegro_dat", "formats") - self.menu.addAction("game\\doom_wad", "formats") - self.menu.addAction("game\\dune_2_pak", "formats") - self.menu.addAction("game\\fallout2_dat", "formats") - self.menu.addAction("game\\fallout_dat", "formats") - self.menu.addAction("game\\ftl_dat", "formats") - self.menu.addAction("game\\gran_turismo_vol", "formats") - self.menu.addAction("game\\heaps_pak", "formats") - self.menu.addAction("game\\heroes_of_might_and_magic_agg", "formats") - self.menu.addAction("game\\heroes_of_might_and_magic_bmp", "formats") - self.menu.addAction("game\\quake_mdl", "formats") - self.menu.addAction("game\\quake_pak", "formats") - self.menu.addAction("game\\renderware_binary_stream", "formats") - self.menu.addAction("game\\saints_row_2_vpp_pc", "formats") - self.menu.addAction("game\\warcraft_2_pud", "formats") - self.menu.addAction("geospatial\\shapefile_index", "formats") - self.menu.addAction("geospatial\\shapefile_main", "formats") - self.menu.addAction("hardware\\edid", "formats") - self.menu.addAction("hardware\\mifare\\mifare_classic", "formats") - self.menu.addAction("image\\bmp", "formats") - self.menu.addAction("image\\dicom", "formats") - self.menu.addAction("image\\exif", "formats") - self.menu.addAction("image\\exif_be", "formats") - self.menu.addAction("image\\exif_le", "formats") - self.menu.addAction("image\\gif", "formats") - self.menu.addAction("image\\icc_4", "formats") - self.menu.addAction("image\\ico", "formats") - self.menu.addAction("image\\jpeg", "formats") - self.menu.addAction("image\\pcx", "formats") - self.menu.addAction("image\\pcx_dcx", "formats") - self.menu.addAction("image\\png", "formats") - self.menu.addAction("image\\psx_tim", "formats") - self.menu.addAction("image\\tga", "formats") - self.menu.addAction("image\\wmf", "formats") - self.menu.addAction("image\\xwd", "formats") - self.menu.addAction("log\\aix_utmp", "formats") - self.menu.addAction("log\\glibc_utmp", "formats") - self.menu.addAction("log\\systemd_journal", "formats") - self.menu.addAction("log\\windows_evt_log", "formats") - self.menu.addAction("machine_code\\code_6502", "formats") - self.menu.addAction("media\\avi", "formats") - self.menu.addAction("media\\blender_blend", "formats") - self.menu.addAction("media\\creative_voice_file", "formats") - self.menu.addAction("media\\genmidi_op2", "formats") - self.menu.addAction("media\\id3v1_1", "formats") - self.menu.addAction("media\\id3v2_3", "formats") - self.menu.addAction("media\\id3v2_4", "formats") - self.menu.addAction("media\\magicavoxel_vox", "formats") - self.menu.addAction("media\\ogg", "formats") - self.menu.addAction("media\\quicktime_mov", "formats") - self.menu.addAction("media\\standard_midi_file", "formats") - self.menu.addAction("media\\stl", "formats") - self.menu.addAction("media\\tracker_modules\\fasttracker_xm_module", "formats") - self.menu.addAction("media\\tracker_modules\\s3m", "formats") - self.menu.addAction("media\\vp8_ivf", "formats") - self.menu.addAction("media\\wav", "formats") - self.menu.addAction("network\\bitcoin_transaction", "formats") - self.menu.addAction("network\\dns_packet", "formats") - self.menu.addAction("network\\hccap", "formats") - self.menu.addAction("network\\hccapx", "formats") - self.menu.addAction("network\\icmp_packet", "formats") - - if sys.version_info[0] == 3: - self.menu.addAction("network\\ethernet_frame", "formats") - self.menu.addAction("network\\ipv4_packet", "formats") - self.menu.addAction("network\\ipv6_packet", "formats") - self.menu.addAction("network\\microsoft_network_monitor_v2", "formats") - self.menu.addAction("network\\packet_ppi", "formats") - self.menu.addAction("network\\pcap", "formats") - self.menu.addAction("network\\protocol_body", "formats") - - self.menu.addAction("network\\rtcp_payload", "formats") - self.menu.addAction("network\\rtp_packet", "formats") - self.menu.addAction("network\\tcp_segment", "formats") - self.menu.addAction("network\\tls_client_hello", "formats") - self.menu.addAction("network\\udp_datagram", "formats") - self.menu.addAction("network\\windows_systemtime", "formats") - self.menu.addAction("scientific\\nt_mdt\\nt_mdt", "formats") - self.menu.addAction("scientific\\nt_mdt\\nt_mdt_pal", "formats") - self.menu.addAction("scientific\\spectroscopy\\avantes_roh60", "formats") - self.menu.addAction("scientific\\spectroscopy\\specpr", "formats") - self.menu.addAction("security\\openpgp_message", "formats") - self.menu.addAction("security\\ssh_public_key", "formats") - self.menu.addAction("serialization\\asn1\\asn1_der", "formats") - self.menu.addAction("serialization\\bson", "formats") - self.menu.addAction("serialization\\google_protobuf", "formats") - self.menu.addAction("serialization\\microsoft_cfb", "formats") - self.menu.addAction("serialization\\msgpack", "formats") - self.menu.addAction("serialization\\ruby_marshal", "formats") - self.menu.addAction("windows\\regf", "formats") - self.menu.addAction("windows\\windows_lnk_file", "formats") - self.menu.addAction("windows\\windows_minidump", "formats") - self.menu.addAction("windows\\windows_resource_file", "formats") - self.menu.addAction("windows\\windows_shell_items", "formats") - self.menu.addAction("windows\\windows_systemtime", "formats") - - def bindActions(self): - self.actionHandler.bindAction("archive\\cpio_old_le", UIAction(self.on_cpio_old_le)) - self.actionHandler.bindAction("archive\\gzip", UIAction(self.on_gzip)) - self.actionHandler.bindAction("archive\\lzh", UIAction(self.on_lzh)) - self.actionHandler.bindAction("archive\\rar", UIAction(self.on_rar)) - self.actionHandler.bindAction("archive\\zip", UIAction(self.on_zip)) - self.actionHandler.bindAction("cad\\monomakh_sapr_chg", UIAction(self.on_monomakh_sapr_chg)) - self.actionHandler.bindAction("common\\bcd", UIAction(self.on_bcd)) - self.actionHandler.bindAction("database\\dbf", UIAction(self.on_dbf)) - self.actionHandler.bindAction("database\\gettext_mo", UIAction(self.on_gettext_mo)) - self.actionHandler.bindAction("database\\sqlite3", UIAction(self.on_sqlite3)) - self.actionHandler.bindAction("database\\tsm", UIAction(self.on_tsm)) - self.actionHandler.bindAction("executable\\dex", UIAction(self.on_dex)) - self.actionHandler.bindAction("executable\\dos_mz", UIAction(self.on_dos_mz)) - self.actionHandler.bindAction("executable\\elf", UIAction(self.on_elf)) - self.actionHandler.bindAction("executable\\java_class", UIAction(self.on_java_class)) - self.actionHandler.bindAction("executable\\mach_o", UIAction(self.on_mach_o)) - self.actionHandler.bindAction("executable\\microsoft_pe", UIAction(self.on_microsoft_pe)) - self.actionHandler.bindAction("executable\\python_pyc_27", UIAction(self.on_python_pyc_27)) - self.actionHandler.bindAction("executable\\swf", UIAction(self.on_swf)) - self.actionHandler.bindAction("filesystem\\apm_partition_table", UIAction(self.on_apm_partition_table)) - self.actionHandler.bindAction("filesystem\\apple_single_double", UIAction(self.on_apple_single_double)) - self.actionHandler.bindAction("filesystem\\cramfs", UIAction(self.on_cramfs)) - self.actionHandler.bindAction("filesystem\\ext2", UIAction(self.on_ext2)) - self.actionHandler.bindAction("filesystem\\gpt_partition_table", UIAction(self.on_gpt_partition_table)) - self.actionHandler.bindAction("filesystem\\iso9660", UIAction(self.on_iso9660)) - self.actionHandler.bindAction("filesystem\\luks", UIAction(self.on_luks)) - self.actionHandler.bindAction("filesystem\\lvm2", UIAction(self.on_lvm2)) - self.actionHandler.bindAction("filesystem\\mbr_partition_table", UIAction(self.on_mbr_partition_table)) - self.actionHandler.bindAction("filesystem\\tr_dos_image", UIAction(self.on_tr_dos_image)) - self.actionHandler.bindAction("filesystem\\vdi", UIAction(self.on_vdi)) - self.actionHandler.bindAction("filesystem\\vfat", UIAction(self.on_vfat)) - self.actionHandler.bindAction("filesystem\\vmware_vmdk", UIAction(self.on_vmware_vmdk)) - self.actionHandler.bindAction("firmware\\andes_firmware", UIAction(self.on_andes_firmware)) - self.actionHandler.bindAction("firmware\\ines", UIAction(self.on_ines)) - self.actionHandler.bindAction("firmware\\uimage", UIAction(self.on_uimage)) - self.actionHandler.bindAction("font\\ttf", UIAction(self.on_ttf)) - self.actionHandler.bindAction("game\\allegro_dat", UIAction(self.on_allegro_dat)) - self.actionHandler.bindAction("game\\doom_wad", UIAction(self.on_doom_wad)) - self.actionHandler.bindAction("game\\dune_2_pak", UIAction(self.on_dune_2_pak)) - self.actionHandler.bindAction("game\\fallout2_dat", UIAction(self.on_fallout2_dat)) - self.actionHandler.bindAction("game\\fallout_dat", UIAction(self.on_fallout_dat)) - self.actionHandler.bindAction("game\\ftl_dat", UIAction(self.on_ftl_dat)) - self.actionHandler.bindAction("game\\gran_turismo_vol", UIAction(self.on_gran_turismo_vol)) - self.actionHandler.bindAction("game\\heaps_pak", UIAction(self.on_heaps_pak)) - self.actionHandler.bindAction("game\\heroes_of_might_and_magic_agg", UIAction(self.on_heroes_of_might_and_magic_agg)) - self.actionHandler.bindAction("game\\heroes_of_might_and_magic_bmp", UIAction(self.on_heroes_of_might_and_magic_bmp)) - self.actionHandler.bindAction("game\\quake_mdl", UIAction(self.on_quake_mdl)) - self.actionHandler.bindAction("game\\quake_pak", UIAction(self.on_quake_pak)) - self.actionHandler.bindAction("game\\renderware_binary_stream", UIAction(self.on_renderware_binary_stream)) - self.actionHandler.bindAction("game\\saints_row_2_vpp_pc", UIAction(self.on_saints_row_2_vpp_pc)) - self.actionHandler.bindAction("game\\warcraft_2_pud", UIAction(self.on_warcraft_2_pud)) - self.actionHandler.bindAction("geospatial\\shapefile_index", UIAction(self.on_shapefile_index)) - self.actionHandler.bindAction("geospatial\\shapefile_main", UIAction(self.on_shapefile_main)) - self.actionHandler.bindAction("hardware\\edid", UIAction(self.on_edid)) - self.actionHandler.bindAction("hardware\\mifare\\mifare_classic", UIAction(self.on_mifare_classic)) - self.actionHandler.bindAction("image\\bmp", UIAction(self.on_bmp)) - self.actionHandler.bindAction("image\\dicom", UIAction(self.on_dicom)) - self.actionHandler.bindAction("image\\exif", UIAction(self.on_exif)) - self.actionHandler.bindAction("image\\exif_be", UIAction(self.on_exif_be)) - self.actionHandler.bindAction("image\\exif_le", UIAction(self.on_exif_le)) - self.actionHandler.bindAction("image\\gif", UIAction(self.on_gif)) - self.actionHandler.bindAction("image\\icc_4", UIAction(self.on_icc_4)) - self.actionHandler.bindAction("image\\ico", UIAction(self.on_ico)) - self.actionHandler.bindAction("image\\jpeg", UIAction(self.on_jpeg)) - self.actionHandler.bindAction("image\\pcx", UIAction(self.on_pcx)) - self.actionHandler.bindAction("image\\pcx_dcx", UIAction(self.on_pcx_dcx)) - self.actionHandler.bindAction("image\\png", UIAction(self.on_png)) - self.actionHandler.bindAction("image\\psx_tim", UIAction(self.on_psx_tim)) - self.actionHandler.bindAction("image\\tga", UIAction(self.on_tga)) - self.actionHandler.bindAction("image\\wmf", UIAction(self.on_wmf)) - self.actionHandler.bindAction("image\\xwd", UIAction(self.on_xwd)) - self.actionHandler.bindAction("log\\aix_utmp", UIAction(self.on_aix_utmp)) - self.actionHandler.bindAction("log\\glibc_utmp", UIAction(self.on_glibc_utmp)) - self.actionHandler.bindAction("log\\systemd_journal", UIAction(self.on_systemd_journal)) - self.actionHandler.bindAction("log\\windows_evt_log", UIAction(self.on_windows_evt_log)) - self.actionHandler.bindAction("machine_code\\code_6502", UIAction(self.on_code_6502)) - self.actionHandler.bindAction("media\\avi", UIAction(self.on_avi)) - self.actionHandler.bindAction("media\\blender_blend", UIAction(self.on_blender_blend)) - self.actionHandler.bindAction("media\\creative_voice_file", UIAction(self.on_creative_voice_file)) - self.actionHandler.bindAction("media\\genmidi_op2", UIAction(self.on_genmidi_op2)) - self.actionHandler.bindAction("media\\id3v1_1", UIAction(self.on_id3v1_1)) - self.actionHandler.bindAction("media\\id3v2_3", UIAction(self.on_id3v2_3)) - self.actionHandler.bindAction("media\\id3v2_4", UIAction(self.on_id3v2_4)) - self.actionHandler.bindAction("media\\magicavoxel_vox", UIAction(self.on_magicavoxel_vox)) - self.actionHandler.bindAction("media\\ogg", UIAction(self.on_ogg)) - self.actionHandler.bindAction("media\\quicktime_mov", UIAction(self.on_quicktime_mov)) - self.actionHandler.bindAction("media\\standard_midi_file", UIAction(self.on_standard_midi_file)) - self.actionHandler.bindAction("media\\stl", UIAction(self.on_stl)) - self.actionHandler.bindAction("media\\tracker_modules\\fasttracker_xm_module", UIAction(self.on_fasttracker_xm_module)) - self.actionHandler.bindAction("media\\tracker_modules\\s3m", UIAction(self.on_s3m)) - self.actionHandler.bindAction("media\\vp8_ivf", UIAction(self.on_vp8_ivf)) - self.actionHandler.bindAction("media\\wav", UIAction(self.on_wav)) - self.actionHandler.bindAction("network\\bitcoin_transaction", UIAction(self.on_bitcoin_transaction)) - self.actionHandler.bindAction("network\\dns_packet", UIAction(self.on_dns_packet)) - self.actionHandler.bindAction("network\\hccap", UIAction(self.on_hccap)) - self.actionHandler.bindAction("network\\hccapx", UIAction(self.on_hccapx)) - self.actionHandler.bindAction("network\\icmp_packet", UIAction(self.on_icmp_packet)) - - if sys.version_info[0] == 3: - self.actionHandler.bindAction("network\\ethernet_frame", UIAction(self.on_ethernet_frame)) - self.actionHandler.bindAction("network\\ipv4_packet", UIAction(self.on_ipv4_packet)) - self.actionHandler.bindAction("network\\ipv6_packet", UIAction(self.on_ipv6_packet)) - self.actionHandler.bindAction("network\\microsoft_network_monitor_v2", UIAction(self.on_microsoft_network_monitor_v2)) - self.actionHandler.bindAction("network\\packet_ppi", UIAction(self.on_packet_ppi)) - self.actionHandler.bindAction("network\\pcap", UIAction(self.on_pcap)) - self.actionHandler.bindAction("network\\protocol_body", UIAction(self.on_protocol_body)) - - self.actionHandler.bindAction("network\\rtcp_payload", UIAction(self.on_rtcp_payload)) - self.actionHandler.bindAction("network\\rtp_packet", UIAction(self.on_rtp_packet)) - self.actionHandler.bindAction("network\\tcp_segment", UIAction(self.on_tcp_segment)) - self.actionHandler.bindAction("network\\tls_client_hello", UIAction(self.on_tls_client_hello)) - self.actionHandler.bindAction("network\\udp_datagram", UIAction(self.on_udp_datagram)) - self.actionHandler.bindAction("network\\windows_systemtime", UIAction(self.on_windows_systemtime)) - self.actionHandler.bindAction("scientific\\nt_mdt\\nt_mdt", UIAction(self.on_nt_mdt)) - self.actionHandler.bindAction("scientific\\nt_mdt\\nt_mdt_pal", UIAction(self.on_nt_mdt_pal)) - self.actionHandler.bindAction("scientific\\spectroscopy\\avantes_roh60", UIAction(self.on_avantes_roh60)) - self.actionHandler.bindAction("scientific\\spectroscopy\\specpr", UIAction(self.on_specpr)) - self.actionHandler.bindAction("security\\openpgp_message", UIAction(self.on_openpgp_message)) - self.actionHandler.bindAction("security\\ssh_public_key", UIAction(self.on_ssh_public_key)) - self.actionHandler.bindAction("serialization\\asn1\\asn1_der", UIAction(self.on_asn1_der)) - self.actionHandler.bindAction("serialization\\bson", UIAction(self.on_bson)) - self.actionHandler.bindAction("serialization\\google_protobuf", UIAction(self.on_google_protobuf)) - self.actionHandler.bindAction("serialization\\microsoft_cfb", UIAction(self.on_microsoft_cfb)) - self.actionHandler.bindAction("serialization\\msgpack", UIAction(self.on_msgpack)) - self.actionHandler.bindAction("serialization\\ruby_marshal", UIAction(self.on_ruby_marshal)) - self.actionHandler.bindAction("windows\\regf", UIAction(self.on_regf)) - self.actionHandler.bindAction("windows\\windows_lnk_file", UIAction(self.on_windows_lnk_file)) - self.actionHandler.bindAction("windows\\windows_minidump", UIAction(self.on_windows_minidump)) - self.actionHandler.bindAction("windows\\windows_resource_file", UIAction(self.on_windows_resource_file)) - self.actionHandler.bindAction("windows\\windows_shell_items", UIAction(self.on_windows_shell_items)) - self.actionHandler.bindAction("windows\\windows_systemtime", UIAction(self.on_windows_systemtime)) - - def mousePressEvent(self, event): - # when someone clicks our label, pop up the context menu - self.contextMenuManager.show(self.menu, self.actionHandler) - - def enterEvent(self, event): - self.setAutoFillBackground(True) - self.setForegroundRole(QPalette.HighlightedText) - QLabel.enterEvent(self, event) - - def leaveEvent(self, event): - self.setAutoFillBackground(False) - self.setForegroundRole(QPalette.WindowText) - QLabel.leaveEvent(self, event) - - def on_cpio_old_le(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('cpio_old_le') - - def on_gzip(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('gzip') - - def on_lzh(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('lzh') - - def on_rar(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('rar') - - def on_zip(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('zip') - - def on_monomakh_sapr_chg(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('monomakh_sapr_chg') - - def on_bcd(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('bcd') - - def on_dbf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dbf') - - def on_gettext_mo(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('gettext_mo') - - def on_sqlite3(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('sqlite3') - - def on_tsm(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('tsm') - - def on_dex(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dex') - - def on_dos_mz(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dos_mz') - - def on_elf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('elf') - - def on_java_class(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('java_class') - - def on_mach_o(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('mach_o') - - def on_microsoft_pe(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('microsoft_pe') - - def on_python_pyc_27(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('python_pyc_27') - - def on_swf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('swf') - - def on_apm_partition_table(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('apm_partition_table') - - def on_apple_single_double(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('apple_single_double') - - def on_cramfs(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('cramfs') - - def on_ext2(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ext2') - - def on_gpt_partition_table(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('gpt_partition_table') - - def on_iso9660(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('iso9660') - - def on_luks(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('luks') - - def on_lvm2(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('lvm2') - - def on_mbr_partition_table(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('mbr_partition_table') - - def on_tr_dos_image(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('tr_dos_image') - - def on_vdi(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('vdi') - - def on_vfat(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('vfat') - - def on_vmware_vmdk(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('vmware_vmdk') - - def on_andes_firmware(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('andes_firmware') - - def on_ines(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ines') - - def on_uimage(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('uimage') - - def on_ttf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ttf') - - def on_allegro_dat(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('allegro_dat') - - def on_doom_wad(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('doom_wad') - - def on_dune_2_pak(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dune_2_pak') - - def on_fallout2_dat(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('fallout2_dat') - - def on_fallout_dat(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('fallout_dat') - - def on_ftl_dat(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ftl_dat') - - def on_gran_turismo_vol(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('gran_turismo_vol') - - def on_heaps_pak(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('heaps_pak') - - def on_heroes_of_might_and_magic_agg(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('heroes_of_might_and_magic_agg') - - def on_heroes_of_might_and_magic_bmp(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('heroes_of_might_and_magic_bmp') - - def on_quake_mdl(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('quake_mdl') - - def on_quake_pak(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('quake_pak') - - def on_renderware_binary_stream(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('renderware_binary_stream') - - def on_saints_row_2_vpp_pc(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('saints_row_2_vpp_pc') - - def on_warcraft_2_pud(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('warcraft_2_pud') - - def on_shapefile_index(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('shapefile_index') - - def on_shapefile_main(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('shapefile_main') - - def on_edid(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('edid') - - def on_mifare_classic(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('mifare_classic') - - def on_bmp(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('bmp') - - def on_dicom(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dicom') - - def on_exif(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('exif') - - def on_exif_be(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('exif_be') - - def on_exif_le(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('exif_le') - - def on_gif(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('gif') - - def on_icc_4(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('icc_4') - - def on_ico(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ico') - - def on_jpeg(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('jpeg') - - def on_pcx(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('pcx') - - def on_pcx_dcx(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('pcx_dcx') - - def on_png(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('png') - - def on_psx_tim(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('psx_tim') - - def on_tga(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('tga') - - def on_wmf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('wmf') - - def on_xwd(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('xwd') - - def on_aix_utmp(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('aix_utmp') - - def on_glibc_utmp(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('glibc_utmp') - - def on_systemd_journal(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('systemd_journal') - - def on_windows_evt_log(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_evt_log') - - def on_code_6502(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('code_6502') - - def on_avi(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('avi') - - def on_blender_blend(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('blender_blend') - - def on_creative_voice_file(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('creative_voice_file') - - def on_genmidi_op2(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('genmidi_op2') - - def on_id3v1_1(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('id3v1_1') - - def on_id3v2_3(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('id3v2_3') - - def on_id3v2_4(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('id3v2_4') - - def on_magicavoxel_vox(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('magicavoxel_vox') - - def on_ogg(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ogg') - - def on_quicktime_mov(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('quicktime_mov') - - def on_standard_midi_file(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('standard_midi_file') - - def on_stl(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('stl') - - def on_fasttracker_xm_module(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('fasttracker_xm_module') - - def on_s3m(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('s3m') - - def on_vp8_ivf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('vp8_ivf') - - def on_wav(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('wav') - - def on_bitcoin_transaction(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('bitcoin_transaction') - - def on_dns_packet(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('dns_packet') - - def on_ethernet_frame(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ethernet_frame') - - def on_hccap(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('hccap') - - def on_hccapx(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('hccapx') - - def on_icmp_packet(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('icmp_packet') - - def on_ipv4_packet(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ipv4_packet') - - def on_ipv6_packet(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ipv6_packet') - - def on_microsoft_network_monitor_v2(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('microsoft_network_monitor_v2') - - def on_packet_ppi(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('packet_ppi') - - def on_pcap(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('pcap') - - def on_protocol_body(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('protocol_body') - - def on_rtcp_payload(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('rtcp_payload') - - def on_rtp_packet(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('rtp_packet') - - def on_tcp_segment(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('tcp_segment') - - def on_tls_client_hello(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('tls_client_hello') - - def on_udp_datagram(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('udp_datagram') - - def on_windows_systemtime(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_systemtime') - - def on_nt_mdt(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('nt_mdt') - - def on_nt_mdt_pal(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('nt_mdt_pal') - - def on_avantes_roh60(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('avantes_roh60') - - def on_specpr(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('specpr') - - def on_openpgp_message(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('openpgp_message') - - def on_ssh_public_key(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ssh_public_key') - - def on_asn1_der(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('asn1_der') - - def on_bson(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('bson') - - def on_google_protobuf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('google_protobuf') - - def on_microsoft_cfb(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('microsoft_cfb') - - def on_msgpack(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('msgpack') - - def on_ruby_marshal(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('ruby_marshal') - - def on_regf(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('regf') - - def on_windows_lnk_file(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_lnk_file') - - def on_windows_minidump(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_minidump') - - def on_windows_resource_file(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_resource_file') - - def on_windows_shell_items(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_shell_items') - - def on_windows_systemtime(self, uiActionContext): - self.statusBarWidget.kaitaiView.kaitaiParse('windows_systemtime') - - -# KaitaiStatusBarWidget <- StatusBarWidget <- QFrame -class KaitaiStatusBarWidget(StatusBarWidget): - def __init__(self, parent): - StatusBarWidget.__init__(self, parent) - - self.kaitaiView = parent - - self.layout = QHBoxLayout(self) - self.layout.setContentsMargins(0,0,0,0) - - self.options = KaitaiOptionsWidget(self) - self.layout.addWidget(self.options) - - def updateStatus(self): - #print 'updateStatus()' - pass diff --git a/python/examples/kaitai/microsoft_cfb.py b/python/examples/kaitai/microsoft_cfb.py deleted file mode 100644 index 578835b7..00000000 --- a/python/examples/kaitai/microsoft_cfb.py +++ /dev/null @@ -1,286 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 MicrosoftCfb(KaitaiStruct): - SEQ_FIELDS = ["header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.CfbHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class CfbHeader(KaitaiStruct): - SEQ_FIELDS = ["signature", "clsid", "version_minor", "version_major", "byte_order", "sector_shift", "mini_sector_shift", "reserved1", "size_dir", "size_fat", "ofs_dir", "transaction_seq", "mini_stream_cutoff_size", "ofs_mini_fat", "size_mini_fat", "ofs_difat", "size_difat", "difat"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") - self._debug['signature']['end'] = self._io.pos() - self._debug['clsid']['start'] = self._io.pos() - self.clsid = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - self._debug['clsid']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u2le() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u2le() - self._debug['version_major']['end'] = self._io.pos() - self._debug['byte_order']['start'] = self._io.pos() - self.byte_order = self._io.ensure_fixed_contents(b"\xFE\xFF") - self._debug['byte_order']['end'] = self._io.pos() - self._debug['sector_shift']['start'] = self._io.pos() - self.sector_shift = self._io.read_u2le() - self._debug['sector_shift']['end'] = self._io.pos() - self._debug['mini_sector_shift']['start'] = self._io.pos() - self.mini_sector_shift = self._io.read_u2le() - self._debug['mini_sector_shift']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(6) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['size_dir']['start'] = self._io.pos() - self.size_dir = self._io.read_s4le() - self._debug['size_dir']['end'] = self._io.pos() - self._debug['size_fat']['start'] = self._io.pos() - self.size_fat = self._io.read_s4le() - self._debug['size_fat']['end'] = self._io.pos() - self._debug['ofs_dir']['start'] = self._io.pos() - self.ofs_dir = self._io.read_s4le() - self._debug['ofs_dir']['end'] = self._io.pos() - self._debug['transaction_seq']['start'] = self._io.pos() - self.transaction_seq = self._io.read_s4le() - self._debug['transaction_seq']['end'] = self._io.pos() - self._debug['mini_stream_cutoff_size']['start'] = self._io.pos() - self.mini_stream_cutoff_size = self._io.read_s4le() - self._debug['mini_stream_cutoff_size']['end'] = self._io.pos() - self._debug['ofs_mini_fat']['start'] = self._io.pos() - self.ofs_mini_fat = self._io.read_s4le() - self._debug['ofs_mini_fat']['end'] = self._io.pos() - self._debug['size_mini_fat']['start'] = self._io.pos() - self.size_mini_fat = self._io.read_s4le() - self._debug['size_mini_fat']['end'] = self._io.pos() - self._debug['ofs_difat']['start'] = self._io.pos() - self.ofs_difat = self._io.read_s4le() - self._debug['ofs_difat']['end'] = self._io.pos() - self._debug['size_difat']['start'] = self._io.pos() - self.size_difat = self._io.read_s4le() - self._debug['size_difat']['end'] = self._io.pos() - self._debug['difat']['start'] = self._io.pos() - self.difat = [None] * (109) - for i in range(109): - if not 'arr' in self._debug['difat']: - self._debug['difat']['arr'] = [] - self._debug['difat']['arr'].append({'start': self._io.pos()}) - self.difat[i] = self._io.read_s4le() - self._debug['difat']['arr'][i]['end'] = self._io.pos() - - self._debug['difat']['end'] = self._io.pos() - - - class FatEntries(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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()}) - self.entries.append(self._io.read_s4le()) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - - class DirEntry(KaitaiStruct): - - class ObjType(Enum): - unknown = 0 - storage = 1 - stream = 2 - root_storage = 5 - - class RbColor(Enum): - red = 0 - black = 1 - SEQ_FIELDS = ["name", "name_len", "object_type", "color_flag", "left_sibling_id", "right_sibling_id", "child_id", "clsid", "state", "time_create", "time_mod", "ofs", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(64)).decode(u"UTF-16LE") - self._debug['name']['end'] = self._io.pos() - self._debug['name_len']['start'] = self._io.pos() - self.name_len = self._io.read_u2le() - self._debug['name_len']['end'] = self._io.pos() - self._debug['object_type']['start'] = self._io.pos() - self.object_type = KaitaiStream.resolve_enum(self._root.DirEntry.ObjType, self._io.read_u1()) - self._debug['object_type']['end'] = self._io.pos() - self._debug['color_flag']['start'] = self._io.pos() - self.color_flag = KaitaiStream.resolve_enum(self._root.DirEntry.RbColor, self._io.read_u1()) - self._debug['color_flag']['end'] = self._io.pos() - self._debug['left_sibling_id']['start'] = self._io.pos() - self.left_sibling_id = self._io.read_s4le() - self._debug['left_sibling_id']['end'] = self._io.pos() - self._debug['right_sibling_id']['start'] = self._io.pos() - self.right_sibling_id = self._io.read_s4le() - self._debug['right_sibling_id']['end'] = self._io.pos() - self._debug['child_id']['start'] = self._io.pos() - self.child_id = self._io.read_s4le() - self._debug['child_id']['end'] = self._io.pos() - self._debug['clsid']['start'] = self._io.pos() - self.clsid = self._io.read_bytes(16) - self._debug['clsid']['end'] = self._io.pos() - self._debug['state']['start'] = self._io.pos() - self.state = self._io.read_u4le() - self._debug['state']['end'] = self._io.pos() - self._debug['time_create']['start'] = self._io.pos() - self.time_create = self._io.read_u8le() - self._debug['time_create']['end'] = self._io.pos() - self._debug['time_mod']['start'] = self._io.pos() - self.time_mod = self._io.read_u8le() - self._debug['time_mod']['end'] = self._io.pos() - self._debug['ofs']['start'] = self._io.pos() - self.ofs = self._io.read_s4le() - self._debug['ofs']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u8le() - self._debug['size']['end'] = self._io.pos() - - @property - def mini_stream(self): - if hasattr(self, '_m_mini_stream'): - return self._m_mini_stream if hasattr(self, '_m_mini_stream') else None - - if self.object_type == self._root.DirEntry.ObjType.root_storage: - io = self._root._io - _pos = io.pos() - io.seek(((self.ofs + 1) * self._root.sector_size)) - self._debug['_m_mini_stream']['start'] = io.pos() - self._m_mini_stream = io.read_bytes(self.size) - self._debug['_m_mini_stream']['end'] = io.pos() - io.seek(_pos) - - return self._m_mini_stream if hasattr(self, '_m_mini_stream') else None - - @property - def child(self): - if hasattr(self, '_m_child'): - return self._m_child if hasattr(self, '_m_child') else None - - if self.child_id != -1: - io = self._root._io - _pos = io.pos() - io.seek((((self._root.header.ofs_dir + 1) * self._root.sector_size) + (self.child_id * 128))) - self._debug['_m_child']['start'] = io.pos() - self._m_child = self._root.DirEntry(io, self, self._root) - self._m_child._read() - self._debug['_m_child']['end'] = io.pos() - io.seek(_pos) - - return self._m_child if hasattr(self, '_m_child') else None - - @property - def left_sibling(self): - if hasattr(self, '_m_left_sibling'): - return self._m_left_sibling if hasattr(self, '_m_left_sibling') else None - - if self.left_sibling_id != -1: - io = self._root._io - _pos = io.pos() - io.seek((((self._root.header.ofs_dir + 1) * self._root.sector_size) + (self.left_sibling_id * 128))) - self._debug['_m_left_sibling']['start'] = io.pos() - self._m_left_sibling = self._root.DirEntry(io, self, self._root) - self._m_left_sibling._read() - self._debug['_m_left_sibling']['end'] = io.pos() - io.seek(_pos) - - return self._m_left_sibling if hasattr(self, '_m_left_sibling') else None - - @property - def right_sibling(self): - if hasattr(self, '_m_right_sibling'): - return self._m_right_sibling if hasattr(self, '_m_right_sibling') else None - - if self.right_sibling_id != -1: - io = self._root._io - _pos = io.pos() - io.seek((((self._root.header.ofs_dir + 1) * self._root.sector_size) + (self.right_sibling_id * 128))) - self._debug['_m_right_sibling']['start'] = io.pos() - self._m_right_sibling = self._root.DirEntry(io, self, self._root) - self._m_right_sibling._read() - self._debug['_m_right_sibling']['end'] = io.pos() - io.seek(_pos) - - return self._m_right_sibling if hasattr(self, '_m_right_sibling') else None - - - @property - def sector_size(self): - if hasattr(self, '_m_sector_size'): - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - self._m_sector_size = (1 << self.header.sector_shift) - return self._m_sector_size if hasattr(self, '_m_sector_size') else None - - @property - def fat(self): - if hasattr(self, '_m_fat'): - return self._m_fat if hasattr(self, '_m_fat') else None - - _pos = self._io.pos() - self._io.seek(self.sector_size) - self._debug['_m_fat']['start'] = self._io.pos() - self._raw__m_fat = self._io.read_bytes((self.header.size_fat * self.sector_size)) - io = KaitaiStream(BytesIO(self._raw__m_fat)) - self._m_fat = self._root.FatEntries(io, self, self._root) - self._m_fat._read() - self._debug['_m_fat']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_fat if hasattr(self, '_m_fat') else None - - @property - def dir(self): - if hasattr(self, '_m_dir'): - return self._m_dir if hasattr(self, '_m_dir') else None - - _pos = self._io.pos() - self._io.seek(((self.header.ofs_dir + 1) * self.sector_size)) - self._debug['_m_dir']['start'] = self._io.pos() - self._m_dir = self._root.DirEntry(self._io, self, self._root) - self._m_dir._read() - self._debug['_m_dir']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_dir if hasattr(self, '_m_dir') else None - - diff --git a/python/examples/kaitai/microsoft_network_monitor_v2.py b/python/examples/kaitai/microsoft_network_monitor_v2.py deleted file mode 100644 index be145e11..00000000 --- a/python/examples/kaitai/microsoft_network_monitor_v2.py +++ /dev/null @@ -1,306 +0,0 @@ -# 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 -import collections - - -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)) - -from . import windows_systemtime -from . import ethernet_frame -class MicrosoftNetworkMonitorV2(KaitaiStruct): - """Microsoft Network Monitor (AKA Netmon) is a proprietary Microsoft's - network packet sniffing and analysis tool. It can save captured - traffic as .cap files, which usually contain the packets and may - contain some additional info - enhanced network info, calculated - statistics, etc. - - There are at least 2 different versions of the format: v1 and - v2. Netmon v3 seems to use the same file format as v1. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/ee817717.aspx - """ - - class Linktype(Enum): - null_linktype = 0 - ethernet = 1 - ax25 = 3 - ieee802_5 = 6 - arcnet_bsd = 7 - slip = 8 - ppp = 9 - fddi = 10 - ppp_hdlc = 50 - ppp_ether = 51 - atm_rfc1483 = 100 - raw = 101 - c_hdlc = 104 - ieee802_11 = 105 - frelay = 107 - loop = 108 - linux_sll = 113 - ltalk = 114 - pflog = 117 - ieee802_11_prism = 119 - ip_over_fc = 122 - sunatm = 123 - ieee802_11_radiotap = 127 - arcnet_linux = 129 - apple_ip_over_ieee1394 = 138 - mtp2_with_phdr = 139 - mtp2 = 140 - mtp3 = 141 - sccp = 142 - docsis = 143 - linux_irda = 144 - user0 = 147 - user1 = 148 - user2 = 149 - user3 = 150 - user4 = 151 - user5 = 152 - user6 = 153 - user7 = 154 - user8 = 155 - user9 = 156 - user10 = 157 - user11 = 158 - user12 = 159 - user13 = 160 - user14 = 161 - user15 = 162 - ieee802_11_avs = 163 - bacnet_ms_tp = 165 - ppp_pppd = 166 - gprs_llc = 169 - gpf_t = 170 - gpf_f = 171 - linux_lapd = 177 - bluetooth_hci_h4 = 187 - usb_linux = 189 - ppi = 192 - ieee802_15_4 = 195 - sita = 196 - erf = 197 - bluetooth_hci_h4_with_phdr = 201 - ax25_kiss = 202 - lapd = 203 - ppp_with_dir = 204 - c_hdlc_with_dir = 205 - frelay_with_dir = 206 - ipmb_linux = 209 - ieee802_15_4_nonask_phy = 215 - usb_linux_mmapped = 220 - fc_2 = 224 - fc_2_with_frame_delims = 225 - ipnet = 226 - can_socketcan = 227 - ipv4 = 228 - ipv6 = 229 - ieee802_15_4_nofcs = 230 - dbus = 231 - dvb_ci = 235 - mux27010 = 236 - stanag_5066_d_pdu = 237 - nflog = 239 - netanalyzer = 240 - netanalyzer_transparent = 241 - ipoib = 242 - mpeg_2_ts = 243 - ng40 = 244 - nfc_llcp = 245 - infiniband = 247 - sctp = 248 - usbpcap = 249 - rtac_serial = 250 - bluetooth_le_ll = 251 - netlink = 253 - bluetooth_linux_monitor = 254 - bluetooth_bredr_bb = 255 - bluetooth_le_ll_with_phdr = 256 - profibus_dl = 257 - pktap = 258 - epon = 259 - ipmi_hpm_2 = 260 - zwave_r1_r2 = 261 - zwave_r3 = 262 - wattstopper_dlm = 263 - iso_14443 = 264 - SEQ_FIELDS = ["signature", "version_minor", "version_major", "mac_type", "time_capture_start", "frame_table_ofs", "frame_table_len", "user_data_ofs", "user_data_len", "comment_ofs", "comment_len", "statistics_ofs", "statistics_len", "network_info_ofs", "network_info_len", "conversation_stats_ofs", "conversation_stats_len"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x47\x4D\x42\x55") - self._debug['signature']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u1() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u1() - self._debug['version_major']['end'] = self._io.pos() - self._debug['mac_type']['start'] = self._io.pos() - self.mac_type = KaitaiStream.resolve_enum(self._root.Linktype, self._io.read_u2le()) - self._debug['mac_type']['end'] = self._io.pos() - self._debug['time_capture_start']['start'] = self._io.pos() - self.time_capture_start = windows_systemtime.WindowsSystemtime(self._io) - self.time_capture_start._read() - self._debug['time_capture_start']['end'] = self._io.pos() - self._debug['frame_table_ofs']['start'] = self._io.pos() - self.frame_table_ofs = self._io.read_u4le() - self._debug['frame_table_ofs']['end'] = self._io.pos() - self._debug['frame_table_len']['start'] = self._io.pos() - self.frame_table_len = self._io.read_u4le() - self._debug['frame_table_len']['end'] = self._io.pos() - self._debug['user_data_ofs']['start'] = self._io.pos() - self.user_data_ofs = self._io.read_u4le() - self._debug['user_data_ofs']['end'] = self._io.pos() - self._debug['user_data_len']['start'] = self._io.pos() - self.user_data_len = self._io.read_u4le() - self._debug['user_data_len']['end'] = self._io.pos() - self._debug['comment_ofs']['start'] = self._io.pos() - self.comment_ofs = self._io.read_u4le() - self._debug['comment_ofs']['end'] = self._io.pos() - self._debug['comment_len']['start'] = self._io.pos() - self.comment_len = self._io.read_u4le() - self._debug['comment_len']['end'] = self._io.pos() - self._debug['statistics_ofs']['start'] = self._io.pos() - self.statistics_ofs = self._io.read_u4le() - self._debug['statistics_ofs']['end'] = self._io.pos() - self._debug['statistics_len']['start'] = self._io.pos() - self.statistics_len = self._io.read_u4le() - self._debug['statistics_len']['end'] = self._io.pos() - self._debug['network_info_ofs']['start'] = self._io.pos() - self.network_info_ofs = self._io.read_u4le() - self._debug['network_info_ofs']['end'] = self._io.pos() - self._debug['network_info_len']['start'] = self._io.pos() - self.network_info_len = self._io.read_u4le() - self._debug['network_info_len']['end'] = self._io.pos() - self._debug['conversation_stats_ofs']['start'] = self._io.pos() - self.conversation_stats_ofs = self._io.read_u4le() - self._debug['conversation_stats_ofs']['end'] = self._io.pos() - self._debug['conversation_stats_len']['start'] = self._io.pos() - self.conversation_stats_len = self._io.read_u4le() - self._debug['conversation_stats_len']['end'] = self._io.pos() - - class FrameIndex(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.FrameIndexEntry(self._io, self, self._root) - _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() - - - class FrameIndexEntry(KaitaiStruct): - """Each index entry is just a pointer to where the frame data is - stored in the file. - """ - SEQ_FIELDS = ["ofs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs']['start'] = self._io.pos() - self.ofs = self._io.read_u4le() - self._debug['ofs']['end'] = self._io.pos() - - @property - def body(self): - """Frame body itself.""" - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs) - self._debug['_m_body']['start'] = io.pos() - self._m_body = self._root.Frame(io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = io.pos() - io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class Frame(KaitaiStruct): - """A container for actually captured network data. Allow to - timestamp individual frames and designates how much data from - the original packet was actually written into the file. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/ee831821.aspx - """ - SEQ_FIELDS = ["ts_delta", "orig_len", "inc_len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ts_delta']['start'] = self._io.pos() - self.ts_delta = self._io.read_u8le() - self._debug['ts_delta']['end'] = self._io.pos() - self._debug['orig_len']['start'] = self._io.pos() - self.orig_len = self._io.read_u4le() - self._debug['orig_len']['end'] = self._io.pos() - self._debug['inc_len']['start'] = self._io.pos() - self.inc_len = self._io.read_u4le() - self._debug['inc_len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self._root.mac_type - if _on == self._root.Linktype.ethernet: - self._raw_body = self._io.read_bytes(self.inc_len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = ethernet_frame.EthernetFrame(io) - self.body._read() - else: - self.body = self._io.read_bytes(self.inc_len) - self._debug['body']['end'] = self._io.pos() - - - @property - def frame_table(self): - """Index that is used to access individual captured frames.""" - if hasattr(self, '_m_frame_table'): - return self._m_frame_table if hasattr(self, '_m_frame_table') else None - - _pos = self._io.pos() - self._io.seek(self.frame_table_ofs) - self._debug['_m_frame_table']['start'] = self._io.pos() - self._raw__m_frame_table = self._io.read_bytes(self.frame_table_len) - io = KaitaiStream(BytesIO(self._raw__m_frame_table)) - self._m_frame_table = self._root.FrameIndex(io, self, self._root) - self._m_frame_table._read() - self._debug['_m_frame_table']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_frame_table if hasattr(self, '_m_frame_table') else None - - diff --git a/python/examples/kaitai/microsoft_pe.py b/python/examples/kaitai/microsoft_pe.py deleted file mode 100644 index 325b823a..00000000 --- a/python/examples/kaitai/microsoft_pe.py +++ /dev/null @@ -1,758 +0,0 @@ -# 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 -import collections - - -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 MicrosoftPe(KaitaiStruct): - """ - .. seealso:: - Source - http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx - """ - - class PeFormat(Enum): - rom_image = 263 - pe32 = 267 - pe32_plus = 523 - SEQ_FIELDS = ["mz"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['mz']['start'] = self._io.pos() - self.mz = self._root.MzPlaceholder(self._io, self, self._root) - self.mz._read() - self._debug['mz']['end'] = self._io.pos() - - class CertificateEntry(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#the-attribute-certificate-table-image-only - """ - - class CertificateRevision(Enum): - revision_1_0 = 256 - revision_2_0 = 512 - - class CertificateType(Enum): - x509 = 1 - pkcs_signed_data = 2 - reserved_1 = 3 - ts_stack_signed = 4 - SEQ_FIELDS = ["length", "revision", "certificate_type", "certificate_bytes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['revision']['start'] = self._io.pos() - self.revision = KaitaiStream.resolve_enum(self._root.CertificateEntry.CertificateRevision, self._io.read_u2le()) - self._debug['revision']['end'] = self._io.pos() - self._debug['certificate_type']['start'] = self._io.pos() - self.certificate_type = KaitaiStream.resolve_enum(self._root.CertificateEntry.CertificateType, self._io.read_u2le()) - self._debug['certificate_type']['end'] = self._io.pos() - self._debug['certificate_bytes']['start'] = self._io.pos() - self.certificate_bytes = self._io.read_bytes((self.length - 8)) - self._debug['certificate_bytes']['end'] = self._io.pos() - - - class OptionalHeaderWindows(KaitaiStruct): - - class SubsystemEnum(Enum): - unknown = 0 - native = 1 - windows_gui = 2 - windows_cui = 3 - posix_cui = 7 - windows_ce_gui = 9 - efi_application = 10 - efi_boot_service_driver = 11 - efi_runtime_driver = 12 - efi_rom = 13 - xbox = 14 - windows_boot_application = 16 - SEQ_FIELDS = ["image_base_32", "image_base_64", "section_alignment", "file_alignment", "major_operating_system_version", "minor_operating_system_version", "major_image_version", "minor_image_version", "major_subsystem_version", "minor_subsystem_version", "win32_version_value", "size_of_image", "size_of_headers", "check_sum", "subsystem", "dll_characteristics", "size_of_stack_reserve_32", "size_of_stack_reserve_64", "size_of_stack_commit_32", "size_of_stack_commit_64", "size_of_heap_reserve_32", "size_of_heap_reserve_64", "size_of_heap_commit_32", "size_of_heap_commit_64", "loader_flags", "number_of_rva_and_sizes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - if self._parent.std.format == self._root.PeFormat.pe32: - self._debug['image_base_32']['start'] = self._io.pos() - self.image_base_32 = self._io.read_u4le() - self._debug['image_base_32']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32_plus: - self._debug['image_base_64']['start'] = self._io.pos() - self.image_base_64 = self._io.read_u8le() - self._debug['image_base_64']['end'] = self._io.pos() - - self._debug['section_alignment']['start'] = self._io.pos() - self.section_alignment = self._io.read_u4le() - self._debug['section_alignment']['end'] = self._io.pos() - self._debug['file_alignment']['start'] = self._io.pos() - self.file_alignment = self._io.read_u4le() - self._debug['file_alignment']['end'] = self._io.pos() - self._debug['major_operating_system_version']['start'] = self._io.pos() - self.major_operating_system_version = self._io.read_u2le() - self._debug['major_operating_system_version']['end'] = self._io.pos() - self._debug['minor_operating_system_version']['start'] = self._io.pos() - self.minor_operating_system_version = self._io.read_u2le() - self._debug['minor_operating_system_version']['end'] = self._io.pos() - self._debug['major_image_version']['start'] = self._io.pos() - self.major_image_version = self._io.read_u2le() - self._debug['major_image_version']['end'] = self._io.pos() - self._debug['minor_image_version']['start'] = self._io.pos() - self.minor_image_version = self._io.read_u2le() - self._debug['minor_image_version']['end'] = self._io.pos() - self._debug['major_subsystem_version']['start'] = self._io.pos() - self.major_subsystem_version = self._io.read_u2le() - self._debug['major_subsystem_version']['end'] = self._io.pos() - self._debug['minor_subsystem_version']['start'] = self._io.pos() - self.minor_subsystem_version = self._io.read_u2le() - self._debug['minor_subsystem_version']['end'] = self._io.pos() - self._debug['win32_version_value']['start'] = self._io.pos() - self.win32_version_value = self._io.read_u4le() - self._debug['win32_version_value']['end'] = self._io.pos() - self._debug['size_of_image']['start'] = self._io.pos() - self.size_of_image = self._io.read_u4le() - self._debug['size_of_image']['end'] = self._io.pos() - self._debug['size_of_headers']['start'] = self._io.pos() - self.size_of_headers = self._io.read_u4le() - self._debug['size_of_headers']['end'] = self._io.pos() - self._debug['check_sum']['start'] = self._io.pos() - self.check_sum = self._io.read_u4le() - self._debug['check_sum']['end'] = self._io.pos() - self._debug['subsystem']['start'] = self._io.pos() - self.subsystem = KaitaiStream.resolve_enum(self._root.OptionalHeaderWindows.SubsystemEnum, self._io.read_u2le()) - self._debug['subsystem']['end'] = self._io.pos() - self._debug['dll_characteristics']['start'] = self._io.pos() - self.dll_characteristics = self._io.read_u2le() - self._debug['dll_characteristics']['end'] = self._io.pos() - if self._parent.std.format == self._root.PeFormat.pe32: - self._debug['size_of_stack_reserve_32']['start'] = self._io.pos() - self.size_of_stack_reserve_32 = self._io.read_u4le() - self._debug['size_of_stack_reserve_32']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32_plus: - self._debug['size_of_stack_reserve_64']['start'] = self._io.pos() - self.size_of_stack_reserve_64 = self._io.read_u8le() - self._debug['size_of_stack_reserve_64']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32: - self._debug['size_of_stack_commit_32']['start'] = self._io.pos() - self.size_of_stack_commit_32 = self._io.read_u4le() - self._debug['size_of_stack_commit_32']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32_plus: - self._debug['size_of_stack_commit_64']['start'] = self._io.pos() - self.size_of_stack_commit_64 = self._io.read_u8le() - self._debug['size_of_stack_commit_64']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32: - self._debug['size_of_heap_reserve_32']['start'] = self._io.pos() - self.size_of_heap_reserve_32 = self._io.read_u4le() - self._debug['size_of_heap_reserve_32']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32_plus: - self._debug['size_of_heap_reserve_64']['start'] = self._io.pos() - self.size_of_heap_reserve_64 = self._io.read_u8le() - self._debug['size_of_heap_reserve_64']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32: - self._debug['size_of_heap_commit_32']['start'] = self._io.pos() - self.size_of_heap_commit_32 = self._io.read_u4le() - self._debug['size_of_heap_commit_32']['end'] = self._io.pos() - - if self._parent.std.format == self._root.PeFormat.pe32_plus: - self._debug['size_of_heap_commit_64']['start'] = self._io.pos() - self.size_of_heap_commit_64 = self._io.read_u8le() - self._debug['size_of_heap_commit_64']['end'] = self._io.pos() - - self._debug['loader_flags']['start'] = self._io.pos() - self.loader_flags = self._io.read_u4le() - self._debug['loader_flags']['end'] = self._io.pos() - self._debug['number_of_rva_and_sizes']['start'] = self._io.pos() - self.number_of_rva_and_sizes = self._io.read_u4le() - self._debug['number_of_rva_and_sizes']['end'] = self._io.pos() - - - class OptionalHeaderDataDirs(KaitaiStruct): - SEQ_FIELDS = ["export_table", "import_table", "resource_table", "exception_table", "certificate_table", "base_relocation_table", "debug", "architecture", "global_ptr", "tls_table", "load_config_table", "bound_import", "iat", "delay_import_descriptor", "clr_runtime_header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['export_table']['start'] = self._io.pos() - self.export_table = self._root.DataDir(self._io, self, self._root) - self.export_table._read() - self._debug['export_table']['end'] = self._io.pos() - self._debug['import_table']['start'] = self._io.pos() - self.import_table = self._root.DataDir(self._io, self, self._root) - self.import_table._read() - self._debug['import_table']['end'] = self._io.pos() - self._debug['resource_table']['start'] = self._io.pos() - self.resource_table = self._root.DataDir(self._io, self, self._root) - self.resource_table._read() - self._debug['resource_table']['end'] = self._io.pos() - self._debug['exception_table']['start'] = self._io.pos() - self.exception_table = self._root.DataDir(self._io, self, self._root) - self.exception_table._read() - self._debug['exception_table']['end'] = self._io.pos() - self._debug['certificate_table']['start'] = self._io.pos() - self.certificate_table = self._root.DataDir(self._io, self, self._root) - self.certificate_table._read() - self._debug['certificate_table']['end'] = self._io.pos() - self._debug['base_relocation_table']['start'] = self._io.pos() - self.base_relocation_table = self._root.DataDir(self._io, self, self._root) - self.base_relocation_table._read() - self._debug['base_relocation_table']['end'] = self._io.pos() - self._debug['debug']['start'] = self._io.pos() - self.debug = self._root.DataDir(self._io, self, self._root) - self.debug._read() - self._debug['debug']['end'] = self._io.pos() - self._debug['architecture']['start'] = self._io.pos() - self.architecture = self._root.DataDir(self._io, self, self._root) - self.architecture._read() - self._debug['architecture']['end'] = self._io.pos() - self._debug['global_ptr']['start'] = self._io.pos() - self.global_ptr = self._root.DataDir(self._io, self, self._root) - self.global_ptr._read() - self._debug['global_ptr']['end'] = self._io.pos() - self._debug['tls_table']['start'] = self._io.pos() - self.tls_table = self._root.DataDir(self._io, self, self._root) - self.tls_table._read() - self._debug['tls_table']['end'] = self._io.pos() - self._debug['load_config_table']['start'] = self._io.pos() - self.load_config_table = self._root.DataDir(self._io, self, self._root) - self.load_config_table._read() - self._debug['load_config_table']['end'] = self._io.pos() - self._debug['bound_import']['start'] = self._io.pos() - self.bound_import = self._root.DataDir(self._io, self, self._root) - self.bound_import._read() - self._debug['bound_import']['end'] = self._io.pos() - self._debug['iat']['start'] = self._io.pos() - self.iat = self._root.DataDir(self._io, self, self._root) - self.iat._read() - self._debug['iat']['end'] = self._io.pos() - self._debug['delay_import_descriptor']['start'] = self._io.pos() - self.delay_import_descriptor = self._root.DataDir(self._io, self, self._root) - self.delay_import_descriptor._read() - self._debug['delay_import_descriptor']['end'] = self._io.pos() - self._debug['clr_runtime_header']['start'] = self._io.pos() - self.clr_runtime_header = self._root.DataDir(self._io, self, self._root) - self.clr_runtime_header._read() - self._debug['clr_runtime_header']['end'] = self._io.pos() - - - class DataDir(KaitaiStruct): - SEQ_FIELDS = ["virtual_address", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['virtual_address']['start'] = self._io.pos() - self.virtual_address = self._io.read_u4le() - self._debug['virtual_address']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - - - class CoffSymbol(KaitaiStruct): - SEQ_FIELDS = ["name_annoying", "value", "section_number", "type", "storage_class", "number_of_aux_symbols"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_annoying']['start'] = self._io.pos() - self._raw_name_annoying = self._io.read_bytes(8) - io = KaitaiStream(BytesIO(self._raw_name_annoying)) - self.name_annoying = self._root.Annoyingstring(io, self, self._root) - self.name_annoying._read() - self._debug['name_annoying']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u4le() - self._debug['value']['end'] = self._io.pos() - self._debug['section_number']['start'] = self._io.pos() - self.section_number = self._io.read_u2le() - self._debug['section_number']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u2le() - self._debug['type']['end'] = self._io.pos() - self._debug['storage_class']['start'] = self._io.pos() - self.storage_class = self._io.read_u1() - self._debug['storage_class']['end'] = self._io.pos() - self._debug['number_of_aux_symbols']['start'] = self._io.pos() - self.number_of_aux_symbols = self._io.read_u1() - self._debug['number_of_aux_symbols']['end'] = self._io.pos() - - @property - def section(self): - if hasattr(self, '_m_section'): - return self._m_section if hasattr(self, '_m_section') else None - - self._m_section = self._root.pe.sections[(self.section_number - 1)] - return self._m_section if hasattr(self, '_m_section') else None - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - _pos = self._io.pos() - self._io.seek((self.section.pointer_to_raw_data + self.value)) - self._debug['_m_data']['start'] = self._io.pos() - self._m_data = self._io.read_bytes(1) - self._debug['_m_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - class PeHeader(KaitaiStruct): - SEQ_FIELDS = ["pe_signature", "coff_hdr", "optional_hdr", "sections"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pe_signature']['start'] = self._io.pos() - self.pe_signature = self._io.ensure_fixed_contents(b"\x50\x45\x00\x00") - self._debug['pe_signature']['end'] = self._io.pos() - self._debug['coff_hdr']['start'] = self._io.pos() - self.coff_hdr = self._root.CoffHeader(self._io, self, self._root) - self.coff_hdr._read() - self._debug['coff_hdr']['end'] = self._io.pos() - self._debug['optional_hdr']['start'] = self._io.pos() - self._raw_optional_hdr = self._io.read_bytes(self.coff_hdr.size_of_optional_header) - io = KaitaiStream(BytesIO(self._raw_optional_hdr)) - self.optional_hdr = self._root.OptionalHeader(io, self, self._root) - self.optional_hdr._read() - self._debug['optional_hdr']['end'] = self._io.pos() - self._debug['sections']['start'] = self._io.pos() - self.sections = [None] * (self.coff_hdr.number_of_sections) - for i in range(self.coff_hdr.number_of_sections): - if not 'arr' in self._debug['sections']: - self._debug['sections']['arr'] = [] - self._debug['sections']['arr'].append({'start': self._io.pos()}) - _t_sections = self._root.Section(self._io, self, self._root) - _t_sections._read() - self.sections[i] = _t_sections - self._debug['sections']['arr'][i]['end'] = self._io.pos() - - self._debug['sections']['end'] = self._io.pos() - - @property - def certificate_table(self): - if hasattr(self, '_m_certificate_table'): - return self._m_certificate_table if hasattr(self, '_m_certificate_table') else None - - if self.optional_hdr.data_dirs.certificate_table.virtual_address != 0: - _pos = self._io.pos() - self._io.seek(self.optional_hdr.data_dirs.certificate_table.virtual_address) - self._debug['_m_certificate_table']['start'] = self._io.pos() - self._raw__m_certificate_table = self._io.read_bytes(self.optional_hdr.data_dirs.certificate_table.size) - io = KaitaiStream(BytesIO(self._raw__m_certificate_table)) - self._m_certificate_table = self._root.CertificateTable(io, self, self._root) - self._m_certificate_table._read() - self._debug['_m_certificate_table']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_certificate_table if hasattr(self, '_m_certificate_table') else None - - - class OptionalHeader(KaitaiStruct): - SEQ_FIELDS = ["std", "windows", "data_dirs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['std']['start'] = self._io.pos() - self.std = self._root.OptionalHeaderStd(self._io, self, self._root) - self.std._read() - self._debug['std']['end'] = self._io.pos() - self._debug['windows']['start'] = self._io.pos() - self.windows = self._root.OptionalHeaderWindows(self._io, self, self._root) - self.windows._read() - self._debug['windows']['end'] = self._io.pos() - self._debug['data_dirs']['start'] = self._io.pos() - self.data_dirs = self._root.OptionalHeaderDataDirs(self._io, self, self._root) - self.data_dirs._read() - self._debug['data_dirs']['end'] = self._io.pos() - - - class Section(KaitaiStruct): - SEQ_FIELDS = ["name", "virtual_size", "virtual_address", "size_of_raw_data", "pointer_to_raw_data", "pointer_to_relocations", "pointer_to_linenumbers", "number_of_relocations", "number_of_linenumbers", "characteristics"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 0)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - self._debug['virtual_size']['start'] = self._io.pos() - self.virtual_size = self._io.read_u4le() - self._debug['virtual_size']['end'] = self._io.pos() - self._debug['virtual_address']['start'] = self._io.pos() - self.virtual_address = self._io.read_u4le() - self._debug['virtual_address']['end'] = self._io.pos() - self._debug['size_of_raw_data']['start'] = self._io.pos() - self.size_of_raw_data = self._io.read_u4le() - self._debug['size_of_raw_data']['end'] = self._io.pos() - self._debug['pointer_to_raw_data']['start'] = self._io.pos() - self.pointer_to_raw_data = self._io.read_u4le() - self._debug['pointer_to_raw_data']['end'] = self._io.pos() - self._debug['pointer_to_relocations']['start'] = self._io.pos() - self.pointer_to_relocations = self._io.read_u4le() - self._debug['pointer_to_relocations']['end'] = self._io.pos() - self._debug['pointer_to_linenumbers']['start'] = self._io.pos() - self.pointer_to_linenumbers = self._io.read_u4le() - self._debug['pointer_to_linenumbers']['end'] = self._io.pos() - self._debug['number_of_relocations']['start'] = self._io.pos() - self.number_of_relocations = self._io.read_u2le() - self._debug['number_of_relocations']['end'] = self._io.pos() - self._debug['number_of_linenumbers']['start'] = self._io.pos() - self.number_of_linenumbers = self._io.read_u2le() - self._debug['number_of_linenumbers']['end'] = self._io.pos() - self._debug['characteristics']['start'] = self._io.pos() - self.characteristics = self._io.read_u4le() - self._debug['characteristics']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek(self.pointer_to_raw_data) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._io.read_bytes(self.size_of_raw_data) - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class CertificateTable(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.CertificateEntry(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - class MzPlaceholder(KaitaiStruct): - SEQ_FIELDS = ["magic", "data1", "ofs_pe"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4D\x5A") - self._debug['magic']['end'] = self._io.pos() - self._debug['data1']['start'] = self._io.pos() - self.data1 = self._io.read_bytes(58) - self._debug['data1']['end'] = self._io.pos() - self._debug['ofs_pe']['start'] = self._io.pos() - self.ofs_pe = self._io.read_u4le() - self._debug['ofs_pe']['end'] = self._io.pos() - - - class OptionalHeaderStd(KaitaiStruct): - SEQ_FIELDS = ["format", "major_linker_version", "minor_linker_version", "size_of_code", "size_of_initialized_data", "size_of_uninitialized_data", "address_of_entry_point", "base_of_code", "base_of_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['format']['start'] = self._io.pos() - self.format = KaitaiStream.resolve_enum(self._root.PeFormat, self._io.read_u2le()) - self._debug['format']['end'] = self._io.pos() - self._debug['major_linker_version']['start'] = self._io.pos() - self.major_linker_version = self._io.read_u1() - self._debug['major_linker_version']['end'] = self._io.pos() - self._debug['minor_linker_version']['start'] = self._io.pos() - self.minor_linker_version = self._io.read_u1() - self._debug['minor_linker_version']['end'] = self._io.pos() - self._debug['size_of_code']['start'] = self._io.pos() - self.size_of_code = self._io.read_u4le() - self._debug['size_of_code']['end'] = self._io.pos() - self._debug['size_of_initialized_data']['start'] = self._io.pos() - self.size_of_initialized_data = self._io.read_u4le() - self._debug['size_of_initialized_data']['end'] = self._io.pos() - self._debug['size_of_uninitialized_data']['start'] = self._io.pos() - self.size_of_uninitialized_data = self._io.read_u4le() - self._debug['size_of_uninitialized_data']['end'] = self._io.pos() - self._debug['address_of_entry_point']['start'] = self._io.pos() - self.address_of_entry_point = self._io.read_u4le() - self._debug['address_of_entry_point']['end'] = self._io.pos() - self._debug['base_of_code']['start'] = self._io.pos() - self.base_of_code = self._io.read_u4le() - self._debug['base_of_code']['end'] = self._io.pos() - if self.format == self._root.PeFormat.pe32: - self._debug['base_of_data']['start'] = self._io.pos() - self.base_of_data = self._io.read_u4le() - self._debug['base_of_data']['end'] = self._io.pos() - - - - class CoffHeader(KaitaiStruct): - """ - .. seealso:: - 3.3. COFF File Header (Object and Image) - """ - - class MachineType(Enum): - unknown = 0 - i386 = 332 - r4000 = 358 - wcemipsv2 = 361 - alpha = 388 - sh3 = 418 - sh3dsp = 419 - sh4 = 422 - sh5 = 424 - arm = 448 - thumb = 450 - armnt = 452 - am33 = 467 - powerpc = 496 - powerpcfp = 497 - ia64 = 512 - mips16 = 614 - mipsfpu = 870 - mipsfpu16 = 1126 - ebc = 3772 - riscv32 = 20530 - riscv64 = 20580 - riscv128 = 20776 - amd64 = 34404 - m32r = 36929 - arm64 = 43620 - SEQ_FIELDS = ["machine", "number_of_sections", "time_date_stamp", "pointer_to_symbol_table", "number_of_symbols", "size_of_optional_header", "characteristics"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['machine']['start'] = self._io.pos() - self.machine = KaitaiStream.resolve_enum(self._root.CoffHeader.MachineType, self._io.read_u2le()) - self._debug['machine']['end'] = self._io.pos() - self._debug['number_of_sections']['start'] = self._io.pos() - self.number_of_sections = self._io.read_u2le() - self._debug['number_of_sections']['end'] = self._io.pos() - self._debug['time_date_stamp']['start'] = self._io.pos() - self.time_date_stamp = self._io.read_u4le() - self._debug['time_date_stamp']['end'] = self._io.pos() - self._debug['pointer_to_symbol_table']['start'] = self._io.pos() - self.pointer_to_symbol_table = self._io.read_u4le() - self._debug['pointer_to_symbol_table']['end'] = self._io.pos() - self._debug['number_of_symbols']['start'] = self._io.pos() - self.number_of_symbols = self._io.read_u4le() - self._debug['number_of_symbols']['end'] = self._io.pos() - self._debug['size_of_optional_header']['start'] = self._io.pos() - self.size_of_optional_header = self._io.read_u2le() - self._debug['size_of_optional_header']['end'] = self._io.pos() - self._debug['characteristics']['start'] = self._io.pos() - self.characteristics = self._io.read_u2le() - self._debug['characteristics']['end'] = self._io.pos() - - @property - def symbol_table_size(self): - if hasattr(self, '_m_symbol_table_size'): - return self._m_symbol_table_size if hasattr(self, '_m_symbol_table_size') else None - - self._m_symbol_table_size = (self.number_of_symbols * 18) - return self._m_symbol_table_size if hasattr(self, '_m_symbol_table_size') else None - - @property - def symbol_name_table_offset(self): - if hasattr(self, '_m_symbol_name_table_offset'): - return self._m_symbol_name_table_offset if hasattr(self, '_m_symbol_name_table_offset') else None - - self._m_symbol_name_table_offset = (self.pointer_to_symbol_table + self.symbol_table_size) - return self._m_symbol_name_table_offset if hasattr(self, '_m_symbol_name_table_offset') else None - - @property - def symbol_name_table_size(self): - if hasattr(self, '_m_symbol_name_table_size'): - return self._m_symbol_name_table_size if hasattr(self, '_m_symbol_name_table_size') else None - - _pos = self._io.pos() - self._io.seek(self.symbol_name_table_offset) - self._debug['_m_symbol_name_table_size']['start'] = self._io.pos() - self._m_symbol_name_table_size = self._io.read_u4le() - self._debug['_m_symbol_name_table_size']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_symbol_name_table_size if hasattr(self, '_m_symbol_name_table_size') else None - - @property - def symbol_table(self): - if hasattr(self, '_m_symbol_table'): - return self._m_symbol_table if hasattr(self, '_m_symbol_table') else None - - _pos = self._io.pos() - self._io.seek(self.pointer_to_symbol_table) - self._debug['_m_symbol_table']['start'] = self._io.pos() - self._m_symbol_table = [None] * (self.number_of_symbols) - for i in range(self.number_of_symbols): - if not 'arr' in self._debug['_m_symbol_table']: - self._debug['_m_symbol_table']['arr'] = [] - self._debug['_m_symbol_table']['arr'].append({'start': self._io.pos()}) - _t__m_symbol_table = self._root.CoffSymbol(self._io, self, self._root) - _t__m_symbol_table._read() - self._m_symbol_table[i] = _t__m_symbol_table - self._debug['_m_symbol_table']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_symbol_table']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_symbol_table if hasattr(self, '_m_symbol_table') else None - - - class Annoyingstring(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def name_from_offset(self): - if hasattr(self, '_m_name_from_offset'): - return self._m_name_from_offset if hasattr(self, '_m_name_from_offset') else None - - if self.name_zeroes == 0: - io = self._root._io - _pos = io.pos() - io.seek(((self._parent._parent.symbol_name_table_offset + self.name_offset) if self.name_zeroes == 0 else 0)) - self._debug['_m_name_from_offset']['start'] = io.pos() - self._m_name_from_offset = (io.read_bytes_term(0, False, True, False)).decode(u"ascii") - self._debug['_m_name_from_offset']['end'] = io.pos() - io.seek(_pos) - - return self._m_name_from_offset if hasattr(self, '_m_name_from_offset') else None - - @property - def name_offset(self): - if hasattr(self, '_m_name_offset'): - return self._m_name_offset if hasattr(self, '_m_name_offset') else None - - _pos = self._io.pos() - self._io.seek(4) - self._debug['_m_name_offset']['start'] = self._io.pos() - self._m_name_offset = self._io.read_u4le() - self._debug['_m_name_offset']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_name_offset if hasattr(self, '_m_name_offset') else None - - @property - def name(self): - if hasattr(self, '_m_name'): - return self._m_name if hasattr(self, '_m_name') else None - - self._m_name = (self.name_from_offset if self.name_zeroes == 0 else self.name_from_short) - return self._m_name if hasattr(self, '_m_name') else None - - @property - def name_zeroes(self): - if hasattr(self, '_m_name_zeroes'): - return self._m_name_zeroes if hasattr(self, '_m_name_zeroes') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_name_zeroes']['start'] = self._io.pos() - self._m_name_zeroes = self._io.read_u4le() - self._debug['_m_name_zeroes']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_name_zeroes if hasattr(self, '_m_name_zeroes') else None - - @property - def name_from_short(self): - if hasattr(self, '_m_name_from_short'): - return self._m_name_from_short if hasattr(self, '_m_name_from_short') else None - - if self.name_zeroes != 0: - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_name_from_short']['start'] = self._io.pos() - self._m_name_from_short = (self._io.read_bytes_term(0, False, True, False)).decode(u"ascii") - self._debug['_m_name_from_short']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_name_from_short if hasattr(self, '_m_name_from_short') else None - - - @property - def pe(self): - if hasattr(self, '_m_pe'): - return self._m_pe if hasattr(self, '_m_pe') else None - - _pos = self._io.pos() - self._io.seek(self.mz.ofs_pe) - self._debug['_m_pe']['start'] = self._io.pos() - self._m_pe = self._root.PeHeader(self._io, self, self._root) - self._m_pe._read() - self._debug['_m_pe']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_pe if hasattr(self, '_m_pe') else None - - diff --git a/python/examples/kaitai/mifare_classic.py b/python/examples/kaitai/mifare_classic.py deleted file mode 100644 index 72414493..00000000 --- a/python/examples/kaitai/mifare_classic.py +++ /dev/null @@ -1,704 +0,0 @@ -# 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 -import collections - - -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 MifareClassic(KaitaiStruct): - """You can get a dump for testing by the link: https://github.com/zhovner/mfdread/raw/master/dump.mfd - - .. seealso:: - Source - https://github.com/nfc-tools/libnfc - https://www.nxp.com/docs/en/data-sheet/MF1S70YYX_V1.pdf - """ - SEQ_FIELDS = ["sectors"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sectors']['start'] = self._io.pos() - self._raw_sectors = [] - self.sectors = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['sectors']: - self._debug['sectors']['arr'] = [] - self._debug['sectors']['arr'].append({'start': self._io.pos()}) - self._raw_sectors.append(self._io.read_bytes((((4 if i >= 32 else 1) * 4) * 16))) - io = KaitaiStream(BytesIO(self._raw_sectors[-1])) - _t_sectors = self._root.Sector(i == 0, io, self, self._root) - _t_sectors._read() - self.sectors.append(_t_sectors) - self._debug['sectors']['arr'][len(self.sectors) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['sectors']['end'] = self._io.pos() - - class Key(KaitaiStruct): - SEQ_FIELDS = ["key"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key']['start'] = self._io.pos() - self.key = self._io.read_bytes(6) - self._debug['key']['end'] = self._io.pos() - - - class Sector(KaitaiStruct): - SEQ_FIELDS = ["manufacturer", "data_filler", "trailer"] - def __init__(self, has_manufacturer, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.has_manufacturer = has_manufacturer - self._debug = collections.defaultdict(dict) - - def _read(self): - if self.has_manufacturer: - self._debug['manufacturer']['start'] = self._io.pos() - self.manufacturer = self._root.Manufacturer(self._io, self, self._root) - self.manufacturer._read() - self._debug['manufacturer']['end'] = self._io.pos() - - self._debug['data_filler']['start'] = self._io.pos() - self._raw_data_filler = self._io.read_bytes(((self._io.size() - self._io.pos()) - 16)) - io = KaitaiStream(BytesIO(self._raw_data_filler)) - self.data_filler = self._root.Sector.Filler(io, self, self._root) - self.data_filler._read() - self._debug['data_filler']['end'] = self._io.pos() - self._debug['trailer']['start'] = self._io.pos() - self.trailer = self._root.Trailer(self._io, self, self._root) - self.trailer._read() - self._debug['trailer']['end'] = self._io.pos() - - class Values(KaitaiStruct): - SEQ_FIELDS = ["values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['values']['start'] = self._io.pos() - self.values = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - _t_values = self._root.Sector.Values.ValueBlock(self._io, self, self._root) - _t_values._read() - self.values.append(_t_values) - self._debug['values']['arr'][len(self.values) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['values']['end'] = self._io.pos() - - class ValueBlock(KaitaiStruct): - SEQ_FIELDS = ["valuez", "addrz"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['valuez']['start'] = self._io.pos() - self.valuez = [None] * (3) - for i in range(3): - if not 'arr' in self._debug['valuez']: - self._debug['valuez']['arr'] = [] - self._debug['valuez']['arr'].append({'start': self._io.pos()}) - self.valuez[i] = self._io.read_u4le() - self._debug['valuez']['arr'][i]['end'] = self._io.pos() - - self._debug['valuez']['end'] = self._io.pos() - self._debug['addrz']['start'] = self._io.pos() - self.addrz = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['addrz']: - self._debug['addrz']['arr'] = [] - self._debug['addrz']['arr'].append({'start': self._io.pos()}) - self.addrz[i] = self._io.read_u1() - self._debug['addrz']['arr'][i]['end'] = self._io.pos() - - self._debug['addrz']['end'] = self._io.pos() - - @property - def addr(self): - if hasattr(self, '_m_addr'): - return self._m_addr if hasattr(self, '_m_addr') else None - - if self.valid: - self._m_addr = self.addrz[0] - - return self._m_addr if hasattr(self, '_m_addr') else None - - @property - def addr_valid(self): - if hasattr(self, '_m_addr_valid'): - return self._m_addr_valid if hasattr(self, '_m_addr_valid') else None - - self._m_addr_valid = ((self.addrz[0] == ~(self.addrz[1])) and (self.addrz[0] == self.addrz[2]) and (self.addrz[1] == self.addrz[3])) - return self._m_addr_valid if hasattr(self, '_m_addr_valid') else None - - @property - def valid(self): - if hasattr(self, '_m_valid'): - return self._m_valid if hasattr(self, '_m_valid') else None - - self._m_valid = ((self.value_valid) and (self.addr_valid)) - return self._m_valid if hasattr(self, '_m_valid') else None - - @property - def value_valid(self): - if hasattr(self, '_m_value_valid'): - return self._m_value_valid if hasattr(self, '_m_value_valid') else None - - self._m_value_valid = ((self.valuez[0] == ~(self.valuez[1])) and (self.valuez[0] == self.valuez[2])) - return self._m_value_valid if hasattr(self, '_m_value_valid') else None - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - if self.valid: - self._m_value = self.valuez[0] - - return self._m_value if hasattr(self, '_m_value') else None - - - - class Filler(KaitaiStruct): - """only to create _io.""" - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self._io.size()) - self._debug['data']['end'] = self._io.pos() - - - @property - def block_size(self): - if hasattr(self, '_m_block_size'): - return self._m_block_size if hasattr(self, '_m_block_size') else None - - self._m_block_size = 16 - return self._m_block_size if hasattr(self, '_m_block_size') else None - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - self._m_data = self.data_filler.data - return self._m_data if hasattr(self, '_m_data') else None - - @property - def blocks(self): - if hasattr(self, '_m_blocks'): - return self._m_blocks if hasattr(self, '_m_blocks') else None - - io = self.data_filler._io - _pos = io.pos() - io.seek(0) - self._debug['_m_blocks']['start'] = io.pos() - self._m_blocks = [] - i = 0 - while not io.is_eof(): - if not 'arr' in self._debug['_m_blocks']: - self._debug['_m_blocks']['arr'] = [] - self._debug['_m_blocks']['arr'].append({'start': io.pos()}) - self._m_blocks.append(io.read_bytes(self.block_size)) - self._debug['_m_blocks']['arr'][len(self._m_blocks) - 1]['end'] = io.pos() - i += 1 - - self._debug['_m_blocks']['end'] = io.pos() - io.seek(_pos) - return self._m_blocks if hasattr(self, '_m_blocks') else None - - @property - def values(self): - if hasattr(self, '_m_values'): - return self._m_values if hasattr(self, '_m_values') else None - - io = self.data_filler._io - _pos = io.pos() - io.seek(0) - self._debug['_m_values']['start'] = io.pos() - self._m_values = self._root.Sector.Values(io, self, self._root) - self._m_values._read() - self._debug['_m_values']['end'] = io.pos() - io.seek(_pos) - return self._m_values if hasattr(self, '_m_values') else None - - - class Manufacturer(KaitaiStruct): - SEQ_FIELDS = ["nuid", "bcc", "sak", "atqa", "manufacturer"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['nuid']['start'] = self._io.pos() - self.nuid = self._io.read_u4le() - self._debug['nuid']['end'] = self._io.pos() - self._debug['bcc']['start'] = self._io.pos() - self.bcc = self._io.read_u1() - self._debug['bcc']['end'] = self._io.pos() - self._debug['sak']['start'] = self._io.pos() - self.sak = self._io.read_u1() - self._debug['sak']['end'] = self._io.pos() - self._debug['atqa']['start'] = self._io.pos() - self.atqa = self._io.read_u2le() - self._debug['atqa']['end'] = self._io.pos() - self._debug['manufacturer']['start'] = self._io.pos() - self.manufacturer = self._io.read_bytes(8) - self._debug['manufacturer']['end'] = self._io.pos() - - - class Trailer(KaitaiStruct): - SEQ_FIELDS = ["key_a", "access_bits", "user_byte", "key_b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key_a']['start'] = self._io.pos() - self.key_a = self._root.Key(self._io, self, self._root) - self.key_a._read() - self._debug['key_a']['end'] = self._io.pos() - self._debug['access_bits']['start'] = self._io.pos() - self._raw_access_bits = self._io.read_bytes(3) - io = KaitaiStream(BytesIO(self._raw_access_bits)) - self.access_bits = self._root.Trailer.AccessConditions(io, self, self._root) - self.access_bits._read() - self._debug['access_bits']['end'] = self._io.pos() - self._debug['user_byte']['start'] = self._io.pos() - self.user_byte = self._io.read_u1() - self._debug['user_byte']['end'] = self._io.pos() - self._debug['key_b']['start'] = self._io.pos() - self.key_b = self._root.Key(self._io, self, self._root) - self.key_b._read() - self._debug['key_b']['end'] = self._io.pos() - - class AccessConditions(KaitaiStruct): - SEQ_FIELDS = ["raw_chunks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['raw_chunks']['start'] = self._io.pos() - self.raw_chunks = [None] * (self._parent.ac_count_of_chunks) - for i in range(self._parent.ac_count_of_chunks): - if not 'arr' in self._debug['raw_chunks']: - self._debug['raw_chunks']['arr'] = [] - self._debug['raw_chunks']['arr'].append({'start': self._io.pos()}) - self.raw_chunks[i] = self._io.read_bits_int(4) - self._debug['raw_chunks']['arr'][i]['end'] = self._io.pos() - - self._debug['raw_chunks']['end'] = self._io.pos() - - class TrailerAc(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, ac, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.ac = ac - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def can_read_key_b(self): - """key A is required.""" - if hasattr(self, '_m_can_read_key_b'): - return self._m_can_read_key_b if hasattr(self, '_m_can_read_key_b') else None - - self._m_can_read_key_b = self.ac.inv_shift_val <= 2 - return self._m_can_read_key_b if hasattr(self, '_m_can_read_key_b') else None - - @property - def can_write_keys(self): - if hasattr(self, '_m_can_write_keys'): - return self._m_can_write_keys if hasattr(self, '_m_can_write_keys') else None - - self._m_can_write_keys = ((((self.ac.inv_shift_val + 1) % 3) != 0) and (self.ac.inv_shift_val < 6)) - return self._m_can_write_keys if hasattr(self, '_m_can_write_keys') else None - - @property - def can_write_access_bits(self): - if hasattr(self, '_m_can_write_access_bits'): - return self._m_can_write_access_bits if hasattr(self, '_m_can_write_access_bits') else None - - self._m_can_write_access_bits = self.ac.bits[2].b - return self._m_can_write_access_bits if hasattr(self, '_m_can_write_access_bits') else None - - @property - def key_b_controls_write(self): - if hasattr(self, '_m_key_b_controls_write'): - return self._m_key_b_controls_write if hasattr(self, '_m_key_b_controls_write') else None - - self._m_key_b_controls_write = not (self.can_read_key_b) - return self._m_key_b_controls_write if hasattr(self, '_m_key_b_controls_write') else None - - - class ChunkBitRemap(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, bit_no, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.bit_no = bit_no - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def shift_value(self): - if hasattr(self, '_m_shift_value'): - return self._m_shift_value if hasattr(self, '_m_shift_value') else None - - self._m_shift_value = (-1 if self.bit_no == 1 else 1) - return self._m_shift_value if hasattr(self, '_m_shift_value') else None - - @property - def chunk_no(self): - if hasattr(self, '_m_chunk_no'): - return self._m_chunk_no if hasattr(self, '_m_chunk_no') else None - - self._m_chunk_no = (((self.inv_chunk_no + self.shift_value) + self._parent._parent.ac_count_of_chunks) % self._parent._parent.ac_count_of_chunks) - return self._m_chunk_no if hasattr(self, '_m_chunk_no') else None - - @property - def inv_chunk_no(self): - if hasattr(self, '_m_inv_chunk_no'): - return self._m_inv_chunk_no if hasattr(self, '_m_inv_chunk_no') else None - - self._m_inv_chunk_no = (self.bit_no + self.shift_value) - return self._m_inv_chunk_no if hasattr(self, '_m_inv_chunk_no') else None - - - class DataAc(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, ac, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.ac = ac - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def read_key_a_required(self): - if hasattr(self, '_m_read_key_a_required'): - return self._m_read_key_a_required if hasattr(self, '_m_read_key_a_required') else None - - self._m_read_key_a_required = self.ac.val <= 4 - return self._m_read_key_a_required if hasattr(self, '_m_read_key_a_required') else None - - @property - def write_key_b_required(self): - if hasattr(self, '_m_write_key_b_required'): - return self._m_write_key_b_required if hasattr(self, '_m_write_key_b_required') else None - - self._m_write_key_b_required = (( ((not (self.read_key_a_required)) or (self.read_key_b_required)) ) and (not (self.ac.bits[0].b))) - return self._m_write_key_b_required if hasattr(self, '_m_write_key_b_required') else None - - @property - def write_key_a_required(self): - if hasattr(self, '_m_write_key_a_required'): - return self._m_write_key_a_required if hasattr(self, '_m_write_key_a_required') else None - - self._m_write_key_a_required = self.ac.val == 0 - return self._m_write_key_a_required if hasattr(self, '_m_write_key_a_required') else None - - @property - def read_key_b_required(self): - if hasattr(self, '_m_read_key_b_required'): - return self._m_read_key_b_required if hasattr(self, '_m_read_key_b_required') else None - - self._m_read_key_b_required = self.ac.val <= 6 - return self._m_read_key_b_required if hasattr(self, '_m_read_key_b_required') else None - - @property - def decrement_available(self): - if hasattr(self, '_m_decrement_available'): - return self._m_decrement_available if hasattr(self, '_m_decrement_available') else None - - self._m_decrement_available = (( ((self.ac.bits[1].b) or (not (self.ac.bits[0].b))) ) and (not (self.ac.bits[2].b))) - return self._m_decrement_available if hasattr(self, '_m_decrement_available') else None - - @property - def increment_available(self): - if hasattr(self, '_m_increment_available'): - return self._m_increment_available if hasattr(self, '_m_increment_available') else None - - self._m_increment_available = (( ((not (self.ac.bits[0].b)) and (not (self.read_key_a_required)) and (not (self.read_key_b_required))) ) or ( ((not (self.ac.bits[0].b)) and (self.read_key_a_required) and (self.read_key_b_required)) )) - return self._m_increment_available if hasattr(self, '_m_increment_available') else None - - - class Ac(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, index, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.index = index - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - class AcBit(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, i, chunk, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.i = i - self.chunk = chunk - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def n(self): - if hasattr(self, '_m_n'): - return self._m_n if hasattr(self, '_m_n') else None - - self._m_n = ((self.chunk >> self.i) & 1) - return self._m_n if hasattr(self, '_m_n') else None - - @property - def b(self): - if hasattr(self, '_m_b'): - return self._m_b if hasattr(self, '_m_b') else None - - self._m_b = self.n == 1 - return self._m_b if hasattr(self, '_m_b') else None - - - @property - def bits(self): - if hasattr(self, '_m_bits'): - return self._m_bits if hasattr(self, '_m_bits') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_bits']['start'] = self._io.pos() - self._m_bits = [None] * (self._parent._parent.ac_bits) - for i in range(self._parent._parent.ac_bits): - if not 'arr' in self._debug['_m_bits']: - self._debug['_m_bits']['arr'] = [] - self._debug['_m_bits']['arr'].append({'start': self._io.pos()}) - _t__m_bits = self._root.Trailer.AccessConditions.Ac.AcBit(self.index, self._parent.chunks[i].chunk, self._io, self, self._root) - _t__m_bits._read() - self._m_bits[i] = _t__m_bits - self._debug['_m_bits']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_bits']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_bits if hasattr(self, '_m_bits') else None - - @property - def val(self): - """c3 c2 c1.""" - if hasattr(self, '_m_val'): - return self._m_val if hasattr(self, '_m_val') else None - - self._m_val = (((self.bits[2].n << 2) | (self.bits[1].n << 1)) | self.bits[0].n) - return self._m_val if hasattr(self, '_m_val') else None - - @property - def inv_shift_val(self): - if hasattr(self, '_m_inv_shift_val'): - return self._m_inv_shift_val if hasattr(self, '_m_inv_shift_val') else None - - self._m_inv_shift_val = (((self.bits[0].n << 2) | (self.bits[1].n << 1)) | self.bits[2].n) - return self._m_inv_shift_val if hasattr(self, '_m_inv_shift_val') else None - - - class ValidChunk(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, inv_chunk, chunk, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.inv_chunk = inv_chunk - self.chunk = chunk - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - @property - def valid(self): - if hasattr(self, '_m_valid'): - return self._m_valid if hasattr(self, '_m_valid') else None - - self._m_valid = (self.inv_chunk ^ self.chunk) == 15 - return self._m_valid if hasattr(self, '_m_valid') else None - - - @property - def data_acs(self): - if hasattr(self, '_m_data_acs'): - return self._m_data_acs if hasattr(self, '_m_data_acs') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_data_acs']['start'] = self._io.pos() - self._m_data_acs = [None] * ((self._parent.acs_in_sector - 1)) - for i in range((self._parent.acs_in_sector - 1)): - if not 'arr' in self._debug['_m_data_acs']: - self._debug['_m_data_acs']['arr'] = [] - self._debug['_m_data_acs']['arr'].append({'start': self._io.pos()}) - _t__m_data_acs = self._root.Trailer.AccessConditions.DataAc(self.acs_raw[i], self._io, self, self._root) - _t__m_data_acs._read() - self._m_data_acs[i] = _t__m_data_acs - self._debug['_m_data_acs']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_data_acs']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data_acs if hasattr(self, '_m_data_acs') else None - - @property - def remaps(self): - if hasattr(self, '_m_remaps'): - return self._m_remaps if hasattr(self, '_m_remaps') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_remaps']['start'] = self._io.pos() - self._m_remaps = [None] * (self._parent.ac_bits) - for i in range(self._parent.ac_bits): - if not 'arr' in self._debug['_m_remaps']: - self._debug['_m_remaps']['arr'] = [] - self._debug['_m_remaps']['arr'].append({'start': self._io.pos()}) - _t__m_remaps = self._root.Trailer.AccessConditions.ChunkBitRemap(i, self._io, self, self._root) - _t__m_remaps._read() - self._m_remaps[i] = _t__m_remaps - self._debug['_m_remaps']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_remaps']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_remaps if hasattr(self, '_m_remaps') else None - - @property - def acs_raw(self): - if hasattr(self, '_m_acs_raw'): - return self._m_acs_raw if hasattr(self, '_m_acs_raw') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_acs_raw']['start'] = self._io.pos() - self._m_acs_raw = [None] * (self._parent.acs_in_sector) - for i in range(self._parent.acs_in_sector): - if not 'arr' in self._debug['_m_acs_raw']: - self._debug['_m_acs_raw']['arr'] = [] - self._debug['_m_acs_raw']['arr'].append({'start': self._io.pos()}) - _t__m_acs_raw = self._root.Trailer.AccessConditions.Ac(i, self._io, self, self._root) - _t__m_acs_raw._read() - self._m_acs_raw[i] = _t__m_acs_raw - self._debug['_m_acs_raw']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_acs_raw']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_acs_raw if hasattr(self, '_m_acs_raw') else None - - @property - def trailer_ac(self): - if hasattr(self, '_m_trailer_ac'): - return self._m_trailer_ac if hasattr(self, '_m_trailer_ac') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_trailer_ac']['start'] = self._io.pos() - self._m_trailer_ac = self._root.Trailer.AccessConditions.TrailerAc(self.acs_raw[(self._parent.acs_in_sector - 1)], self._io, self, self._root) - self._m_trailer_ac._read() - self._debug['_m_trailer_ac']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_trailer_ac if hasattr(self, '_m_trailer_ac') else None - - @property - def chunks(self): - if hasattr(self, '_m_chunks'): - return self._m_chunks if hasattr(self, '_m_chunks') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_chunks']['start'] = self._io.pos() - self._m_chunks = [None] * (self._parent.ac_bits) - for i in range(self._parent.ac_bits): - if not 'arr' in self._debug['_m_chunks']: - self._debug['_m_chunks']['arr'] = [] - self._debug['_m_chunks']['arr'].append({'start': self._io.pos()}) - _t__m_chunks = self._root.Trailer.AccessConditions.ValidChunk(self.raw_chunks[self.remaps[i].inv_chunk_no], self.raw_chunks[self.remaps[i].chunk_no], self._io, self, self._root) - _t__m_chunks._read() - self._m_chunks[i] = _t__m_chunks - self._debug['_m_chunks']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_chunks']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_chunks if hasattr(self, '_m_chunks') else None - - - @property - def ac_bits(self): - if hasattr(self, '_m_ac_bits'): - return self._m_ac_bits if hasattr(self, '_m_ac_bits') else None - - self._m_ac_bits = 3 - return self._m_ac_bits if hasattr(self, '_m_ac_bits') else None - - @property - def acs_in_sector(self): - if hasattr(self, '_m_acs_in_sector'): - return self._m_acs_in_sector if hasattr(self, '_m_acs_in_sector') else None - - self._m_acs_in_sector = 4 - return self._m_acs_in_sector if hasattr(self, '_m_acs_in_sector') else None - - @property - def ac_count_of_chunks(self): - if hasattr(self, '_m_ac_count_of_chunks'): - return self._m_ac_count_of_chunks if hasattr(self, '_m_ac_count_of_chunks') else None - - self._m_ac_count_of_chunks = (self.ac_bits * 2) - return self._m_ac_count_of_chunks if hasattr(self, '_m_ac_count_of_chunks') else None - - - diff --git a/python/examples/kaitai/monomakh_sapr_chg.py b/python/examples/kaitai/monomakh_sapr_chg.py deleted file mode 100644 index 0e7e6400..00000000 --- a/python/examples/kaitai/monomakh_sapr_chg.py +++ /dev/null @@ -1,68 +0,0 @@ -# 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 -import collections - - -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 MonomakhSaprChg(KaitaiStruct): - """CHG is a container format file used by - [MONOMAKH-SAPR](https://www.liraland.com/mono/index.php), a software - package for analysis & design of reinforced concrete multi-storey - buildings with arbitrary configuration in plan. - - CHG is a simple container, which bundles several project files - together. - - Written and tested by Vladimir Shulzhitskiy, 2017 - """ - SEQ_FIELDS = ["title", "ent"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['title']['start'] = self._io.pos() - self.title = (self._io.read_bytes(10)).decode(u"ascii") - self._debug['title']['end'] = self._io.pos() - self._debug['ent']['start'] = self._io.pos() - self.ent = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['ent']: - self._debug['ent']['arr'] = [] - self._debug['ent']['arr'].append({'start': self._io.pos()}) - _t_ent = self._root.Block(self._io, self, self._root) - _t_ent._read() - self.ent.append(_t_ent) - self._debug['ent']['arr'][len(self.ent) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['ent']['end'] = self._io.pos() - - class Block(KaitaiStruct): - SEQ_FIELDS = ["header", "file_size", "file"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = (self._io.read_bytes(13)).decode(u"ascii") - self._debug['header']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u8le() - self._debug['file_size']['end'] = self._io.pos() - self._debug['file']['start'] = self._io.pos() - self.file = self._io.read_bytes(self.file_size) - self._debug['file']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/msgpack.py b/python/examples/kaitai/msgpack.py deleted file mode 100644 index cc14238d..00000000 --- a/python/examples/kaitai/msgpack.py +++ /dev/null @@ -1,466 +0,0 @@ -# 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 -import collections - - -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 Msgpack(KaitaiStruct): - """MessagePack (msgpack) is a system to serialize arbitrary structured - data into a compact binary stream. - - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md - """ - SEQ_FIELDS = ["b1", "int_extra", "float_32_value", "float_64_value", "str_len_8", "str_len_16", "str_len_32", "str_value", "num_array_elements_16", "num_array_elements_32", "array_elements", "num_map_elements_16", "num_map_elements_32", "map_elements"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - self._debug['int_extra']['start'] = self._io.pos() - _on = self.b1 - if _on == 211: - self.int_extra = self._io.read_s8be() - elif _on == 209: - self.int_extra = self._io.read_s2be() - elif _on == 210: - self.int_extra = self._io.read_s4be() - elif _on == 208: - self.int_extra = self._io.read_s1() - elif _on == 205: - self.int_extra = self._io.read_u2be() - elif _on == 207: - self.int_extra = self._io.read_u8be() - elif _on == 204: - self.int_extra = self._io.read_u1() - elif _on == 206: - self.int_extra = self._io.read_u4be() - self._debug['int_extra']['end'] = self._io.pos() - if self.is_float_32: - self._debug['float_32_value']['start'] = self._io.pos() - self.float_32_value = self._io.read_f4be() - self._debug['float_32_value']['end'] = self._io.pos() - - if self.is_float_64: - self._debug['float_64_value']['start'] = self._io.pos() - self.float_64_value = self._io.read_f8be() - self._debug['float_64_value']['end'] = self._io.pos() - - if self.is_str_8: - self._debug['str_len_8']['start'] = self._io.pos() - self.str_len_8 = self._io.read_u1() - self._debug['str_len_8']['end'] = self._io.pos() - - if self.is_str_16: - self._debug['str_len_16']['start'] = self._io.pos() - self.str_len_16 = self._io.read_u2be() - self._debug['str_len_16']['end'] = self._io.pos() - - if self.is_str_32: - self._debug['str_len_32']['start'] = self._io.pos() - self.str_len_32 = self._io.read_u4be() - self._debug['str_len_32']['end'] = self._io.pos() - - if self.is_str: - self._debug['str_value']['start'] = self._io.pos() - self.str_value = (self._io.read_bytes(self.str_len)).decode(u"UTF-8") - self._debug['str_value']['end'] = self._io.pos() - - if self.is_array_16: - self._debug['num_array_elements_16']['start'] = self._io.pos() - self.num_array_elements_16 = self._io.read_u2be() - self._debug['num_array_elements_16']['end'] = self._io.pos() - - if self.is_array_32: - self._debug['num_array_elements_32']['start'] = self._io.pos() - self.num_array_elements_32 = self._io.read_u4be() - self._debug['num_array_elements_32']['end'] = self._io.pos() - - if self.is_array: - self._debug['array_elements']['start'] = self._io.pos() - self.array_elements = [None] * (self.num_array_elements) - for i in range(self.num_array_elements): - if not 'arr' in self._debug['array_elements']: - self._debug['array_elements']['arr'] = [] - self._debug['array_elements']['arr'].append({'start': self._io.pos()}) - _t_array_elements = Msgpack(self._io) - _t_array_elements._read() - self.array_elements[i] = _t_array_elements - self._debug['array_elements']['arr'][i]['end'] = self._io.pos() - - self._debug['array_elements']['end'] = self._io.pos() - - if self.is_map_16: - self._debug['num_map_elements_16']['start'] = self._io.pos() - self.num_map_elements_16 = self._io.read_u2be() - self._debug['num_map_elements_16']['end'] = self._io.pos() - - if self.is_map_32: - self._debug['num_map_elements_32']['start'] = self._io.pos() - self.num_map_elements_32 = self._io.read_u4be() - self._debug['num_map_elements_32']['end'] = self._io.pos() - - if self.is_map: - self._debug['map_elements']['start'] = self._io.pos() - self.map_elements = [None] * (self.num_map_elements) - for i in range(self.num_map_elements): - if not 'arr' in self._debug['map_elements']: - self._debug['map_elements']['arr'] = [] - self._debug['map_elements']['arr'].append({'start': self._io.pos()}) - _t_map_elements = self._root.MapTuple(self._io, self, self._root) - _t_map_elements._read() - self.map_elements[i] = _t_map_elements - self._debug['map_elements']['arr'][i]['end'] = self._io.pos() - - self._debug['map_elements']['end'] = self._io.pos() - - - class MapTuple(KaitaiStruct): - SEQ_FIELDS = ["key", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key']['start'] = self._io.pos() - self.key = Msgpack(self._io) - self.key._read() - self._debug['key']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = Msgpack(self._io) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - - @property - def is_array_32(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-array - """ - if hasattr(self, '_m_is_array_32'): - return self._m_is_array_32 if hasattr(self, '_m_is_array_32') else None - - self._m_is_array_32 = self.b1 == 221 - return self._m_is_array_32 if hasattr(self, '_m_is_array_32') else None - - @property - def int_value(self): - if hasattr(self, '_m_int_value'): - return self._m_int_value if hasattr(self, '_m_int_value') else None - - if self.is_int: - self._m_int_value = (self.pos_int7_value if self.is_pos_int7 else (self.neg_int5_value if self.is_neg_int5 else 4919)) - - return self._m_int_value if hasattr(self, '_m_int_value') else None - - @property - def str_len(self): - if hasattr(self, '_m_str_len'): - return self._m_str_len if hasattr(self, '_m_str_len') else None - - if self.is_str: - self._m_str_len = ((self.b1 & 31) if self.is_fix_str else (self.str_len_8 if self.is_str_8 else (self.str_len_16 if self.is_str_16 else self.str_len_32))) - - return self._m_str_len if hasattr(self, '_m_str_len') else None - - @property - def is_fix_array(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-array - """ - if hasattr(self, '_m_is_fix_array'): - return self._m_is_fix_array if hasattr(self, '_m_is_fix_array') else None - - self._m_is_fix_array = (self.b1 & 240) == 144 - return self._m_is_fix_array if hasattr(self, '_m_is_fix_array') else None - - @property - def is_map(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map - """ - if hasattr(self, '_m_is_map'): - return self._m_is_map if hasattr(self, '_m_is_map') else None - - self._m_is_map = ((self.is_fix_map) or (self.is_map_16) or (self.is_map_32)) - return self._m_is_map if hasattr(self, '_m_is_map') else None - - @property - def is_array(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-array - """ - if hasattr(self, '_m_is_array'): - return self._m_is_array if hasattr(self, '_m_is_array') else None - - self._m_is_array = ((self.is_fix_array) or (self.is_array_16) or (self.is_array_32)) - return self._m_is_array if hasattr(self, '_m_is_array') else None - - @property - def is_float(self): - if hasattr(self, '_m_is_float'): - return self._m_is_float if hasattr(self, '_m_is_float') else None - - self._m_is_float = ((self.is_float_32) or (self.is_float_64)) - return self._m_is_float if hasattr(self, '_m_is_float') else None - - @property - def is_str_8(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-str - """ - if hasattr(self, '_m_is_str_8'): - return self._m_is_str_8 if hasattr(self, '_m_is_str_8') else None - - self._m_is_str_8 = self.b1 == 217 - return self._m_is_str_8 if hasattr(self, '_m_is_str_8') else None - - @property - def is_fix_map(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map - """ - if hasattr(self, '_m_is_fix_map'): - return self._m_is_fix_map if hasattr(self, '_m_is_fix_map') else None - - self._m_is_fix_map = (self.b1 & 240) == 128 - return self._m_is_fix_map if hasattr(self, '_m_is_fix_map') else None - - @property - def is_int(self): - if hasattr(self, '_m_is_int'): - return self._m_is_int if hasattr(self, '_m_is_int') else None - - self._m_is_int = ((self.is_pos_int7) or (self.is_neg_int5)) - return self._m_is_int if hasattr(self, '_m_is_int') else None - - @property - def is_bool(self): - if hasattr(self, '_m_is_bool'): - return self._m_is_bool if hasattr(self, '_m_is_bool') else None - - self._m_is_bool = ((self.b1 == 194) or (self.b1 == 195)) - return self._m_is_bool if hasattr(self, '_m_is_bool') else None - - @property - def is_str_16(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-str - """ - if hasattr(self, '_m_is_str_16'): - return self._m_is_str_16 if hasattr(self, '_m_is_str_16') else None - - self._m_is_str_16 = self.b1 == 218 - return self._m_is_str_16 if hasattr(self, '_m_is_str_16') else None - - @property - def is_float_64(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-float - """ - if hasattr(self, '_m_is_float_64'): - return self._m_is_float_64 if hasattr(self, '_m_is_float_64') else None - - self._m_is_float_64 = self.b1 == 203 - return self._m_is_float_64 if hasattr(self, '_m_is_float_64') else None - - @property - def is_map_16(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map - """ - if hasattr(self, '_m_is_map_16'): - return self._m_is_map_16 if hasattr(self, '_m_is_map_16') else None - - self._m_is_map_16 = self.b1 == 222 - return self._m_is_map_16 if hasattr(self, '_m_is_map_16') else None - - @property - def is_neg_int5(self): - if hasattr(self, '_m_is_neg_int5'): - return self._m_is_neg_int5 if hasattr(self, '_m_is_neg_int5') else None - - self._m_is_neg_int5 = (self.b1 & 224) == 224 - return self._m_is_neg_int5 if hasattr(self, '_m_is_neg_int5') else None - - @property - def pos_int7_value(self): - if hasattr(self, '_m_pos_int7_value'): - return self._m_pos_int7_value if hasattr(self, '_m_pos_int7_value') else None - - if self.is_pos_int7: - self._m_pos_int7_value = self.b1 - - return self._m_pos_int7_value if hasattr(self, '_m_pos_int7_value') else None - - @property - def is_nil(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-nil - """ - if hasattr(self, '_m_is_nil'): - return self._m_is_nil if hasattr(self, '_m_is_nil') else None - - self._m_is_nil = self.b1 == 192 - return self._m_is_nil if hasattr(self, '_m_is_nil') else None - - @property - def float_value(self): - if hasattr(self, '_m_float_value'): - return self._m_float_value if hasattr(self, '_m_float_value') else None - - if self.is_float: - self._m_float_value = (self.float_32_value if self.is_float_32 else self.float_64_value) - - return self._m_float_value if hasattr(self, '_m_float_value') else None - - @property - def num_array_elements(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-array - """ - if hasattr(self, '_m_num_array_elements'): - return self._m_num_array_elements if hasattr(self, '_m_num_array_elements') else None - - if self.is_array: - self._m_num_array_elements = ((self.b1 & 15) if self.is_fix_array else (self.num_array_elements_16 if self.is_array_16 else self.num_array_elements_32)) - - return self._m_num_array_elements if hasattr(self, '_m_num_array_elements') else None - - @property - def neg_int5_value(self): - if hasattr(self, '_m_neg_int5_value'): - return self._m_neg_int5_value if hasattr(self, '_m_neg_int5_value') else None - - if self.is_neg_int5: - self._m_neg_int5_value = -((self.b1 & 31)) - - return self._m_neg_int5_value if hasattr(self, '_m_neg_int5_value') else None - - @property - def bool_value(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-bool - """ - if hasattr(self, '_m_bool_value'): - return self._m_bool_value if hasattr(self, '_m_bool_value') else None - - if self.is_bool: - self._m_bool_value = self.b1 == 195 - - return self._m_bool_value if hasattr(self, '_m_bool_value') else None - - @property - def is_pos_int7(self): - if hasattr(self, '_m_is_pos_int7'): - return self._m_is_pos_int7 if hasattr(self, '_m_is_pos_int7') else None - - self._m_is_pos_int7 = (self.b1 & 128) == 0 - return self._m_is_pos_int7 if hasattr(self, '_m_is_pos_int7') else None - - @property - def is_array_16(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-array - """ - if hasattr(self, '_m_is_array_16'): - return self._m_is_array_16 if hasattr(self, '_m_is_array_16') else None - - self._m_is_array_16 = self.b1 == 220 - return self._m_is_array_16 if hasattr(self, '_m_is_array_16') else None - - @property - def is_str(self): - if hasattr(self, '_m_is_str'): - return self._m_is_str if hasattr(self, '_m_is_str') else None - - self._m_is_str = ((self.is_fix_str) or (self.is_str_8) or (self.is_str_16) or (self.is_str_32)) - return self._m_is_str if hasattr(self, '_m_is_str') else None - - @property - def is_fix_str(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-str - """ - if hasattr(self, '_m_is_fix_str'): - return self._m_is_fix_str if hasattr(self, '_m_is_fix_str') else None - - self._m_is_fix_str = (self.b1 & 224) == 160 - return self._m_is_fix_str if hasattr(self, '_m_is_fix_str') else None - - @property - def is_str_32(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-str - """ - if hasattr(self, '_m_is_str_32'): - return self._m_is_str_32 if hasattr(self, '_m_is_str_32') else None - - self._m_is_str_32 = self.b1 == 219 - return self._m_is_str_32 if hasattr(self, '_m_is_str_32') else None - - @property - def num_map_elements(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map - """ - if hasattr(self, '_m_num_map_elements'): - return self._m_num_map_elements if hasattr(self, '_m_num_map_elements') else None - - if self.is_map: - self._m_num_map_elements = ((self.b1 & 15) if self.is_fix_map else (self.num_map_elements_16 if self.is_map_16 else self.num_map_elements_32)) - - return self._m_num_map_elements if hasattr(self, '_m_num_map_elements') else None - - @property - def is_float_32(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-float - """ - if hasattr(self, '_m_is_float_32'): - return self._m_is_float_32 if hasattr(self, '_m_is_float_32') else None - - self._m_is_float_32 = self.b1 == 202 - return self._m_is_float_32 if hasattr(self, '_m_is_float_32') else None - - @property - def is_map_32(self): - """ - .. seealso:: - Source - https://github.com/msgpack/msgpack/blob/master/spec.md#formats-map - """ - if hasattr(self, '_m_is_map_32'): - return self._m_is_map_32 if hasattr(self, '_m_is_map_32') else None - - self._m_is_map_32 = self.b1 == 223 - return self._m_is_map_32 if hasattr(self, '_m_is_map_32') else None - - diff --git a/python/examples/kaitai/nt_mdt.py b/python/examples/kaitai/nt_mdt.py deleted file mode 100644 index 8a0a1184..00000000 --- a/python/examples/kaitai/nt_mdt.py +++ /dev/null @@ -1,1308 +0,0 @@ -# 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 -import collections - - -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 NtMdt(KaitaiStruct): - """A native file format of NT-MDT scientific software. Usually contains - any of: - - * [Scanning probe](https://en.wikipedia.org/wiki/Scanning_probe_microscopy) microscopy scans and spectra - * [Raman spectra](https://en.wikipedia.org/wiki/Raman_spectroscopy) - * results of their analysis - - Some examples of mdt files can be downloaded at: - - * http://www.ntmdt-si.ru/scan-gallery - * http://callistosoft.narod.ru/Resources/Mdt.zip - - .. seealso:: - Source - https://svn.code.sf.net/p/gwyddion/code/trunk/gwyddion/modules/file/nt-mdt.c - """ - - class AdcMode(Enum): - height = 0 - dfl = 1 - lateral_f = 2 - bias_v = 3 - current = 4 - fb_out = 5 - mag = 6 - mag_sin = 7 - mag_cos = 8 - rms = 9 - calc_mag = 10 - phase1 = 11 - phase2 = 12 - calc_phase = 13 - ex1 = 14 - ex2 = 15 - hv_x = 16 - hv_y = 17 - snap_back = 18 - false = 255 - - class XmlScanLocation(Enum): - hlt = 0 - hlb = 1 - hrt = 2 - hrb = 3 - vlt = 4 - vlb = 5 - vrt = 6 - vrb = 7 - - class DataType(Enum): - floatfix = -65544 - float80 = -16138 - float64 = -13320 - float48 = -9990 - float32 = -5892 - int64 = -8 - int32 = -4 - int16 = -2 - int8 = -1 - unknown0 = 0 - uint8 = 1 - uint16 = 2 - uint32 = 4 - uint64 = 8 - - class XmlParamType(Enum): - none = 0 - laser_wavelength = 1 - units = 2 - data_array = 255 - - class SpmMode(Enum): - constant_force = 0 - contact_constant_height = 1 - contact_error = 2 - lateral_force = 3 - force_modulation = 4 - spreading_resistance_imaging = 5 - semicontact_topography = 6 - semicontact_error = 7 - phase_contrast = 8 - ac_magnetic_force = 9 - dc_magnetic_force = 10 - electrostatic_force = 11 - capacitance_contrast = 12 - kelvin_probe = 13 - constant_current = 14 - barrier_height = 15 - constant_height = 16 - afam = 17 - contact_efm = 18 - shear_force_topography = 19 - sfom = 20 - contact_capacitance = 21 - snom_transmission = 22 - snom_reflection = 23 - snom_all = 24 - snom = 25 - - class Unit(Enum): - raman_shift = -10 - reserved0 = -9 - reserved1 = -8 - reserved2 = -7 - reserved3 = -6 - meter = -5 - centi_meter = -4 - milli_meter = -3 - micro_meter = -2 - nano_meter = -1 - angstrom = 0 - nano_ampere = 1 - volt = 2 - none = 3 - kilo_hertz = 4 - degrees = 5 - percent = 6 - celsius_degree = 7 - volt_high = 8 - second = 9 - milli_second = 10 - micro_second = 11 - nano_second = 12 - counts = 13 - pixels = 14 - reserved_sfom0 = 15 - reserved_sfom1 = 16 - reserved_sfom2 = 17 - reserved_sfom3 = 18 - reserved_sfom4 = 19 - ampere2 = 20 - milli_ampere = 21 - micro_ampere = 22 - nano_ampere2 = 23 - pico_ampere = 24 - volt2 = 25 - milli_volt = 26 - micro_volt = 27 - nano_volt = 28 - pico_volt = 29 - newton = 30 - milli_newton = 31 - micro_newton = 32 - nano_newton = 33 - pico_newton = 34 - reserved_dos0 = 35 - reserved_dos1 = 36 - reserved_dos2 = 37 - reserved_dos3 = 38 - reserved_dos4 = 39 - - class SpmTechnique(Enum): - contact_mode = 0 - semicontact_mode = 1 - tunnel_current = 2 - snom = 3 - - class Consts(Enum): - frame_mode_size = 8 - frame_header_size = 22 - axis_scales_size = 30 - file_header_size = 32 - spectro_vars_min_size = 38 - scan_vars_min_size = 77 - SEQ_FIELDS = ["signature", "size", "reserved0", "last_frame", "reserved1", "wrond_doc", "frames"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x01\xB0\x93\xFF") - self._debug['signature']['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['reserved0']['start'] = self._io.pos() - self.reserved0 = self._io.read_bytes(4) - self._debug['reserved0']['end'] = self._io.pos() - self._debug['last_frame']['start'] = self._io.pos() - self.last_frame = self._io.read_u2le() - self._debug['last_frame']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(18) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['wrond_doc']['start'] = self._io.pos() - self.wrond_doc = self._io.read_bytes(1) - self._debug['wrond_doc']['end'] = self._io.pos() - self._debug['frames']['start'] = self._io.pos() - self._raw_frames = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_frames)) - self.frames = self._root.Framez(io, self, self._root) - self.frames._read() - self._debug['frames']['end'] = self._io.pos() - - class Uuid(KaitaiStruct): - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = [None] * (16) - for i in range(16): - if not 'arr' in self._debug['data']: - self._debug['data']['arr'] = [] - self._debug['data']['arr'].append({'start': self._io.pos()}) - self.data[i] = self._io.read_u1() - self._debug['data']['arr'][i]['end'] = self._io.pos() - - self._debug['data']['end'] = self._io.pos() - - - class Framez(KaitaiStruct): - SEQ_FIELDS = ["frames"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['frames']['start'] = self._io.pos() - self.frames = [None] * ((self._root.last_frame + 1)) - for i in range((self._root.last_frame + 1)): - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.Frame(self._io, self, self._root) - _t_frames._read() - self.frames[i] = _t_frames - self._debug['frames']['arr'][i]['end'] = self._io.pos() - - self._debug['frames']['end'] = self._io.pos() - - - class Frame(KaitaiStruct): - - class FrameType(Enum): - scanned = 0 - spectroscopy = 1 - text = 3 - old_mda = 105 - mda = 106 - palette = 107 - curves_new = 190 - curves = 201 - SEQ_FIELDS = ["size", "main"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - self._debug['main']['start'] = self._io.pos() - self._raw_main = self._io.read_bytes((self.size - 4)) - io = KaitaiStream(BytesIO(self._raw_main)) - self.main = self._root.Frame.FrameMain(io, self, self._root) - self.main._read() - self._debug['main']['end'] = self._io.pos() - - class Dots(KaitaiStruct): - SEQ_FIELDS = ["fm_ndots", "coord_header", "coordinates", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['fm_ndots']['start'] = self._io.pos() - self.fm_ndots = self._io.read_u2le() - self._debug['fm_ndots']['end'] = self._io.pos() - if self.fm_ndots > 0: - self._debug['coord_header']['start'] = self._io.pos() - self.coord_header = self._root.Frame.Dots.DotsHeader(self._io, self, self._root) - self.coord_header._read() - self._debug['coord_header']['end'] = self._io.pos() - - self._debug['coordinates']['start'] = self._io.pos() - self.coordinates = [None] * (self.fm_ndots) - for i in range(self.fm_ndots): - if not 'arr' in self._debug['coordinates']: - self._debug['coordinates']['arr'] = [] - self._debug['coordinates']['arr'].append({'start': self._io.pos()}) - _t_coordinates = self._root.Frame.Dots.DotsData(self._io, self, self._root) - _t_coordinates._read() - self.coordinates[i] = _t_coordinates - self._debug['coordinates']['arr'][i]['end'] = self._io.pos() - - self._debug['coordinates']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = [None] * (self.fm_ndots) - for i in range(self.fm_ndots): - if not 'arr' in self._debug['data']: - self._debug['data']['arr'] = [] - self._debug['data']['arr'].append({'start': self._io.pos()}) - _t_data = self._root.Frame.Dots.DataLinez(i, self._io, self, self._root) - _t_data._read() - self.data[i] = _t_data - self._debug['data']['arr'][i]['end'] = self._io.pos() - - self._debug['data']['end'] = self._io.pos() - - class DotsHeader(KaitaiStruct): - SEQ_FIELDS = ["header_size", "header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_s4le() - self._debug['header_size']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Frame.Dots.DotsHeader.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["coord_size", "version", "xyunits"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['coord_size']['start'] = self._io.pos() - self.coord_size = self._io.read_s4le() - self._debug['coord_size']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_s4le() - self._debug['version']['end'] = self._io.pos() - self._debug['xyunits']['start'] = self._io.pos() - self.xyunits = KaitaiStream.resolve_enum(self._root.Unit, self._io.read_s2le()) - self._debug['xyunits']['end'] = self._io.pos() - - - - class DotsData(KaitaiStruct): - SEQ_FIELDS = ["coord_x", "coord_y", "forward_size", "backward_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['coord_x']['start'] = self._io.pos() - self.coord_x = self._io.read_f4le() - self._debug['coord_x']['end'] = self._io.pos() - self._debug['coord_y']['start'] = self._io.pos() - self.coord_y = self._io.read_f4le() - self._debug['coord_y']['end'] = self._io.pos() - self._debug['forward_size']['start'] = self._io.pos() - self.forward_size = self._io.read_s4le() - self._debug['forward_size']['end'] = self._io.pos() - self._debug['backward_size']['start'] = self._io.pos() - self.backward_size = self._io.read_s4le() - self._debug['backward_size']['end'] = self._io.pos() - - - class DataLinez(KaitaiStruct): - SEQ_FIELDS = ["forward", "backward"] - def __init__(self, index, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.index = index - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['forward']['start'] = self._io.pos() - self.forward = [None] * (self._parent.coordinates[self.index].forward_size) - for i in range(self._parent.coordinates[self.index].forward_size): - if not 'arr' in self._debug['forward']: - self._debug['forward']['arr'] = [] - self._debug['forward']['arr'].append({'start': self._io.pos()}) - self.forward[i] = self._io.read_s2le() - self._debug['forward']['arr'][i]['end'] = self._io.pos() - - self._debug['forward']['end'] = self._io.pos() - self._debug['backward']['start'] = self._io.pos() - self.backward = [None] * (self._parent.coordinates[self.index].backward_size) - for i in range(self._parent.coordinates[self.index].backward_size): - if not 'arr' in self._debug['backward']: - self._debug['backward']['arr'] = [] - self._debug['backward']['arr'].append({'start': self._io.pos()}) - self.backward[i] = self._io.read_s2le() - self._debug['backward']['arr'][i]['end'] = self._io.pos() - - self._debug['backward']['end'] = self._io.pos() - - - - class FrameMain(KaitaiStruct): - SEQ_FIELDS = ["type", "version", "date_time", "var_size", "frame_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.Frame.FrameType, self._io.read_u2le()) - self._debug['type']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Version(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['date_time']['start'] = self._io.pos() - self.date_time = self._root.Frame.DateTime(self._io, self, self._root) - self.date_time._read() - self._debug['date_time']['end'] = self._io.pos() - self._debug['var_size']['start'] = self._io.pos() - self.var_size = self._io.read_u2le() - self._debug['var_size']['end'] = self._io.pos() - self._debug['frame_data']['start'] = self._io.pos() - _on = self.type - if _on == self._root.Frame.FrameType.mda: - self._raw_frame_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_frame_data)) - self.frame_data = self._root.Frame.FdMetaData(io, self, self._root) - self.frame_data._read() - elif _on == self._root.Frame.FrameType.curves_new: - self._raw_frame_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_frame_data)) - self.frame_data = self._root.Frame.FdCurvesNew(io, self, self._root) - self.frame_data._read() - elif _on == self._root.Frame.FrameType.curves: - self._raw_frame_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_frame_data)) - self.frame_data = self._root.Frame.FdSpectroscopy(io, self, self._root) - self.frame_data._read() - elif _on == self._root.Frame.FrameType.spectroscopy: - self._raw_frame_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_frame_data)) - self.frame_data = self._root.Frame.FdSpectroscopy(io, self, self._root) - self.frame_data._read() - elif _on == self._root.Frame.FrameType.scanned: - self._raw_frame_data = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_frame_data)) - self.frame_data = self._root.Frame.FdScanned(io, self, self._root) - self.frame_data._read() - else: - self.frame_data = self._io.read_bytes_full() - self._debug['frame_data']['end'] = self._io.pos() - - - class FdCurvesNew(KaitaiStruct): - SEQ_FIELDS = ["block_count", "blocks_headers", "blocks_names", "blocks_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['block_count']['start'] = self._io.pos() - self.block_count = self._io.read_u4le() - self._debug['block_count']['end'] = self._io.pos() - self._debug['blocks_headers']['start'] = self._io.pos() - self.blocks_headers = [None] * (self.block_count) - for i in range(self.block_count): - if not 'arr' in self._debug['blocks_headers']: - self._debug['blocks_headers']['arr'] = [] - self._debug['blocks_headers']['arr'].append({'start': self._io.pos()}) - _t_blocks_headers = self._root.Frame.FdCurvesNew.BlockDescr(self._io, self, self._root) - _t_blocks_headers._read() - self.blocks_headers[i] = _t_blocks_headers - self._debug['blocks_headers']['arr'][i]['end'] = self._io.pos() - - self._debug['blocks_headers']['end'] = self._io.pos() - self._debug['blocks_names']['start'] = self._io.pos() - self.blocks_names = [None] * (self.block_count) - for i in range(self.block_count): - if not 'arr' in self._debug['blocks_names']: - self._debug['blocks_names']['arr'] = [] - self._debug['blocks_names']['arr'].append({'start': self._io.pos()}) - self.blocks_names[i] = (self._io.read_bytes(self.blocks_headers[i].name_len)).decode(u"UTF-8") - self._debug['blocks_names']['arr'][i]['end'] = self._io.pos() - - self._debug['blocks_names']['end'] = self._io.pos() - self._debug['blocks_data']['start'] = self._io.pos() - self.blocks_data = [None] * (self.block_count) - for i in range(self.block_count): - if not 'arr' in self._debug['blocks_data']: - self._debug['blocks_data']['arr'] = [] - self._debug['blocks_data']['arr'].append({'start': self._io.pos()}) - self.blocks_data[i] = self._io.read_bytes(self.blocks_headers[i].len) - self._debug['blocks_data']['arr'][i]['end'] = self._io.pos() - - self._debug['blocks_data']['end'] = self._io.pos() - - class BlockDescr(KaitaiStruct): - SEQ_FIELDS = ["name_len", "len"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_len']['start'] = self._io.pos() - self.name_len = self._io.read_u4le() - self._debug['name_len']['end'] = self._io.pos() - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u4le() - self._debug['len']['end'] = self._io.pos() - - - - class FdMetaData(KaitaiStruct): - SEQ_FIELDS = ["head_size", "tot_len", "guids", "frame_status", "name_size", "comm_size", "view_info_size", "spec_size", "source_info_size", "var_size", "data_offset", "data_size", "title", "xml", "struct_len", "array_size", "cell_size", "n_dimensions", "n_mesurands", "dimensions", "mesurands"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['head_size']['start'] = self._io.pos() - self.head_size = self._io.read_u4le() - self._debug['head_size']['end'] = self._io.pos() - self._debug['tot_len']['start'] = self._io.pos() - self.tot_len = self._io.read_u4le() - self._debug['tot_len']['end'] = self._io.pos() - self._debug['guids']['start'] = self._io.pos() - self.guids = [None] * (2) - for i in range(2): - if not 'arr' in self._debug['guids']: - self._debug['guids']['arr'] = [] - self._debug['guids']['arr'].append({'start': self._io.pos()}) - _t_guids = self._root.Uuid(self._io, self, self._root) - _t_guids._read() - self.guids[i] = _t_guids - self._debug['guids']['arr'][i]['end'] = self._io.pos() - - self._debug['guids']['end'] = self._io.pos() - self._debug['frame_status']['start'] = self._io.pos() - self.frame_status = self._io.read_bytes(4) - self._debug['frame_status']['end'] = self._io.pos() - self._debug['name_size']['start'] = self._io.pos() - self.name_size = self._io.read_u4le() - self._debug['name_size']['end'] = self._io.pos() - self._debug['comm_size']['start'] = self._io.pos() - self.comm_size = self._io.read_u4le() - self._debug['comm_size']['end'] = self._io.pos() - self._debug['view_info_size']['start'] = self._io.pos() - self.view_info_size = self._io.read_u4le() - self._debug['view_info_size']['end'] = self._io.pos() - self._debug['spec_size']['start'] = self._io.pos() - self.spec_size = self._io.read_u4le() - self._debug['spec_size']['end'] = self._io.pos() - self._debug['source_info_size']['start'] = self._io.pos() - self.source_info_size = self._io.read_u4le() - self._debug['source_info_size']['end'] = self._io.pos() - self._debug['var_size']['start'] = self._io.pos() - self.var_size = self._io.read_u4le() - self._debug['var_size']['end'] = self._io.pos() - self._debug['data_offset']['start'] = self._io.pos() - self.data_offset = self._io.read_u4le() - self._debug['data_offset']['end'] = self._io.pos() - self._debug['data_size']['start'] = self._io.pos() - self.data_size = self._io.read_u4le() - self._debug['data_size']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = (self._io.read_bytes(self.name_size)).decode(u"UTF-8") - self._debug['title']['end'] = self._io.pos() - self._debug['xml']['start'] = self._io.pos() - self.xml = (self._io.read_bytes(self.comm_size)).decode(u"UTF-8") - self._debug['xml']['end'] = self._io.pos() - self._debug['struct_len']['start'] = self._io.pos() - self.struct_len = self._io.read_u4le() - self._debug['struct_len']['end'] = self._io.pos() - self._debug['array_size']['start'] = self._io.pos() - self.array_size = self._io.read_u8le() - self._debug['array_size']['end'] = self._io.pos() - self._debug['cell_size']['start'] = self._io.pos() - self.cell_size = self._io.read_u4le() - self._debug['cell_size']['end'] = self._io.pos() - self._debug['n_dimensions']['start'] = self._io.pos() - self.n_dimensions = self._io.read_u4le() - self._debug['n_dimensions']['end'] = self._io.pos() - self._debug['n_mesurands']['start'] = self._io.pos() - self.n_mesurands = self._io.read_u4le() - self._debug['n_mesurands']['end'] = self._io.pos() - self._debug['dimensions']['start'] = self._io.pos() - self.dimensions = [None] * (self.n_dimensions) - for i in range(self.n_dimensions): - if not 'arr' in self._debug['dimensions']: - self._debug['dimensions']['arr'] = [] - self._debug['dimensions']['arr'].append({'start': self._io.pos()}) - _t_dimensions = self._root.Frame.FdMetaData.Calibration(self._io, self, self._root) - _t_dimensions._read() - self.dimensions[i] = _t_dimensions - self._debug['dimensions']['arr'][i]['end'] = self._io.pos() - - self._debug['dimensions']['end'] = self._io.pos() - self._debug['mesurands']['start'] = self._io.pos() - self.mesurands = [None] * (self.n_mesurands) - for i in range(self.n_mesurands): - if not 'arr' in self._debug['mesurands']: - self._debug['mesurands']['arr'] = [] - self._debug['mesurands']['arr'].append({'start': self._io.pos()}) - _t_mesurands = self._root.Frame.FdMetaData.Calibration(self._io, self, self._root) - _t_mesurands._read() - self.mesurands[i] = _t_mesurands - self._debug['mesurands']['arr'][i]['end'] = self._io.pos() - - self._debug['mesurands']['end'] = self._io.pos() - - class Image(KaitaiStruct): - SEQ_FIELDS = ["image"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['image']['start'] = self._io.pos() - self.image = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['image']: - self._debug['image']['arr'] = [] - self._debug['image']['arr'].append({'start': self._io.pos()}) - _t_image = self._root.Frame.FdMetaData.Image.Vec(self._io, self, self._root) - _t_image._read() - self.image.append(_t_image) - self._debug['image']['arr'][len(self.image) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['image']['end'] = self._io.pos() - - class Vec(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self._parent._parent.n_mesurands) - for i in range(self._parent._parent.n_mesurands): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _on = self._parent._parent.mesurands[i].data_type - if _on == self._root.DataType.uint64: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_u8le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.uint8: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_u1() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.float32: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_f4le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.int8: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_s1() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.uint16: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_u2le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.int64: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_s8le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.uint32: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_u4le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.float64: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_f8le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.int16: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_s2le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - elif _on == self._root.DataType.int32: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - self.items[i] = self._io.read_s4le() - self._debug['items']['arr'][i]['end'] = self._io.pos() - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - - - class Calibration(KaitaiStruct): - SEQ_FIELDS = ["len_tot", "len_struct", "len_name", "len_comment", "len_unit", "si_unit", "accuracy", "function_id_and_dimensions", "bias", "scale", "min_index", "max_index", "data_type", "len_author", "name", "comment", "unit", "author"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_tot']['start'] = self._io.pos() - self.len_tot = self._io.read_u4le() - self._debug['len_tot']['end'] = self._io.pos() - self._debug['len_struct']['start'] = self._io.pos() - self.len_struct = self._io.read_u4le() - self._debug['len_struct']['end'] = self._io.pos() - self._debug['len_name']['start'] = self._io.pos() - self.len_name = self._io.read_u4le() - self._debug['len_name']['end'] = self._io.pos() - self._debug['len_comment']['start'] = self._io.pos() - self.len_comment = self._io.read_u4le() - self._debug['len_comment']['end'] = self._io.pos() - self._debug['len_unit']['start'] = self._io.pos() - self.len_unit = self._io.read_u4le() - self._debug['len_unit']['end'] = self._io.pos() - self._debug['si_unit']['start'] = self._io.pos() - self.si_unit = self._io.read_u8le() - self._debug['si_unit']['end'] = self._io.pos() - self._debug['accuracy']['start'] = self._io.pos() - self.accuracy = self._io.read_f8le() - self._debug['accuracy']['end'] = self._io.pos() - self._debug['function_id_and_dimensions']['start'] = self._io.pos() - self.function_id_and_dimensions = self._io.read_u8le() - self._debug['function_id_and_dimensions']['end'] = self._io.pos() - self._debug['bias']['start'] = self._io.pos() - self.bias = self._io.read_f8le() - self._debug['bias']['end'] = self._io.pos() - self._debug['scale']['start'] = self._io.pos() - self.scale = self._io.read_f8le() - self._debug['scale']['end'] = self._io.pos() - self._debug['min_index']['start'] = self._io.pos() - self.min_index = self._io.read_u8le() - self._debug['min_index']['end'] = self._io.pos() - self._debug['max_index']['start'] = self._io.pos() - self.max_index = self._io.read_u8le() - self._debug['max_index']['end'] = self._io.pos() - self._debug['data_type']['start'] = self._io.pos() - self.data_type = KaitaiStream.resolve_enum(self._root.DataType, self._io.read_s4le()) - self._debug['data_type']['end'] = self._io.pos() - self._debug['len_author']['start'] = self._io.pos() - self.len_author = self._io.read_u4le() - self._debug['len_author']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.len_name)).decode(u"utf-8") - self._debug['name']['end'] = self._io.pos() - self._debug['comment']['start'] = self._io.pos() - self.comment = (self._io.read_bytes(self.len_comment)).decode(u"utf-8") - self._debug['comment']['end'] = self._io.pos() - self._debug['unit']['start'] = self._io.pos() - self.unit = (self._io.read_bytes(self.len_unit)).decode(u"utf-8") - self._debug['unit']['end'] = self._io.pos() - self._debug['author']['start'] = self._io.pos() - self.author = (self._io.read_bytes(self.len_author)).decode(u"utf-8") - self._debug['author']['end'] = self._io.pos() - - @property - def count(self): - if hasattr(self, '_m_count'): - return self._m_count if hasattr(self, '_m_count') else None - - self._m_count = ((self.max_index - self.min_index) + 1) - return self._m_count if hasattr(self, '_m_count') else None - - - @property - def image(self): - if hasattr(self, '_m_image'): - return self._m_image if hasattr(self, '_m_image') else None - - _pos = self._io.pos() - self._io.seek(self.data_offset) - self._debug['_m_image']['start'] = self._io.pos() - self._raw__m_image = self._io.read_bytes(self.data_size) - io = KaitaiStream(BytesIO(self._raw__m_image)) - self._m_image = self._root.Frame.FdMetaData.Image(io, self, self._root) - self._m_image._read() - self._debug['_m_image']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_image if hasattr(self, '_m_image') else None - - - class FdSpectroscopy(KaitaiStruct): - SEQ_FIELDS = ["vars", "fm_mode", "fm_xres", "fm_yres", "dots", "data", "title", "xml"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['vars']['start'] = self._io.pos() - self._raw_vars = self._io.read_bytes(self._parent.var_size) - io = KaitaiStream(BytesIO(self._raw_vars)) - self.vars = self._root.Frame.FdSpectroscopy.Vars(io, self, self._root) - self.vars._read() - self._debug['vars']['end'] = self._io.pos() - self._debug['fm_mode']['start'] = self._io.pos() - self.fm_mode = self._io.read_u2le() - self._debug['fm_mode']['end'] = self._io.pos() - self._debug['fm_xres']['start'] = self._io.pos() - self.fm_xres = self._io.read_u2le() - self._debug['fm_xres']['end'] = self._io.pos() - self._debug['fm_yres']['start'] = self._io.pos() - self.fm_yres = self._io.read_u2le() - self._debug['fm_yres']['end'] = self._io.pos() - self._debug['dots']['start'] = self._io.pos() - self.dots = self._root.Frame.Dots(self._io, self, self._root) - self.dots._read() - self._debug['dots']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = [None] * ((self.fm_xres * self.fm_yres)) - for i in range((self.fm_xres * self.fm_yres)): - if not 'arr' in self._debug['data']: - self._debug['data']['arr'] = [] - self._debug['data']['arr'].append({'start': self._io.pos()}) - self.data[i] = self._io.read_s2le() - self._debug['data']['arr'][i]['end'] = self._io.pos() - - self._debug['data']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = self._root.Title(self._io, self, self._root) - self.title._read() - self._debug['title']['end'] = self._io.pos() - self._debug['xml']['start'] = self._io.pos() - self.xml = self._root.Xml(self._io, self, self._root) - self.xml._read() - self._debug['xml']['end'] = self._io.pos() - - class Vars(KaitaiStruct): - SEQ_FIELDS = ["x_scale", "y_scale", "z_scale", "sp_mode", "sp_filter", "u_begin", "u_end", "z_up", "z_down", "sp_averaging", "sp_repeat", "sp_back", "sp_4nx", "sp_osc", "sp_n4", "sp_4x0", "sp_4xr", "sp_4u", "sp_4i", "sp_nx"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x_scale']['start'] = self._io.pos() - self.x_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.x_scale._read() - self._debug['x_scale']['end'] = self._io.pos() - self._debug['y_scale']['start'] = self._io.pos() - self.y_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.y_scale._read() - self._debug['y_scale']['end'] = self._io.pos() - self._debug['z_scale']['start'] = self._io.pos() - self.z_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.z_scale._read() - self._debug['z_scale']['end'] = self._io.pos() - self._debug['sp_mode']['start'] = self._io.pos() - self.sp_mode = self._io.read_u2le() - self._debug['sp_mode']['end'] = self._io.pos() - self._debug['sp_filter']['start'] = self._io.pos() - self.sp_filter = self._io.read_u2le() - self._debug['sp_filter']['end'] = self._io.pos() - self._debug['u_begin']['start'] = self._io.pos() - self.u_begin = self._io.read_f4le() - self._debug['u_begin']['end'] = self._io.pos() - self._debug['u_end']['start'] = self._io.pos() - self.u_end = self._io.read_f4le() - self._debug['u_end']['end'] = self._io.pos() - self._debug['z_up']['start'] = self._io.pos() - self.z_up = self._io.read_s2le() - self._debug['z_up']['end'] = self._io.pos() - self._debug['z_down']['start'] = self._io.pos() - self.z_down = self._io.read_s2le() - self._debug['z_down']['end'] = self._io.pos() - self._debug['sp_averaging']['start'] = self._io.pos() - self.sp_averaging = self._io.read_u2le() - self._debug['sp_averaging']['end'] = self._io.pos() - self._debug['sp_repeat']['start'] = self._io.pos() - self.sp_repeat = self._io.read_u1() - self._debug['sp_repeat']['end'] = self._io.pos() - self._debug['sp_back']['start'] = self._io.pos() - self.sp_back = self._io.read_u1() - self._debug['sp_back']['end'] = self._io.pos() - self._debug['sp_4nx']['start'] = self._io.pos() - self.sp_4nx = self._io.read_s2le() - self._debug['sp_4nx']['end'] = self._io.pos() - self._debug['sp_osc']['start'] = self._io.pos() - self.sp_osc = self._io.read_u1() - self._debug['sp_osc']['end'] = self._io.pos() - self._debug['sp_n4']['start'] = self._io.pos() - self.sp_n4 = self._io.read_u1() - self._debug['sp_n4']['end'] = self._io.pos() - self._debug['sp_4x0']['start'] = self._io.pos() - self.sp_4x0 = self._io.read_f4le() - self._debug['sp_4x0']['end'] = self._io.pos() - self._debug['sp_4xr']['start'] = self._io.pos() - self.sp_4xr = self._io.read_f4le() - self._debug['sp_4xr']['end'] = self._io.pos() - self._debug['sp_4u']['start'] = self._io.pos() - self.sp_4u = self._io.read_s2le() - self._debug['sp_4u']['end'] = self._io.pos() - self._debug['sp_4i']['start'] = self._io.pos() - self.sp_4i = self._io.read_s2le() - self._debug['sp_4i']['end'] = self._io.pos() - self._debug['sp_nx']['start'] = self._io.pos() - self.sp_nx = self._io.read_s2le() - self._debug['sp_nx']['end'] = self._io.pos() - - - - class DateTime(KaitaiStruct): - SEQ_FIELDS = ["date", "time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['date']['start'] = self._io.pos() - self.date = self._root.Frame.DateTime.Date(self._io, self, self._root) - self.date._read() - self._debug['date']['end'] = self._io.pos() - self._debug['time']['start'] = self._io.pos() - self.time = self._root.Frame.DateTime.Time(self._io, self, self._root) - self.time._read() - self._debug['time']['end'] = self._io.pos() - - class Date(KaitaiStruct): - SEQ_FIELDS = ["year", "month", "day"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = self._io.read_u2le() - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = self._io.read_u2le() - self._debug['month']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = self._io.read_u2le() - self._debug['day']['end'] = self._io.pos() - - - class Time(KaitaiStruct): - SEQ_FIELDS = ["hour", "min", "sec"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hour']['start'] = self._io.pos() - self.hour = self._io.read_u2le() - self._debug['hour']['end'] = self._io.pos() - self._debug['min']['start'] = self._io.pos() - self.min = self._io.read_u2le() - self._debug['min']['end'] = self._io.pos() - self._debug['sec']['start'] = self._io.pos() - self.sec = self._io.read_u2le() - self._debug['sec']['end'] = self._io.pos() - - - - class AxisScale(KaitaiStruct): - SEQ_FIELDS = ["offset", "step", "unit"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_f4le() - self._debug['offset']['end'] = self._io.pos() - self._debug['step']['start'] = self._io.pos() - self.step = self._io.read_f4le() - self._debug['step']['end'] = self._io.pos() - self._debug['unit']['start'] = self._io.pos() - self.unit = KaitaiStream.resolve_enum(self._root.Unit, self._io.read_s2le()) - self._debug['unit']['end'] = self._io.pos() - - - class FdScanned(KaitaiStruct): - - class Mode(Enum): - stm = 0 - afm = 1 - unknown2 = 2 - unknown3 = 3 - unknown4 = 4 - - class InputSignal(Enum): - extension_slot = 0 - bias_v = 1 - ground = 2 - - class LiftMode(Enum): - step = 0 - fine = 1 - slope = 2 - SEQ_FIELDS = ["vars", "orig_format", "tune", "feedback_gain", "dac_scale", "overscan", "fm_mode", "fm_xres", "fm_yres", "dots", "image", "title", "xml"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['vars']['start'] = self._io.pos() - self._raw_vars = self._io.read_bytes(self._parent.var_size) - io = KaitaiStream(BytesIO(self._raw_vars)) - self.vars = self._root.Frame.FdScanned.Vars(io, self, self._root) - self.vars._read() - self._debug['vars']['end'] = self._io.pos() - if False: - self._debug['orig_format']['start'] = self._io.pos() - self.orig_format = self._io.read_u4le() - self._debug['orig_format']['end'] = self._io.pos() - - if False: - self._debug['tune']['start'] = self._io.pos() - self.tune = KaitaiStream.resolve_enum(self._root.Frame.FdScanned.LiftMode, self._io.read_u4le()) - self._debug['tune']['end'] = self._io.pos() - - if False: - self._debug['feedback_gain']['start'] = self._io.pos() - self.feedback_gain = self._io.read_f8le() - self._debug['feedback_gain']['end'] = self._io.pos() - - if False: - self._debug['dac_scale']['start'] = self._io.pos() - self.dac_scale = self._io.read_s4le() - self._debug['dac_scale']['end'] = self._io.pos() - - if False: - self._debug['overscan']['start'] = self._io.pos() - self.overscan = self._io.read_s4le() - self._debug['overscan']['end'] = self._io.pos() - - self._debug['fm_mode']['start'] = self._io.pos() - self.fm_mode = self._io.read_u2le() - self._debug['fm_mode']['end'] = self._io.pos() - self._debug['fm_xres']['start'] = self._io.pos() - self.fm_xres = self._io.read_u2le() - self._debug['fm_xres']['end'] = self._io.pos() - self._debug['fm_yres']['start'] = self._io.pos() - self.fm_yres = self._io.read_u2le() - self._debug['fm_yres']['end'] = self._io.pos() - self._debug['dots']['start'] = self._io.pos() - self.dots = self._root.Frame.Dots(self._io, self, self._root) - self.dots._read() - self._debug['dots']['end'] = self._io.pos() - self._debug['image']['start'] = self._io.pos() - self.image = [None] * ((self.fm_xres * self.fm_yres)) - for i in range((self.fm_xres * self.fm_yres)): - if not 'arr' in self._debug['image']: - self._debug['image']['arr'] = [] - self._debug['image']['arr'].append({'start': self._io.pos()}) - self.image[i] = self._io.read_s2le() - self._debug['image']['arr'][i]['end'] = self._io.pos() - - self._debug['image']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = self._root.Title(self._io, self, self._root) - self.title._read() - self._debug['title']['end'] = self._io.pos() - self._debug['xml']['start'] = self._io.pos() - self.xml = self._root.Xml(self._io, self, self._root) - self.xml._read() - self._debug['xml']['end'] = self._io.pos() - - class Vars(KaitaiStruct): - SEQ_FIELDS = ["x_scale", "y_scale", "z_scale", "channel_index", "mode", "xres", "yres", "ndacq", "step_length", "adt", "adc_gain_amp_log10", "adc_index", "input_signal_or_version", "substr_plane_order_or_pass_num", "scan_dir", "power_of_2", "velocity", "setpoint", "bias_voltage", "draw", "reserved", "xoff", "yoff", "nl_corr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x_scale']['start'] = self._io.pos() - self.x_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.x_scale._read() - self._debug['x_scale']['end'] = self._io.pos() - self._debug['y_scale']['start'] = self._io.pos() - self.y_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.y_scale._read() - self._debug['y_scale']['end'] = self._io.pos() - self._debug['z_scale']['start'] = self._io.pos() - self.z_scale = self._root.Frame.AxisScale(self._io, self, self._root) - self.z_scale._read() - self._debug['z_scale']['end'] = self._io.pos() - self._debug['channel_index']['start'] = self._io.pos() - self.channel_index = KaitaiStream.resolve_enum(self._root.AdcMode, self._io.read_u1()) - self._debug['channel_index']['end'] = self._io.pos() - self._debug['mode']['start'] = self._io.pos() - self.mode = KaitaiStream.resolve_enum(self._root.Frame.FdScanned.Mode, self._io.read_u1()) - self._debug['mode']['end'] = self._io.pos() - self._debug['xres']['start'] = self._io.pos() - self.xres = self._io.read_u2le() - self._debug['xres']['end'] = self._io.pos() - self._debug['yres']['start'] = self._io.pos() - self.yres = self._io.read_u2le() - self._debug['yres']['end'] = self._io.pos() - self._debug['ndacq']['start'] = self._io.pos() - self.ndacq = self._io.read_u2le() - self._debug['ndacq']['end'] = self._io.pos() - self._debug['step_length']['start'] = self._io.pos() - self.step_length = self._io.read_f4le() - self._debug['step_length']['end'] = self._io.pos() - self._debug['adt']['start'] = self._io.pos() - self.adt = self._io.read_u2le() - self._debug['adt']['end'] = self._io.pos() - self._debug['adc_gain_amp_log10']['start'] = self._io.pos() - self.adc_gain_amp_log10 = self._io.read_u1() - self._debug['adc_gain_amp_log10']['end'] = self._io.pos() - self._debug['adc_index']['start'] = self._io.pos() - self.adc_index = self._io.read_u1() - self._debug['adc_index']['end'] = self._io.pos() - self._debug['input_signal_or_version']['start'] = self._io.pos() - self.input_signal_or_version = self._io.read_u1() - self._debug['input_signal_or_version']['end'] = self._io.pos() - self._debug['substr_plane_order_or_pass_num']['start'] = self._io.pos() - self.substr_plane_order_or_pass_num = self._io.read_u1() - self._debug['substr_plane_order_or_pass_num']['end'] = self._io.pos() - self._debug['scan_dir']['start'] = self._io.pos() - self.scan_dir = self._root.Frame.FdScanned.ScanDir(self._io, self, self._root) - self.scan_dir._read() - self._debug['scan_dir']['end'] = self._io.pos() - self._debug['power_of_2']['start'] = self._io.pos() - self.power_of_2 = self._io.read_u1() - self._debug['power_of_2']['end'] = self._io.pos() - self._debug['velocity']['start'] = self._io.pos() - self.velocity = self._io.read_f4le() - self._debug['velocity']['end'] = self._io.pos() - self._debug['setpoint']['start'] = self._io.pos() - self.setpoint = self._io.read_f4le() - self._debug['setpoint']['end'] = self._io.pos() - self._debug['bias_voltage']['start'] = self._io.pos() - self.bias_voltage = self._io.read_f4le() - self._debug['bias_voltage']['end'] = self._io.pos() - self._debug['draw']['start'] = self._io.pos() - self.draw = self._io.read_u1() - self._debug['draw']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u1() - self._debug['reserved']['end'] = self._io.pos() - self._debug['xoff']['start'] = self._io.pos() - self.xoff = self._io.read_s4le() - self._debug['xoff']['end'] = self._io.pos() - self._debug['yoff']['start'] = self._io.pos() - self.yoff = self._io.read_s4le() - self._debug['yoff']['end'] = self._io.pos() - self._debug['nl_corr']['start'] = self._io.pos() - self.nl_corr = self._io.read_u1() - self._debug['nl_corr']['end'] = self._io.pos() - - - class Dot(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - - - class ScanDir(KaitaiStruct): - SEQ_FIELDS = ["unkn", "double_pass", "bottom", "left", "horizontal"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unkn']['start'] = self._io.pos() - self.unkn = self._io.read_bits_int(4) - self._debug['unkn']['end'] = self._io.pos() - self._debug['double_pass']['start'] = self._io.pos() - self.double_pass = self._io.read_bits_int(1) != 0 - self._debug['double_pass']['end'] = self._io.pos() - self._debug['bottom']['start'] = self._io.pos() - self.bottom = self._io.read_bits_int(1) != 0 - self._debug['bottom']['end'] = self._io.pos() - self._debug['left']['start'] = self._io.pos() - self.left = self._io.read_bits_int(1) != 0 - self._debug['left']['end'] = self._io.pos() - self._debug['horizontal']['start'] = self._io.pos() - self.horizontal = self._io.read_bits_int(1) != 0 - self._debug['horizontal']['end'] = self._io.pos() - - - - - class Version(KaitaiStruct): - SEQ_FIELDS = ["minor", "major"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u1() - self._debug['minor']['end'] = self._io.pos() - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u1() - self._debug['major']['end'] = self._io.pos() - - - class Xml(KaitaiStruct): - SEQ_FIELDS = ["xml_len", "xml"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['xml_len']['start'] = self._io.pos() - self.xml_len = self._io.read_u4le() - self._debug['xml_len']['end'] = self._io.pos() - self._debug['xml']['start'] = self._io.pos() - self.xml = (self._io.read_bytes(self.xml_len)).decode(u"UTF-16LE") - self._debug['xml']['end'] = self._io.pos() - - - class Title(KaitaiStruct): - SEQ_FIELDS = ["title_len", "title"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['title_len']['start'] = self._io.pos() - self.title_len = self._io.read_u4le() - self._debug['title_len']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = (self._io.read_bytes(self.title_len)).decode(u"cp1251") - self._debug['title']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/nt_mdt_pal.py b/python/examples/kaitai/nt_mdt_pal.py deleted file mode 100644 index ca3f8958..00000000 --- a/python/examples/kaitai/nt_mdt_pal.py +++ /dev/null @@ -1,152 +0,0 @@ -# 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 -import collections - - -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 NtMdtPal(KaitaiStruct): - """It is a color scheme for visualising SPM scans.""" - SEQ_FIELDS = ["signature", "count", "meta", "something2", "tables"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x4E\x54\x2D\x4D\x44\x54\x20\x50\x61\x6C\x65\x74\x74\x65\x20\x46\x69\x6C\x65\x20\x20\x31\x2E\x30\x30\x21") - self._debug['signature']['end'] = self._io.pos() - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u4be() - self._debug['count']['end'] = self._io.pos() - self._debug['meta']['start'] = self._io.pos() - self.meta = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['meta']: - self._debug['meta']['arr'] = [] - self._debug['meta']['arr'].append({'start': self._io.pos()}) - _t_meta = self._root.Meta(self._io, self, self._root) - _t_meta._read() - self.meta[i] = _t_meta - self._debug['meta']['arr'][i]['end'] = self._io.pos() - - self._debug['meta']['end'] = self._io.pos() - self._debug['something2']['start'] = self._io.pos() - self.something2 = self._io.read_bytes(1) - self._debug['something2']['end'] = self._io.pos() - self._debug['tables']['start'] = self._io.pos() - self.tables = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['tables']: - self._debug['tables']['arr'] = [] - self._debug['tables']['arr'].append({'start': self._io.pos()}) - _t_tables = self._root.ColTable(i, self._io, self, self._root) - _t_tables._read() - self.tables[i] = _t_tables - self._debug['tables']['arr'][i]['end'] = self._io.pos() - - self._debug['tables']['end'] = self._io.pos() - - class Meta(KaitaiStruct): - SEQ_FIELDS = ["unkn00", "unkn01", "unkn02", "unkn03", "colors_count", "unkn10", "unkn11", "unkn12", "name_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unkn00']['start'] = self._io.pos() - self.unkn00 = self._io.read_bytes(3) - self._debug['unkn00']['end'] = self._io.pos() - self._debug['unkn01']['start'] = self._io.pos() - self.unkn01 = self._io.read_bytes(2) - self._debug['unkn01']['end'] = self._io.pos() - self._debug['unkn02']['start'] = self._io.pos() - self.unkn02 = self._io.read_bytes(1) - self._debug['unkn02']['end'] = self._io.pos() - self._debug['unkn03']['start'] = self._io.pos() - self.unkn03 = self._io.read_bytes(1) - self._debug['unkn03']['end'] = self._io.pos() - self._debug['colors_count']['start'] = self._io.pos() - self.colors_count = self._io.read_u2le() - self._debug['colors_count']['end'] = self._io.pos() - self._debug['unkn10']['start'] = self._io.pos() - self.unkn10 = self._io.read_bytes(2) - self._debug['unkn10']['end'] = self._io.pos() - self._debug['unkn11']['start'] = self._io.pos() - self.unkn11 = self._io.read_bytes(1) - self._debug['unkn11']['end'] = self._io.pos() - self._debug['unkn12']['start'] = self._io.pos() - self.unkn12 = self._io.read_bytes(2) - self._debug['unkn12']['end'] = self._io.pos() - self._debug['name_size']['start'] = self._io.pos() - self.name_size = self._io.read_u2be() - self._debug['name_size']['end'] = self._io.pos() - - - class Color(KaitaiStruct): - SEQ_FIELDS = ["red", "unkn", "blue", "green"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['red']['start'] = self._io.pos() - self.red = self._io.read_u1() - self._debug['red']['end'] = self._io.pos() - self._debug['unkn']['start'] = self._io.pos() - self.unkn = self._io.read_u1() - self._debug['unkn']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._io.read_u1() - self._debug['blue']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._io.read_u1() - self._debug['green']['end'] = self._io.pos() - - - class ColTable(KaitaiStruct): - SEQ_FIELDS = ["size1", "unkn", "title", "unkn1", "colors"] - def __init__(self, index, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.index = index - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size1']['start'] = self._io.pos() - self.size1 = self._io.read_u1() - self._debug['size1']['end'] = self._io.pos() - self._debug['unkn']['start'] = self._io.pos() - self.unkn = self._io.read_u1() - self._debug['unkn']['end'] = self._io.pos() - self._debug['title']['start'] = self._io.pos() - self.title = (self._io.read_bytes(self._root.meta[self.index].name_size)).decode(u"UTF-16") - self._debug['title']['end'] = self._io.pos() - self._debug['unkn1']['start'] = self._io.pos() - self.unkn1 = self._io.read_u2be() - self._debug['unkn1']['end'] = self._io.pos() - self._debug['colors']['start'] = self._io.pos() - self.colors = [None] * ((self._root.meta[self.index].colors_count - 1)) - for i in range((self._root.meta[self.index].colors_count - 1)): - if not 'arr' in self._debug['colors']: - self._debug['colors']['arr'] = [] - self._debug['colors']['arr'].append({'start': self._io.pos()}) - _t_colors = self._root.Color(self._io, self, self._root) - _t_colors._read() - self.colors[i] = _t_colors - self._debug['colors']['arr'][i]['end'] = self._io.pos() - - self._debug['colors']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/ogg.py b/python/examples/kaitai/ogg.py deleted file mode 100644 index 7396c1b3..00000000 --- a/python/examples/kaitai/ogg.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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 -import collections - - -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 Ogg(KaitaiStruct): - """Ogg is a popular media container format, which provides basic - streaming / buffering mechanisms and is content-agnostic. Most - popular codecs that are used within Ogg streams are Vorbis (thus - making Ogg/Vorbis streams) and Theora (Ogg/Theora). - - Ogg stream is a sequence Ogg pages. They can be read sequentially, - or one can jump into arbitrary stream location and scan for "OggS" - sync code to find the beginning of a new Ogg page and continue - decoding the stream contents from that one. - """ - SEQ_FIELDS = ["pages"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pages']['start'] = self._io.pos() - self.pages = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['pages']: - self._debug['pages']['arr'] = [] - self._debug['pages']['arr'].append({'start': self._io.pos()}) - _t_pages = self._root.Page(self._io, self, self._root) - _t_pages._read() - self.pages.append(_t_pages) - self._debug['pages']['arr'][len(self.pages) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['pages']['end'] = self._io.pos() - - class Page(KaitaiStruct): - """Ogg page is a basic unit of data in an Ogg bitstream, usually - it's around 4-8 KB, with a maximum size of 65307 bytes. - """ - SEQ_FIELDS = ["sync_code", "version", "reserved1", "is_end_of_stream", "is_beginning_of_stream", "is_continuation", "granule_pos", "bitstream_serial", "page_seq_num", "crc32", "num_segments", "len_segments", "segments"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sync_code']['start'] = self._io.pos() - self.sync_code = self._io.ensure_fixed_contents(b"\x4F\x67\x67\x53") - self._debug['sync_code']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.ensure_fixed_contents(b"\x00") - self._debug['version']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(5) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['is_end_of_stream']['start'] = self._io.pos() - self.is_end_of_stream = self._io.read_bits_int(1) != 0 - self._debug['is_end_of_stream']['end'] = self._io.pos() - self._debug['is_beginning_of_stream']['start'] = self._io.pos() - self.is_beginning_of_stream = self._io.read_bits_int(1) != 0 - self._debug['is_beginning_of_stream']['end'] = self._io.pos() - self._debug['is_continuation']['start'] = self._io.pos() - self.is_continuation = self._io.read_bits_int(1) != 0 - self._debug['is_continuation']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['granule_pos']['start'] = self._io.pos() - self.granule_pos = self._io.read_u8le() - self._debug['granule_pos']['end'] = self._io.pos() - self._debug['bitstream_serial']['start'] = self._io.pos() - self.bitstream_serial = self._io.read_u4le() - self._debug['bitstream_serial']['end'] = self._io.pos() - self._debug['page_seq_num']['start'] = self._io.pos() - self.page_seq_num = self._io.read_u4le() - self._debug['page_seq_num']['end'] = self._io.pos() - self._debug['crc32']['start'] = self._io.pos() - self.crc32 = self._io.read_u4le() - self._debug['crc32']['end'] = self._io.pos() - self._debug['num_segments']['start'] = self._io.pos() - self.num_segments = self._io.read_u1() - self._debug['num_segments']['end'] = self._io.pos() - self._debug['len_segments']['start'] = self._io.pos() - self.len_segments = [None] * (self.num_segments) - for i in range(self.num_segments): - if not 'arr' in self._debug['len_segments']: - self._debug['len_segments']['arr'] = [] - self._debug['len_segments']['arr'].append({'start': self._io.pos()}) - self.len_segments[i] = self._io.read_u1() - self._debug['len_segments']['arr'][i]['end'] = self._io.pos() - - self._debug['len_segments']['end'] = self._io.pos() - self._debug['segments']['start'] = self._io.pos() - self.segments = [None] * (self.num_segments) - for i in range(self.num_segments): - if not 'arr' in self._debug['segments']: - self._debug['segments']['arr'] = [] - self._debug['segments']['arr'].append({'start': self._io.pos()}) - self.segments[i] = self._io.read_bytes(self.len_segments[i]) - self._debug['segments']['arr'][i]['end'] = self._io.pos() - - self._debug['segments']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/openpgp_message.py b/python/examples/kaitai/openpgp_message.py deleted file mode 100644 index 3b10b5bc..00000000 --- a/python/examples/kaitai/openpgp_message.py +++ /dev/null @@ -1,992 +0,0 @@ -# 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 -import collections - - -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 OpenpgpMessage(KaitaiStruct): - """The OpenPGP Message Format is a format to store encryption and signature keys for emails. - - .. seealso:: - Source - https://tools.ietf.org/html/rfc4880 - """ - - class PublicKeyAlgorithms(Enum): - rsa_encrypt_or_sign_hac = 1 - rsa_encrypt_only_hac = 2 - rsa_sign_only_hac = 3 - elgamal_encrypt_only_elgamal_hac = 16 - dsa_digital_signature_algorithm_fips_hac = 17 - reserved_for_elliptic_curve = 18 - reserved_for_ecdsa = 19 - reserved_formerly_elgamal_encrypt_or_sign_ = 20 - reserved_for_diffie_hellman_x_as_defined_for_ietf_s_mime = 21 - private_experimental_algorithm_00 = 100 - private_experimental_algorithm_01 = 101 - private_experimental_algorithm_02 = 102 - private_experimental_algorithm_03 = 103 - private_experimental_algorithm_04 = 104 - private_experimental_algorithm_05 = 105 - private_experimental_algorithm_06 = 106 - private_experimental_algorithm_07 = 107 - private_experimental_algorithm_08 = 108 - private_experimental_algorithm_09 = 109 - private_experimental_algorithm_10 = 110 - - class ServerFlags(Enum): - no_modify = 128 - - class KeyFlags(Enum): - this_key_may_be_used_to_certify_other_keys = 1 - this_key_may_be_used_to_sign_data = 2 - this_key_may_be_used_to_encrypt_communications = 4 - this_key_may_be_used_to_encrypt_storage = 8 - the_private_component_of_this_key_may_have_been_split_by_a_secret_sharing_mechanism = 16 - this_key_may_be_used_for_authentication = 32 - the_private_component_of_this_key_may_be_in_the_possession_of_more_than_one_person = 128 - - class CompressionAlgorithms(Enum): - uncompressed = 0 - zib = 1 - zlib = 2 - bzip = 3 - private_experimental_algorithm_00 = 100 - private_experimental_algorithm_01 = 101 - private_experimental_algorithm_02 = 102 - private_experimental_algorithm_03 = 103 - private_experimental_algorithm_04 = 104 - private_experimental_algorithm_05 = 105 - private_experimental_algorithm_06 = 106 - private_experimental_algorithm_07 = 107 - private_experimental_algorithm_08 = 108 - private_experimental_algorithm_09 = 109 - private_experimental_algorithm_10 = 110 - - class PacketTags(Enum): - reserved_a_packet_tag_must_not_have_this_value = 0 - public_key_encrypted_session_key_packet = 1 - signature_packet = 2 - symmetric_key_encrypted_session_key_packet = 3 - one_pass_signature_packet = 4 - secret_key_packet = 5 - public_key_packet = 6 - secret_subkey_packet = 7 - compressed_data_packet = 8 - symmetrically_encrypted_data_packet = 9 - marker_packet = 10 - literal_data_packet = 11 - trust_packet = 12 - user_id_packet = 13 - public_subkey_packet = 14 - user_attribute_packet = 17 - sym_encrypted_and_integrity_protected_data_packet = 18 - modification_detection_code_packet = 19 - private_or_experimental_values_0 = 60 - private_or_experimental_values_1 = 61 - private_or_experimental_values_2 = 62 - private_or_experimental_values_3 = 63 - - class RevocationCodes(Enum): - no_reason_specified_key_revocations_or_cert_revocations = 0 - key_is_superseded_key_revocations = 1 - key_material_has_been_compromised_key_revocations = 2 - key_is_retired_and_no_longer_used_key_revocations = 3 - user_id_information_is_no_longer_valid_cert_revocations = 32 - private_use_1 = 100 - private_use_2 = 101 - private_use_3 = 102 - private_use_4 = 103 - private_use_11 = 110 - - class HashAlgorithms(Enum): - md5 = 1 - sha1 = 2 - ripemd160 = 3 - reserved_4 = 4 - reserved_5 = 5 - reserved_6 = 6 - reserved_7 = 7 - sha256 = 8 - sha384 = 9 - sha512 = 10 - sha224 = 11 - private_experimental_algorithm_00 = 100 - private_experimental_algorithm_01 = 101 - private_experimental_algorithm_02 = 102 - private_experimental_algorithm_03 = 103 - private_experimental_algorithm_04 = 104 - private_experimental_algorithm_05 = 105 - private_experimental_algorithm_06 = 106 - private_experimental_algorithm_07 = 107 - private_experimental_algorithm_08 = 108 - private_experimental_algorithm_09 = 109 - private_experimental_algorithm_10 = 110 - - class SymmetricKeyAlgorithm(Enum): - plain = 0 - idea = 1 - triple_des = 2 - cast5 = 3 - blowfisch = 4 - reserved_5 = 5 - reserved_6 = 6 - aes_128 = 7 - aes_192 = 8 - aes_256 = 9 - twofish_256 = 10 - private_experimental_algorithm_00 = 100 - private_experimental_algorithm_01 = 101 - private_experimental_algorithm_02 = 102 - private_experimental_algorithm_03 = 103 - private_experimental_algorithm_04 = 104 - private_experimental_algorithm_05 = 105 - private_experimental_algorithm_06 = 106 - private_experimental_algorithm_07 = 107 - private_experimental_algorithm_08 = 108 - private_experimental_algorithm_09 = 109 - private_experimental_algorithm_10 = 110 - - class SubpacketTypes(Enum): - reserved0 = 0 - reserved1 = 1 - signature_creation_time = 2 - signature_expiration_time = 3 - exportable_certification = 4 - trust_signature = 5 - regular_expression = 6 - revocable = 7 - reserved8 = 8 - key_expiration_time = 9 - placeholder_for_backward_compatibility = 10 - preferred_symmetric_algorithms = 11 - revocation_key = 12 - reserved13 = 13 - reserved14 = 14 - reserved15 = 15 - issuer = 16 - reserved17 = 17 - reserved18 = 18 - reserved19 = 19 - notation_data = 20 - preferred_hash_algorithms = 21 - preferred_compression_algorithms = 22 - key_server_preferences = 23 - preferred_key_server = 24 - primary_user_id = 25 - policy_uri = 26 - key_flags = 27 - signers_user_id = 28 - reason_for_revocation = 29 - features = 30 - signature_target = 31 - embedded_signature = 32 - SEQ_FIELDS = ["packets"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['packets']['start'] = self._io.pos() - self.packets = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['packets']: - self._debug['packets']['arr'] = [] - self._debug['packets']['arr'].append({'start': self._io.pos()}) - _t_packets = self._root.Packet(self._io, self, self._root) - _t_packets._read() - self.packets.append(_t_packets) - self._debug['packets']['arr'][len(self.packets) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['packets']['end'] = self._io.pos() - - class PreferredHashAlgorithms(KaitaiStruct): - SEQ_FIELDS = ["algorithm"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['algorithm']['start'] = self._io.pos() - self.algorithm = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['algorithm']: - self._debug['algorithm']['arr'] = [] - self._debug['algorithm']['arr'].append({'start': self._io.pos()}) - self.algorithm.append(KaitaiStream.resolve_enum(self._root.HashAlgorithms, self._io.read_u1())) - self._debug['algorithm']['arr'][len(self.algorithm) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['algorithm']['end'] = self._io.pos() - - - class PreferredCompressionAlgorithms(KaitaiStruct): - SEQ_FIELDS = ["algorithm"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['algorithm']['start'] = self._io.pos() - self.algorithm = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['algorithm']: - self._debug['algorithm']['arr'] = [] - self._debug['algorithm']['arr'].append({'start': self._io.pos()}) - self.algorithm.append(KaitaiStream.resolve_enum(self._root.CompressionAlgorithms, self._io.read_u1())) - self._debug['algorithm']['arr'][len(self.algorithm) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['algorithm']['end'] = self._io.pos() - - - class SignersUserId(KaitaiStruct): - SEQ_FIELDS = ["user_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['user_id']['start'] = self._io.pos() - self.user_id = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['user_id']['end'] = self._io.pos() - - - class SecretKeyPacket(KaitaiStruct): - SEQ_FIELDS = ["public_key", "string_to_key", "symmetric_encryption_algorithm", "secret_key"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['public_key']['start'] = self._io.pos() - self.public_key = self._root.PublicKeyPacket(self._io, self, self._root) - self.public_key._read() - self._debug['public_key']['end'] = self._io.pos() - self._debug['string_to_key']['start'] = self._io.pos() - self.string_to_key = self._io.read_u1() - self._debug['string_to_key']['end'] = self._io.pos() - if self.string_to_key >= 254: - self._debug['symmetric_encryption_algorithm']['start'] = self._io.pos() - self.symmetric_encryption_algorithm = KaitaiStream.resolve_enum(self._root.SymmetricKeyAlgorithm, self._io.read_u1()) - self._debug['symmetric_encryption_algorithm']['end'] = self._io.pos() - - self._debug['secret_key']['start'] = self._io.pos() - self.secret_key = self._io.read_bytes_full() - self._debug['secret_key']['end'] = self._io.pos() - - - class KeyServerPreferences(KaitaiStruct): - SEQ_FIELDS = ["flag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag']['start'] = self._io.pos() - self.flag = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['flag']: - self._debug['flag']['arr'] = [] - self._debug['flag']['arr'].append({'start': self._io.pos()}) - self.flag.append(KaitaiStream.resolve_enum(self._root.ServerFlags, self._io.read_u1())) - self._debug['flag']['arr'][len(self.flag) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['flag']['end'] = self._io.pos() - - - class RegularExpression(KaitaiStruct): - SEQ_FIELDS = ["regex"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['regex']['start'] = self._io.pos() - self.regex = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['regex']['end'] = self._io.pos() - - - class Subpackets(KaitaiStruct): - SEQ_FIELDS = ["subpacketss"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['subpacketss']['start'] = self._io.pos() - self.subpacketss = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['subpacketss']: - self._debug['subpacketss']['arr'] = [] - self._debug['subpacketss']['arr'].append({'start': self._io.pos()}) - _t_subpacketss = self._root.Subpacket(self._io, self, self._root) - _t_subpacketss._read() - self.subpacketss.append(_t_subpacketss) - self._debug['subpacketss']['arr'][len(self.subpacketss) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['subpacketss']['end'] = self._io.pos() - - - class RevocationKey(KaitaiStruct): - SEQ_FIELDS = ["class_", "public_key_algorithm", "fingerprint"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['class_']['start'] = self._io.pos() - self.class_ = self._io.read_u1() - self._debug['class_']['end'] = self._io.pos() - self._debug['public_key_algorithm']['start'] = self._io.pos() - self.public_key_algorithm = KaitaiStream.resolve_enum(self._root.PublicKeyAlgorithms, self._io.read_u1()) - self._debug['public_key_algorithm']['end'] = self._io.pos() - self._debug['fingerprint']['start'] = self._io.pos() - self.fingerprint = self._io.read_bytes(20) - self._debug['fingerprint']['end'] = self._io.pos() - - - class UserIdPacket(KaitaiStruct): - SEQ_FIELDS = ["user_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['user_id']['start'] = self._io.pos() - self.user_id = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['user_id']['end'] = self._io.pos() - - - class PolicyUri(KaitaiStruct): - SEQ_FIELDS = ["uri"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['uri']['start'] = self._io.pos() - self.uri = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['uri']['end'] = self._io.pos() - - - class SignatureTarget(KaitaiStruct): - SEQ_FIELDS = ["public_key_algorithm", "hash_algorithm", "hash"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['public_key_algorithm']['start'] = self._io.pos() - self.public_key_algorithm = KaitaiStream.resolve_enum(self._root.PublicKeyAlgorithms, self._io.read_u1()) - self._debug['public_key_algorithm']['end'] = self._io.pos() - self._debug['hash_algorithm']['start'] = self._io.pos() - self.hash_algorithm = KaitaiStream.resolve_enum(self._root.HashAlgorithms, self._io.read_u1()) - self._debug['hash_algorithm']['end'] = self._io.pos() - self._debug['hash']['start'] = self._io.pos() - self.hash = self._io.read_bytes_full() - self._debug['hash']['end'] = self._io.pos() - - - class KeyFlags(KaitaiStruct): - SEQ_FIELDS = ["flag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flag']['start'] = self._io.pos() - self.flag = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['flag']: - self._debug['flag']['arr'] = [] - self._debug['flag']['arr'].append({'start': self._io.pos()}) - self.flag.append(KaitaiStream.resolve_enum(self._root.KeyFlags, self._io.read_u1())) - self._debug['flag']['arr'][len(self.flag) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['flag']['end'] = self._io.pos() - - - class Features(KaitaiStruct): - SEQ_FIELDS = ["flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes_full() - self._debug['flags']['end'] = self._io.pos() - - - class PrimaryUserId(KaitaiStruct): - SEQ_FIELDS = ["user_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['user_id']['start'] = self._io.pos() - self.user_id = self._io.read_u1() - self._debug['user_id']['end'] = self._io.pos() - - - class Subpacket(KaitaiStruct): - SEQ_FIELDS = ["len", "subpacket_type", "content"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.PreferredKeyServer(io, self, self._root) - self.content._read() - elif _on == self._root.SubpacketTypes.issuer: - self._raw_content = self._io.read_bytes((self.len.len - 1)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.Issuer(io, self, self._root) - self.content._read() - elif _on == self._root.SubpacketTypes.revocable: - self._raw_content = self._io.read_bytes((self.len.len - 1)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.Revocable(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.SignatureTarget(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.RegularExpression(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.ExportableCertification(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.ReasonForRevocation(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.KeyServerPreferences(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.SignatureCreationTime(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.PreferredHashAlgorithms(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.TrustSignature(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.KeyExpirationTime(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.KeyFlags(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.SignatureExpirationTime(io, self, self._root) - self.content._read() - elif _on == self._root.SubpacketTypes.features: - self._raw_content = self._io.read_bytes((self.len.len - 1)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.Features(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.SignersUserId(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.NotationData(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.RevocationKey(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.PreferredCompressionAlgorithms(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.PolicyUri(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.PrimaryUserId(io, 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 = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.EmbeddedSignature(io, self, self._root) - self.content._read() - else: - self.content = self._io.read_bytes((self.len.len - 1)) - self._debug['content']['end'] = self._io.pos() - - - class OldPacket(KaitaiStruct): - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - _on = self._parent.len_type - if _on == 0: - self.len = self._io.read_u1() - elif _on == 1: - self.len = self._io.read_u2be() - elif _on == 2: - self.len = self._io.read_u4be() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self._parent.packet_type_old - if _on == self._root.PacketTags.public_key_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PublicKeyPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PacketTags.public_subkey_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PublicKeyPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PacketTags.user_id_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.UserIdPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PacketTags.signature_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SignaturePacket(io, self, self._root) - self.body._read() - elif _on == self._root.PacketTags.secret_subkey_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PublicKeyPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PacketTags.secret_key_packet: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SecretKeyPacket(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.len) - self._debug['body']['end'] = self._io.pos() - - - class Issuer(KaitaiStruct): - SEQ_FIELDS = ["keyid"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['keyid']['start'] = self._io.pos() - self.keyid = self._io.read_u8be() - self._debug['keyid']['end'] = self._io.pos() - - - class ExportableCertification(KaitaiStruct): - SEQ_FIELDS = ["exportable"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['exportable']['start'] = self._io.pos() - self.exportable = self._io.read_u1() - self._debug['exportable']['end'] = self._io.pos() - - - class SignatureExpirationTime(KaitaiStruct): - SEQ_FIELDS = ["time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['time']['start'] = self._io.pos() - self.time = self._io.read_u4be() - self._debug['time']['end'] = self._io.pos() - - - class SignatureCreationTime(KaitaiStruct): - SEQ_FIELDS = ["time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['time']['start'] = self._io.pos() - self.time = self._io.read_u4be() - self._debug['time']['end'] = self._io.pos() - - - class SignaturePacket(KaitaiStruct): - SEQ_FIELDS = ["version", "signature_type", "public_key_algorithm", "hash_algorithm", "len_hashed_subpacket", "hashed_subpackets", "len_unhashed_subpacket", "unhashed_subpackets", "left_signed_hash", "rsa_n", "signature"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['signature_type']['start'] = self._io.pos() - self.signature_type = self._io.read_u1() - self._debug['signature_type']['end'] = self._io.pos() - self._debug['public_key_algorithm']['start'] = self._io.pos() - self.public_key_algorithm = KaitaiStream.resolve_enum(self._root.PublicKeyAlgorithms, self._io.read_u1()) - self._debug['public_key_algorithm']['end'] = self._io.pos() - self._debug['hash_algorithm']['start'] = self._io.pos() - self.hash_algorithm = KaitaiStream.resolve_enum(self._root.HashAlgorithms, self._io.read_u1()) - self._debug['hash_algorithm']['end'] = self._io.pos() - self._debug['len_hashed_subpacket']['start'] = self._io.pos() - self.len_hashed_subpacket = self._io.read_u2be() - self._debug['len_hashed_subpacket']['end'] = self._io.pos() - self._debug['hashed_subpackets']['start'] = self._io.pos() - self._raw_hashed_subpackets = self._io.read_bytes(self.len_hashed_subpacket) - io = KaitaiStream(BytesIO(self._raw_hashed_subpackets)) - self.hashed_subpackets = self._root.Subpackets(io, self, self._root) - self.hashed_subpackets._read() - self._debug['hashed_subpackets']['end'] = self._io.pos() - self._debug['len_unhashed_subpacket']['start'] = self._io.pos() - self.len_unhashed_subpacket = self._io.read_u2be() - self._debug['len_unhashed_subpacket']['end'] = self._io.pos() - self._debug['unhashed_subpackets']['start'] = self._io.pos() - self._raw_unhashed_subpackets = self._io.read_bytes(self.len_unhashed_subpacket) - io = KaitaiStream(BytesIO(self._raw_unhashed_subpackets)) - self.unhashed_subpackets = self._root.Subpackets(io, self, self._root) - self.unhashed_subpackets._read() - self._debug['unhashed_subpackets']['end'] = self._io.pos() - self._debug['left_signed_hash']['start'] = self._io.pos() - self.left_signed_hash = self._io.read_u2be() - self._debug['left_signed_hash']['end'] = self._io.pos() - self._debug['rsa_n']['start'] = self._io.pos() - self.rsa_n = self._io.read_u2be() - self._debug['rsa_n']['end'] = self._io.pos() - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.read_bytes_full() - self._debug['signature']['end'] = self._io.pos() - - - class Revocable(KaitaiStruct): - SEQ_FIELDS = ["revocable"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['revocable']['start'] = self._io.pos() - self.revocable = self._io.read_u1() - self._debug['revocable']['end'] = self._io.pos() - - - class EmbeddedSignature(KaitaiStruct): - SEQ_FIELDS = ["signature_packet"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature_packet']['start'] = self._io.pos() - self.signature_packet = self._root.SignaturePacket(self._io, self, self._root) - self.signature_packet._read() - self._debug['signature_packet']['end'] = self._io.pos() - - - class PreferredKeyServer(KaitaiStruct): - SEQ_FIELDS = ["uri"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['uri']['start'] = self._io.pos() - self.uri = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['uri']['end'] = self._io.pos() - - - class ReasonForRevocation(KaitaiStruct): - SEQ_FIELDS = ["revocation_code", "reason"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['revocation_code']['start'] = self._io.pos() - self.revocation_code = KaitaiStream.resolve_enum(self._root.RevocationCodes, self._io.read_u1()) - self._debug['revocation_code']['end'] = self._io.pos() - self._debug['reason']['start'] = self._io.pos() - self.reason = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['reason']['end'] = self._io.pos() - - - class LenSubpacket(KaitaiStruct): - SEQ_FIELDS = ["first_octet", "second_octet", "scalar"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['first_octet']['start'] = self._io.pos() - self.first_octet = self._io.read_u1() - self._debug['first_octet']['end'] = self._io.pos() - if ((self.first_octet >= 192) and (self.first_octet < 255)) : - self._debug['second_octet']['start'] = self._io.pos() - self.second_octet = self._io.read_u1() - self._debug['second_octet']['end'] = self._io.pos() - - if self.first_octet == 255: - self._debug['scalar']['start'] = self._io.pos() - self.scalar = self._io.read_u4be() - self._debug['scalar']['end'] = self._io.pos() - - - @property - def len(self): - if hasattr(self, '_m_len'): - return self._m_len if hasattr(self, '_m_len') else None - - self._m_len = (self.first_octet if self.first_octet < 192 else (((((self.first_octet - 192) << 8) + self.second_octet) + 192) if ((self.first_octet >= 192) and (self.first_octet < 255)) else self.scalar)) - return self._m_len if hasattr(self, '_m_len') else None - - - class NotationData(KaitaiStruct): - SEQ_FIELDS = ["flags", "len_name", "len_value", "name", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes(4) - self._debug['flags']['end'] = self._io.pos() - self._debug['len_name']['start'] = self._io.pos() - self.len_name = self._io.read_u2be() - self._debug['len_name']['end'] = self._io.pos() - self._debug['len_value']['start'] = self._io.pos() - self.len_value = self._io.read_u2be() - self._debug['len_value']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = self._io.read_bytes(self.len_name) - self._debug['name']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.len_value) - self._debug['value']['end'] = self._io.pos() - - - class PublicKeyPacket(KaitaiStruct): - SEQ_FIELDS = ["version", "timestamp", "public_key_algorithm", "len_alg", "rsa_n", "padding", "rsa_e"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4be() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['public_key_algorithm']['start'] = self._io.pos() - self.public_key_algorithm = KaitaiStream.resolve_enum(self._root.PublicKeyAlgorithms, self._io.read_u1()) - self._debug['public_key_algorithm']['end'] = self._io.pos() - self._debug['len_alg']['start'] = self._io.pos() - self.len_alg = self._io.read_u2be() - self._debug['len_alg']['end'] = self._io.pos() - self._debug['rsa_n']['start'] = self._io.pos() - self.rsa_n = self._io.read_bytes(self.len_alg // 8) - self._debug['rsa_n']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_u2be() - self._debug['padding']['end'] = self._io.pos() - self._debug['rsa_e']['start'] = self._io.pos() - self.rsa_e = self._io.read_bytes(3) - self._debug['rsa_e']['end'] = self._io.pos() - - - class KeyExpirationTime(KaitaiStruct): - SEQ_FIELDS = ["time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['time']['start'] = self._io.pos() - self.time = self._io.read_u4be() - self._debug['time']['end'] = self._io.pos() - - - class Packet(KaitaiStruct): - SEQ_FIELDS = ["one", "new_packet_format", "packet_type_new", "packet_type_old", "len_type", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['one']['start'] = self._io.pos() - self.one = self._io.read_bits_int(1) != 0 - self._debug['one']['end'] = self._io.pos() - self._debug['new_packet_format']['start'] = self._io.pos() - self.new_packet_format = self._io.read_bits_int(1) != 0 - self._debug['new_packet_format']['end'] = self._io.pos() - if self.new_packet_format: - self._debug['packet_type_new']['start'] = self._io.pos() - self.packet_type_new = KaitaiStream.resolve_enum(self._root.PacketTags, self._io.read_bits_int(6)) - self._debug['packet_type_new']['end'] = self._io.pos() - - if not (self.new_packet_format): - self._debug['packet_type_old']['start'] = self._io.pos() - self.packet_type_old = KaitaiStream.resolve_enum(self._root.PacketTags, self._io.read_bits_int(4)) - self._debug['packet_type_old']['end'] = self._io.pos() - - if not (self.new_packet_format): - self._debug['len_type']['start'] = self._io.pos() - self.len_type = self._io.read_bits_int(2) - self._debug['len_type']['end'] = self._io.pos() - - self._io.align_to_byte() - self._debug['body']['start'] = self._io.pos() - _on = self.new_packet_format - if _on == False: - self.body = self._root.OldPacket(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class TrustSignature(KaitaiStruct): - SEQ_FIELDS = ["level", "amount"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['level']['start'] = self._io.pos() - self.level = self._io.read_u1() - self._debug['level']['end'] = self._io.pos() - self._debug['amount']['start'] = self._io.pos() - self.amount = self._io.read_u1() - self._debug['amount']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/packet_ppi.py b/python/examples/kaitai/packet_ppi.py deleted file mode 100644 index c281f784..00000000 --- a/python/examples/kaitai/packet_ppi.py +++ /dev/null @@ -1,513 +0,0 @@ -# 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 -import collections - - -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)) - -from . import ethernet_frame -class PacketPpi(KaitaiStruct): - """PPI is a standard for link layer packet encapsulation, proposed as - generic extensible container to store both captured in-band data and - out-of-band data. Originally it was developed to provide 802.11n - radio information, but can be used for other purposes as well. - - Sample capture: https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=Http.cap - - .. seealso:: - PPI header format spec, section 3 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - - class PfhType(Enum): - radio_802_11_common = 2 - radio_802_11n_mac_ext = 3 - radio_802_11n_mac_phy_ext = 4 - spectrum_map = 5 - process_info = 6 - capture_info = 7 - - class Linktype(Enum): - null_linktype = 0 - ethernet = 1 - ax25 = 3 - ieee802_5 = 6 - arcnet_bsd = 7 - slip = 8 - ppp = 9 - fddi = 10 - ppp_hdlc = 50 - ppp_ether = 51 - atm_rfc1483 = 100 - raw = 101 - c_hdlc = 104 - ieee802_11 = 105 - frelay = 107 - loop = 108 - linux_sll = 113 - ltalk = 114 - pflog = 117 - ieee802_11_prism = 119 - ip_over_fc = 122 - sunatm = 123 - ieee802_11_radiotap = 127 - arcnet_linux = 129 - apple_ip_over_ieee1394 = 138 - mtp2_with_phdr = 139 - mtp2 = 140 - mtp3 = 141 - sccp = 142 - docsis = 143 - linux_irda = 144 - user0 = 147 - user1 = 148 - user2 = 149 - user3 = 150 - user4 = 151 - user5 = 152 - user6 = 153 - user7 = 154 - user8 = 155 - user9 = 156 - user10 = 157 - user11 = 158 - user12 = 159 - user13 = 160 - user14 = 161 - user15 = 162 - ieee802_11_avs = 163 - bacnet_ms_tp = 165 - ppp_pppd = 166 - gprs_llc = 169 - gpf_t = 170 - gpf_f = 171 - linux_lapd = 177 - bluetooth_hci_h4 = 187 - usb_linux = 189 - ppi = 192 - ieee802_15_4 = 195 - sita = 196 - erf = 197 - bluetooth_hci_h4_with_phdr = 201 - ax25_kiss = 202 - lapd = 203 - ppp_with_dir = 204 - c_hdlc_with_dir = 205 - frelay_with_dir = 206 - ipmb_linux = 209 - ieee802_15_4_nonask_phy = 215 - usb_linux_mmapped = 220 - fc_2 = 224 - fc_2_with_frame_delims = 225 - ipnet = 226 - can_socketcan = 227 - ipv4 = 228 - ipv6 = 229 - ieee802_15_4_nofcs = 230 - dbus = 231 - dvb_ci = 235 - mux27010 = 236 - stanag_5066_d_pdu = 237 - nflog = 239 - netanalyzer = 240 - netanalyzer_transparent = 241 - ipoib = 242 - mpeg_2_ts = 243 - ng40 = 244 - nfc_llcp = 245 - infiniband = 247 - sctp = 248 - usbpcap = 249 - rtac_serial = 250 - bluetooth_le_ll = 251 - netlink = 253 - bluetooth_linux_monitor = 254 - bluetooth_bredr_bb = 255 - bluetooth_le_ll_with_phdr = 256 - profibus_dl = 257 - pktap = 258 - epon = 259 - ipmi_hpm_2 = 260 - zwave_r1_r2 = 261 - zwave_r3 = 262 - wattstopper_dlm = 263 - iso_14443 = 264 - SEQ_FIELDS = ["header", "fields", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.PacketPpiHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['fields']['start'] = self._io.pos() - self._raw_fields = self._io.read_bytes((self.header.pph_len - 8)) - io = KaitaiStream(BytesIO(self._raw_fields)) - self.fields = self._root.PacketPpiFields(io, self, self._root) - self.fields._read() - self._debug['fields']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.header.pph_dlt - if _on == self._root.Linktype.ppi: - self._raw_body = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = PacketPpi(io) - self.body._read() - elif _on == self._root.Linktype.ethernet: - self._raw_body = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = ethernet_frame.EthernetFrame(io) - self.body._read() - else: - self.body = self._io.read_bytes_full() - self._debug['body']['end'] = self._io.pos() - - class PacketPpiFields(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.PacketPpiField(self._io, self, self._root) - _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() - - - class Radio80211nMacExtBody(KaitaiStruct): - """ - .. seealso:: - PPI header format spec, section 4.1.3 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - SEQ_FIELDS = ["flags", "a_mpdu_id", "num_delimiters", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.MacFlags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['a_mpdu_id']['start'] = self._io.pos() - self.a_mpdu_id = self._io.read_u4le() - self._debug['a_mpdu_id']['end'] = self._io.pos() - self._debug['num_delimiters']['start'] = self._io.pos() - self.num_delimiters = self._io.read_u1() - self._debug['num_delimiters']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(3) - self._debug['reserved']['end'] = self._io.pos() - - - class MacFlags(KaitaiStruct): - SEQ_FIELDS = ["unused1", "aggregate_delimiter", "more_aggregates", "aggregate", "dup_rx", "rx_short_guard", "is_ht_40", "greenfield", "unused2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unused1']['start'] = self._io.pos() - self.unused1 = self._io.read_bits_int(1) != 0 - self._debug['unused1']['end'] = self._io.pos() - self._debug['aggregate_delimiter']['start'] = self._io.pos() - self.aggregate_delimiter = self._io.read_bits_int(1) != 0 - self._debug['aggregate_delimiter']['end'] = self._io.pos() - self._debug['more_aggregates']['start'] = self._io.pos() - self.more_aggregates = self._io.read_bits_int(1) != 0 - self._debug['more_aggregates']['end'] = self._io.pos() - self._debug['aggregate']['start'] = self._io.pos() - self.aggregate = self._io.read_bits_int(1) != 0 - self._debug['aggregate']['end'] = self._io.pos() - self._debug['dup_rx']['start'] = self._io.pos() - self.dup_rx = self._io.read_bits_int(1) != 0 - self._debug['dup_rx']['end'] = self._io.pos() - self._debug['rx_short_guard']['start'] = self._io.pos() - self.rx_short_guard = self._io.read_bits_int(1) != 0 - self._debug['rx_short_guard']['end'] = self._io.pos() - self._debug['is_ht_40']['start'] = self._io.pos() - self.is_ht_40 = self._io.read_bits_int(1) != 0 - self._debug['is_ht_40']['end'] = self._io.pos() - self._debug['greenfield']['start'] = self._io.pos() - self.greenfield = self._io.read_bits_int(1) != 0 - self._debug['greenfield']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['unused2']['start'] = self._io.pos() - self.unused2 = self._io.read_bytes(3) - self._debug['unused2']['end'] = self._io.pos() - - - class PacketPpiHeader(KaitaiStruct): - """ - .. seealso:: - PPI header format spec, section 3.1 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - SEQ_FIELDS = ["pph_version", "pph_flags", "pph_len", "pph_dlt"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pph_version']['start'] = self._io.pos() - self.pph_version = self._io.read_u1() - self._debug['pph_version']['end'] = self._io.pos() - self._debug['pph_flags']['start'] = self._io.pos() - self.pph_flags = self._io.read_u1() - self._debug['pph_flags']['end'] = self._io.pos() - self._debug['pph_len']['start'] = self._io.pos() - self.pph_len = self._io.read_u2le() - self._debug['pph_len']['end'] = self._io.pos() - self._debug['pph_dlt']['start'] = self._io.pos() - self.pph_dlt = KaitaiStream.resolve_enum(self._root.Linktype, self._io.read_u4le()) - self._debug['pph_dlt']['end'] = self._io.pos() - - - class Radio80211CommonBody(KaitaiStruct): - """ - .. seealso:: - PPI header format spec, section 4.1.2 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - SEQ_FIELDS = ["tsf_timer", "flags", "rate", "channel_freq", "channel_flags", "fhss_hopset", "fhss_pattern", "dbm_antsignal", "dbm_antnoise"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tsf_timer']['start'] = self._io.pos() - self.tsf_timer = self._io.read_u8le() - self._debug['tsf_timer']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['rate']['start'] = self._io.pos() - self.rate = self._io.read_u2le() - self._debug['rate']['end'] = self._io.pos() - self._debug['channel_freq']['start'] = self._io.pos() - self.channel_freq = self._io.read_u2le() - self._debug['channel_freq']['end'] = self._io.pos() - self._debug['channel_flags']['start'] = self._io.pos() - self.channel_flags = self._io.read_u2le() - self._debug['channel_flags']['end'] = self._io.pos() - self._debug['fhss_hopset']['start'] = self._io.pos() - self.fhss_hopset = self._io.read_u1() - self._debug['fhss_hopset']['end'] = self._io.pos() - self._debug['fhss_pattern']['start'] = self._io.pos() - self.fhss_pattern = self._io.read_u1() - self._debug['fhss_pattern']['end'] = self._io.pos() - self._debug['dbm_antsignal']['start'] = self._io.pos() - self.dbm_antsignal = self._io.read_s1() - self._debug['dbm_antsignal']['end'] = self._io.pos() - self._debug['dbm_antnoise']['start'] = self._io.pos() - self.dbm_antnoise = self._io.read_s1() - self._debug['dbm_antnoise']['end'] = self._io.pos() - - - class PacketPpiField(KaitaiStruct): - """ - .. seealso:: - PPI header format spec, section 3.1 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - SEQ_FIELDS = ["pfh_type", "pfh_datalen", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pfh_type']['start'] = self._io.pos() - self.pfh_type = KaitaiStream.resolve_enum(self._root.PfhType, self._io.read_u2le()) - self._debug['pfh_type']['end'] = self._io.pos() - self._debug['pfh_datalen']['start'] = self._io.pos() - self.pfh_datalen = self._io.read_u2le() - self._debug['pfh_datalen']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.pfh_type - if _on == self._root.PfhType.radio_802_11_common: - self._raw_body = self._io.read_bytes(self.pfh_datalen) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.Radio80211CommonBody(io, self, self._root) - self.body._read() - elif _on == self._root.PfhType.radio_802_11n_mac_ext: - self._raw_body = self._io.read_bytes(self.pfh_datalen) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.Radio80211nMacExtBody(io, self, self._root) - self.body._read() - elif _on == self._root.PfhType.radio_802_11n_mac_phy_ext: - self._raw_body = self._io.read_bytes(self.pfh_datalen) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.Radio80211nMacPhyExtBody(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.pfh_datalen) - self._debug['body']['end'] = self._io.pos() - - - class Radio80211nMacPhyExtBody(KaitaiStruct): - """ - .. seealso:: - PPI header format spec, section 4.1.4 - https://www.cacetech.com/documents/PPI_Header_format_1.0.1.pdf - """ - SEQ_FIELDS = ["flags", "a_mpdu_id", "num_delimiters", "mcs", "num_streams", "rssi_combined", "rssi_ant_ctl", "rssi_ant_ext", "ext_channel_freq", "ext_channel_flags", "rf_signal_noise", "evm"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.MacFlags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['a_mpdu_id']['start'] = self._io.pos() - self.a_mpdu_id = self._io.read_u4le() - self._debug['a_mpdu_id']['end'] = self._io.pos() - self._debug['num_delimiters']['start'] = self._io.pos() - self.num_delimiters = self._io.read_u1() - self._debug['num_delimiters']['end'] = self._io.pos() - self._debug['mcs']['start'] = self._io.pos() - self.mcs = self._io.read_u1() - self._debug['mcs']['end'] = self._io.pos() - self._debug['num_streams']['start'] = self._io.pos() - self.num_streams = self._io.read_u1() - self._debug['num_streams']['end'] = self._io.pos() - self._debug['rssi_combined']['start'] = self._io.pos() - self.rssi_combined = self._io.read_u1() - self._debug['rssi_combined']['end'] = self._io.pos() - self._debug['rssi_ant_ctl']['start'] = self._io.pos() - self.rssi_ant_ctl = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['rssi_ant_ctl']: - self._debug['rssi_ant_ctl']['arr'] = [] - self._debug['rssi_ant_ctl']['arr'].append({'start': self._io.pos()}) - self.rssi_ant_ctl[i] = self._io.read_u1() - self._debug['rssi_ant_ctl']['arr'][i]['end'] = self._io.pos() - - self._debug['rssi_ant_ctl']['end'] = self._io.pos() - self._debug['rssi_ant_ext']['start'] = self._io.pos() - self.rssi_ant_ext = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['rssi_ant_ext']: - self._debug['rssi_ant_ext']['arr'] = [] - self._debug['rssi_ant_ext']['arr'].append({'start': self._io.pos()}) - self.rssi_ant_ext[i] = self._io.read_u1() - self._debug['rssi_ant_ext']['arr'][i]['end'] = self._io.pos() - - self._debug['rssi_ant_ext']['end'] = self._io.pos() - self._debug['ext_channel_freq']['start'] = self._io.pos() - self.ext_channel_freq = self._io.read_u2le() - self._debug['ext_channel_freq']['end'] = self._io.pos() - self._debug['ext_channel_flags']['start'] = self._io.pos() - self.ext_channel_flags = self._root.Radio80211nMacPhyExtBody.ChannelFlags(self._io, self, self._root) - self.ext_channel_flags._read() - self._debug['ext_channel_flags']['end'] = self._io.pos() - self._debug['rf_signal_noise']['start'] = self._io.pos() - self.rf_signal_noise = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['rf_signal_noise']: - self._debug['rf_signal_noise']['arr'] = [] - self._debug['rf_signal_noise']['arr'].append({'start': self._io.pos()}) - _t_rf_signal_noise = self._root.Radio80211nMacPhyExtBody.SignalNoise(self._io, self, self._root) - _t_rf_signal_noise._read() - self.rf_signal_noise[i] = _t_rf_signal_noise - self._debug['rf_signal_noise']['arr'][i]['end'] = self._io.pos() - - self._debug['rf_signal_noise']['end'] = self._io.pos() - self._debug['evm']['start'] = self._io.pos() - self.evm = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['evm']: - self._debug['evm']['arr'] = [] - self._debug['evm']['arr'].append({'start': self._io.pos()}) - self.evm[i] = self._io.read_u4le() - self._debug['evm']['arr'][i]['end'] = self._io.pos() - - self._debug['evm']['end'] = self._io.pos() - - class ChannelFlags(KaitaiStruct): - SEQ_FIELDS = ["spectrum_2ghz", "ofdm", "cck", "turbo", "unused", "gfsk", "dyn_cck_ofdm", "only_passive_scan", "spectrum_5ghz"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['spectrum_2ghz']['start'] = self._io.pos() - self.spectrum_2ghz = self._io.read_bits_int(1) != 0 - self._debug['spectrum_2ghz']['end'] = self._io.pos() - self._debug['ofdm']['start'] = self._io.pos() - self.ofdm = self._io.read_bits_int(1) != 0 - self._debug['ofdm']['end'] = self._io.pos() - self._debug['cck']['start'] = self._io.pos() - self.cck = self._io.read_bits_int(1) != 0 - self._debug['cck']['end'] = self._io.pos() - self._debug['turbo']['start'] = self._io.pos() - self.turbo = self._io.read_bits_int(1) != 0 - self._debug['turbo']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_bits_int(8) - self._debug['unused']['end'] = self._io.pos() - self._debug['gfsk']['start'] = self._io.pos() - self.gfsk = self._io.read_bits_int(1) != 0 - self._debug['gfsk']['end'] = self._io.pos() - self._debug['dyn_cck_ofdm']['start'] = self._io.pos() - self.dyn_cck_ofdm = self._io.read_bits_int(1) != 0 - self._debug['dyn_cck_ofdm']['end'] = self._io.pos() - self._debug['only_passive_scan']['start'] = self._io.pos() - self.only_passive_scan = self._io.read_bits_int(1) != 0 - self._debug['only_passive_scan']['end'] = self._io.pos() - self._debug['spectrum_5ghz']['start'] = self._io.pos() - self.spectrum_5ghz = self._io.read_bits_int(1) != 0 - self._debug['spectrum_5ghz']['end'] = self._io.pos() - - - class SignalNoise(KaitaiStruct): - """RF signal + noise pair at a single antenna.""" - SEQ_FIELDS = ["signal", "noise"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signal']['start'] = self._io.pos() - self.signal = self._io.read_s1() - self._debug['signal']['end'] = self._io.pos() - self._debug['noise']['start'] = self._io.pos() - self.noise = self._io.read_s1() - self._debug['noise']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/pcap.py b/python/examples/kaitai/pcap.py deleted file mode 100644 index 80dc1d60..00000000 --- a/python/examples/kaitai/pcap.py +++ /dev/null @@ -1,234 +0,0 @@ -# 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 -import collections - - -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)) - -from . import ethernet_frame -from . import packet_ppi -class Pcap(KaitaiStruct): - """PCAP (named after libpcap / winpcap) is a popular format for saving - network traffic grabbed by network sniffers. It is typically - produced by tools like [tcpdump](https://www.tcpdump.org/) or - [Wireshark](https://www.wireshark.org/). - - .. seealso:: - Source - http://wiki.wireshark.org/Development/LibpcapFileFormat - """ - - class Linktype(Enum): - null_linktype = 0 - ethernet = 1 - ax25 = 3 - ieee802_5 = 6 - arcnet_bsd = 7 - slip = 8 - ppp = 9 - fddi = 10 - ppp_hdlc = 50 - ppp_ether = 51 - atm_rfc1483 = 100 - raw = 101 - c_hdlc = 104 - ieee802_11 = 105 - frelay = 107 - loop = 108 - linux_sll = 113 - ltalk = 114 - pflog = 117 - ieee802_11_prism = 119 - ip_over_fc = 122 - sunatm = 123 - ieee802_11_radiotap = 127 - arcnet_linux = 129 - apple_ip_over_ieee1394 = 138 - mtp2_with_phdr = 139 - mtp2 = 140 - mtp3 = 141 - sccp = 142 - docsis = 143 - linux_irda = 144 - user0 = 147 - user1 = 148 - user2 = 149 - user3 = 150 - user4 = 151 - user5 = 152 - user6 = 153 - user7 = 154 - user8 = 155 - user9 = 156 - user10 = 157 - user11 = 158 - user12 = 159 - user13 = 160 - user14 = 161 - user15 = 162 - ieee802_11_avs = 163 - bacnet_ms_tp = 165 - ppp_pppd = 166 - gprs_llc = 169 - gpf_t = 170 - gpf_f = 171 - linux_lapd = 177 - bluetooth_hci_h4 = 187 - usb_linux = 189 - ppi = 192 - ieee802_15_4 = 195 - sita = 196 - erf = 197 - bluetooth_hci_h4_with_phdr = 201 - ax25_kiss = 202 - lapd = 203 - ppp_with_dir = 204 - c_hdlc_with_dir = 205 - frelay_with_dir = 206 - ipmb_linux = 209 - ieee802_15_4_nonask_phy = 215 - usb_linux_mmapped = 220 - fc_2 = 224 - fc_2_with_frame_delims = 225 - ipnet = 226 - can_socketcan = 227 - ipv4 = 228 - ipv6 = 229 - ieee802_15_4_nofcs = 230 - dbus = 231 - dvb_ci = 235 - mux27010 = 236 - stanag_5066_d_pdu = 237 - nflog = 239 - netanalyzer = 240 - netanalyzer_transparent = 241 - ipoib = 242 - mpeg_2_ts = 243 - ng40 = 244 - nfc_llcp = 245 - infiniband = 247 - sctp = 248 - usbpcap = 249 - rtac_serial = 250 - bluetooth_le_ll = 251 - netlink = 253 - bluetooth_linux_monitor = 254 - bluetooth_bredr_bb = 255 - bluetooth_le_ll_with_phdr = 256 - profibus_dl = 257 - pktap = 258 - epon = 259 - ipmi_hpm_2 = 260 - zwave_r1_r2 = 261 - zwave_r3 = 262 - wattstopper_dlm = 263 - iso_14443 = 264 - SEQ_FIELDS = ["hdr", "packets"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hdr']['start'] = self._io.pos() - self.hdr = self._root.Header(self._io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - self._debug['packets']['start'] = self._io.pos() - self.packets = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['packets']: - self._debug['packets']['arr'] = [] - self._debug['packets']['arr'].append({'start': self._io.pos()}) - _t_packets = self._root.Packet(self._io, self, self._root) - _t_packets._read() - self.packets.append(_t_packets) - self._debug['packets']['arr'][len(self.packets) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['packets']['end'] = self._io.pos() - - class Header(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header - """ - SEQ_FIELDS = ["magic_number", "version_major", "version_minor", "thiszone", "sigfigs", "snaplen", "network"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic_number']['start'] = self._io.pos() - self.magic_number = self._io.ensure_fixed_contents(b"\xD4\xC3\xB2\xA1") - self._debug['magic_number']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u2le() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u2le() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['thiszone']['start'] = self._io.pos() - self.thiszone = self._io.read_s4le() - self._debug['thiszone']['end'] = self._io.pos() - self._debug['sigfigs']['start'] = self._io.pos() - self.sigfigs = self._io.read_u4le() - self._debug['sigfigs']['end'] = self._io.pos() - self._debug['snaplen']['start'] = self._io.pos() - self.snaplen = self._io.read_u4le() - self._debug['snaplen']['end'] = self._io.pos() - self._debug['network']['start'] = self._io.pos() - self.network = KaitaiStream.resolve_enum(self._root.Linktype, self._io.read_u4le()) - self._debug['network']['end'] = self._io.pos() - - - class Packet(KaitaiStruct): - """ - .. seealso:: - Source - https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header - """ - SEQ_FIELDS = ["ts_sec", "ts_usec", "incl_len", "orig_len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ts_sec']['start'] = self._io.pos() - self.ts_sec = self._io.read_u4le() - self._debug['ts_sec']['end'] = self._io.pos() - self._debug['ts_usec']['start'] = self._io.pos() - self.ts_usec = self._io.read_u4le() - self._debug['ts_usec']['end'] = self._io.pos() - self._debug['incl_len']['start'] = self._io.pos() - self.incl_len = self._io.read_u4le() - self._debug['incl_len']['end'] = self._io.pos() - self._debug['orig_len']['start'] = self._io.pos() - self.orig_len = self._io.read_u4le() - self._debug['orig_len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self._root.hdr.network - if _on == self._root.Linktype.ppi: - self._raw_body = self._io.read_bytes(self.incl_len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = packet_ppi.PacketPpi(io) - self.body._read() - elif _on == self._root.Linktype.ethernet: - self._raw_body = self._io.read_bytes(self.incl_len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = ethernet_frame.EthernetFrame(io) - self.body._read() - else: - self.body = self._io.read_bytes(self.incl_len) - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/pcx.py b/python/examples/kaitai/pcx.py deleted file mode 100644 index 2b6123d5..00000000 --- a/python/examples/kaitai/pcx.py +++ /dev/null @@ -1,170 +0,0 @@ -# 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 -import collections - - -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 Pcx(KaitaiStruct): - - class Versions(Enum): - v2_5 = 0 - v2_8_with_palette = 2 - v2_8_without_palette = 3 - paintbrush_for_windows = 4 - v3_0 = 5 - - class Encodings(Enum): - rle = 1 - SEQ_FIELDS = ["hdr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hdr']['start'] = self._io.pos() - self._raw_hdr = self._io.read_bytes(128) - io = KaitaiStream(BytesIO(self._raw_hdr)) - self.hdr = self._root.Header(io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - - class Header(KaitaiStruct): - """ - .. seealso:: - - "ZSoft .PCX FILE HEADER FORMAT" - http://web.archive.org/web/20100206055706/http://www.qzx.com/pc-gpe/pcx.txt - """ - SEQ_FIELDS = ["magic", "version", "encoding", "bits_per_pixel", "img_x_min", "img_y_min", "img_x_max", "img_y_max", "hdpi", "vdpi", "palette_16", "reserved", "num_planes", "bytes_per_line", "palette_info", "h_screen_size", "v_screen_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x0A") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = KaitaiStream.resolve_enum(self._root.Versions, self._io.read_u1()) - self._debug['version']['end'] = self._io.pos() - self._debug['encoding']['start'] = self._io.pos() - self.encoding = KaitaiStream.resolve_enum(self._root.Encodings, self._io.read_u1()) - self._debug['encoding']['end'] = self._io.pos() - self._debug['bits_per_pixel']['start'] = self._io.pos() - self.bits_per_pixel = self._io.read_u1() - self._debug['bits_per_pixel']['end'] = self._io.pos() - self._debug['img_x_min']['start'] = self._io.pos() - self.img_x_min = self._io.read_u2le() - self._debug['img_x_min']['end'] = self._io.pos() - self._debug['img_y_min']['start'] = self._io.pos() - self.img_y_min = self._io.read_u2le() - self._debug['img_y_min']['end'] = self._io.pos() - self._debug['img_x_max']['start'] = self._io.pos() - self.img_x_max = self._io.read_u2le() - self._debug['img_x_max']['end'] = self._io.pos() - self._debug['img_y_max']['start'] = self._io.pos() - self.img_y_max = self._io.read_u2le() - self._debug['img_y_max']['end'] = self._io.pos() - self._debug['hdpi']['start'] = self._io.pos() - self.hdpi = self._io.read_u2le() - self._debug['hdpi']['end'] = self._io.pos() - self._debug['vdpi']['start'] = self._io.pos() - self.vdpi = self._io.read_u2le() - self._debug['vdpi']['end'] = self._io.pos() - self._debug['palette_16']['start'] = self._io.pos() - self.palette_16 = self._io.read_bytes(48) - self._debug['palette_16']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['num_planes']['start'] = self._io.pos() - self.num_planes = self._io.read_u1() - self._debug['num_planes']['end'] = self._io.pos() - self._debug['bytes_per_line']['start'] = self._io.pos() - self.bytes_per_line = self._io.read_u2le() - self._debug['bytes_per_line']['end'] = self._io.pos() - self._debug['palette_info']['start'] = self._io.pos() - self.palette_info = self._io.read_u2le() - self._debug['palette_info']['end'] = self._io.pos() - self._debug['h_screen_size']['start'] = self._io.pos() - self.h_screen_size = self._io.read_u2le() - self._debug['h_screen_size']['end'] = self._io.pos() - self._debug['v_screen_size']['start'] = self._io.pos() - self.v_screen_size = self._io.read_u2le() - self._debug['v_screen_size']['end'] = self._io.pos() - - - class TPalette256(KaitaiStruct): - SEQ_FIELDS = ["magic", "colors"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x0C") - self._debug['magic']['end'] = self._io.pos() - self._debug['colors']['start'] = self._io.pos() - self.colors = [None] * (256) - for i in range(256): - if not 'arr' in self._debug['colors']: - self._debug['colors']['arr'] = [] - self._debug['colors']['arr'].append({'start': self._io.pos()}) - _t_colors = self._root.Rgb(self._io, self, self._root) - _t_colors._read() - self.colors[i] = _t_colors - self._debug['colors']['arr'][i]['end'] = self._io.pos() - - self._debug['colors']['end'] = self._io.pos() - - - class Rgb(KaitaiStruct): - SEQ_FIELDS = ["r", "g", "b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['r']['start'] = self._io.pos() - self.r = self._io.read_u1() - self._debug['r']['end'] = self._io.pos() - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_u1() - self._debug['g']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - - - @property - def palette_256(self): - """ - .. seealso:: - - "VGA 256 Color Palette Information" - http://web.archive.org/web/20100206055706/http://www.qzx.com/pc-gpe/pcx.txt - """ - if hasattr(self, '_m_palette_256'): - return self._m_palette_256 if hasattr(self, '_m_palette_256') else None - - if ((self.hdr.version == self._root.Versions.v3_0) and (self.hdr.bits_per_pixel == 8) and (self.hdr.num_planes == 1)) : - _pos = self._io.pos() - self._io.seek((self._io.size() - 769)) - self._debug['_m_palette_256']['start'] = self._io.pos() - self._m_palette_256 = self._root.TPalette256(self._io, self, self._root) - self._m_palette_256._read() - self._debug['_m_palette_256']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_palette_256 if hasattr(self, '_m_palette_256') else None - - diff --git a/python/examples/kaitai/pcx_dcx.py b/python/examples/kaitai/pcx_dcx.py deleted file mode 100644 index 03ab8ac9..00000000 --- a/python/examples/kaitai/pcx_dcx.py +++ /dev/null @@ -1,76 +0,0 @@ -# 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 -import collections - - -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)) - -from .pcx import Pcx -class PcxDcx(KaitaiStruct): - """DCX is a simple extension of PCX image format allowing to bundle - many PCX images (typically, pages of a document) in one file. It saw - some limited use in DOS-era fax software, but was largely - superseeded with multi-page TIFFs and PDFs since then. - """ - SEQ_FIELDS = ["magic", "files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\xB1\x68\xDE\x3A") - self._debug['magic']['end'] = self._io.pos() - self._debug['files']['start'] = self._io.pos() - self.files = [] - i = 0 - while True: - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.PcxOffset(self._io, self, self._root) - _t_files._read() - _ = _t_files - self.files.append(_) - self._debug['files']['arr'][len(self.files) - 1]['end'] = self._io.pos() - if _.ofs_body == 0: - break - i += 1 - self._debug['files']['end'] = self._io.pos() - - class PcxOffset(KaitaiStruct): - SEQ_FIELDS = ["ofs_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs_body']['start'] = self._io.pos() - self.ofs_body = self._io.read_u4le() - self._debug['ofs_body']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - if self.ofs_body != 0: - _pos = self._io.pos() - self._io.seek(self.ofs_body) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = Pcx(self._io) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_body if hasattr(self, '_m_body') else None - - - diff --git a/python/examples/kaitai/png.py b/python/examples/kaitai/png.py deleted file mode 100644 index 4a494756..00000000 --- a/python/examples/kaitai/png.py +++ /dev/null @@ -1,580 +0,0 @@ -# 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 -import collections -import zlib - - -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 Png(KaitaiStruct): - - class ColorType(Enum): - greyscale = 0 - truecolor = 2 - indexed = 3 - greyscale_alpha = 4 - truecolor_alpha = 6 - - class PhysUnit(Enum): - unknown = 0 - meter = 1 - - class CompressionMethods(Enum): - zlib = 0 - SEQ_FIELDS = ["magic", "ihdr_len", "ihdr_type", "ihdr", "ihdr_crc", "chunks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A") - self._debug['magic']['end'] = self._io.pos() - self._debug['ihdr_len']['start'] = self._io.pos() - self.ihdr_len = self._io.ensure_fixed_contents(b"\x00\x00\x00\x0D") - self._debug['ihdr_len']['end'] = self._io.pos() - self._debug['ihdr_type']['start'] = self._io.pos() - self.ihdr_type = self._io.ensure_fixed_contents(b"\x49\x48\x44\x52") - self._debug['ihdr_type']['end'] = self._io.pos() - self._debug['ihdr']['start'] = self._io.pos() - self.ihdr = self._root.IhdrChunk(self._io, self, self._root) - self.ihdr._read() - self._debug['ihdr']['end'] = self._io.pos() - self._debug['ihdr_crc']['start'] = self._io.pos() - self.ihdr_crc = self._io.read_bytes(4) - self._debug['ihdr_crc']['end'] = self._io.pos() - self._debug['chunks']['start'] = self._io.pos() - self.chunks = [] - i = 0 - while True: - if not 'arr' in self._debug['chunks']: - self._debug['chunks']['arr'] = [] - self._debug['chunks']['arr'].append({'start': self._io.pos()}) - _t_chunks = self._root.Chunk(self._io, self, self._root) - _t_chunks._read() - _ = _t_chunks - self.chunks.append(_) - self._debug['chunks']['arr'][len(self.chunks) - 1]['end'] = self._io.pos() - if ((_.type == u"IEND") or (self._io.is_eof())) : - break - i += 1 - self._debug['chunks']['end'] = self._io.pos() - - class Rgb(KaitaiStruct): - SEQ_FIELDS = ["r", "g", "b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['r']['start'] = self._io.pos() - self.r = self._io.read_u1() - self._debug['r']['end'] = self._io.pos() - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_u1() - self._debug['g']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - - - class Chunk(KaitaiStruct): - SEQ_FIELDS = ["len", "type", "body", "crc"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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 = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.InternationalTextChunk(io, self, self._root) - self.body._read() - elif _on == u"gAMA": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.GamaChunk(io, self, self._root) - self.body._read() - elif _on == u"tIME": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.TimeChunk(io, self, self._root) - self.body._read() - elif _on == u"PLTE": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PlteChunk(io, self, self._root) - self.body._read() - elif _on == u"bKGD": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BkgdChunk(io, self, self._root) - self.body._read() - elif _on == u"pHYs": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PhysChunk(io, self, self._root) - self.body._read() - elif _on == u"tEXt": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.TextChunk(io, self, self._root) - self.body._read() - elif _on == u"cHRM": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ChrmChunk(io, self, self._root) - self.body._read() - elif _on == u"sRGB": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SrgbChunk(io, self, self._root) - self.body._read() - elif _on == u"zTXt": - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CompressedTextChunk(io, 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() - - - class BkgdIndexed(KaitaiStruct): - """Background chunk for images with indexed palette.""" - SEQ_FIELDS = ["palette_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['palette_index']['start'] = self._io.pos() - self.palette_index = self._io.read_u1() - self._debug['palette_index']['end'] = self._io.pos() - - - class Point(KaitaiStruct): - SEQ_FIELDS = ["x_int", "y_int"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x_int']['start'] = self._io.pos() - self.x_int = self._io.read_u4be() - self._debug['x_int']['end'] = self._io.pos() - self._debug['y_int']['start'] = self._io.pos() - self.y_int = self._io.read_u4be() - self._debug['y_int']['end'] = self._io.pos() - - @property - def x(self): - if hasattr(self, '_m_x'): - return self._m_x if hasattr(self, '_m_x') else None - - self._m_x = (self.x_int / 100000.0) - return self._m_x if hasattr(self, '_m_x') else None - - @property - def y(self): - if hasattr(self, '_m_y'): - return self._m_y if hasattr(self, '_m_y') else None - - self._m_y = (self.y_int / 100000.0) - return self._m_y if hasattr(self, '_m_y') else None - - - class BkgdGreyscale(KaitaiStruct): - """Background chunk for greyscale images.""" - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u2be() - self._debug['value']['end'] = self._io.pos() - - - class ChrmChunk(KaitaiStruct): - """ - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11cHRM - """ - SEQ_FIELDS = ["white_point", "red", "green", "blue"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['white_point']['start'] = self._io.pos() - self.white_point = self._root.Point(self._io, self, self._root) - self.white_point._read() - self._debug['white_point']['end'] = self._io.pos() - self._debug['red']['start'] = self._io.pos() - self.red = self._root.Point(self._io, self, self._root) - self.red._read() - self._debug['red']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._root.Point(self._io, self, self._root) - self.green._read() - self._debug['green']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._root.Point(self._io, self, self._root) - self.blue._read() - self._debug['blue']['end'] = self._io.pos() - - - class IhdrChunk(KaitaiStruct): - """ - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11IHDR - """ - SEQ_FIELDS = ["width", "height", "bit_depth", "color_type", "compression_method", "filter_method", "interlace_method"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u4be() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u4be() - self._debug['height']['end'] = self._io.pos() - self._debug['bit_depth']['start'] = self._io.pos() - self.bit_depth = self._io.read_u1() - self._debug['bit_depth']['end'] = self._io.pos() - self._debug['color_type']['start'] = self._io.pos() - self.color_type = KaitaiStream.resolve_enum(self._root.ColorType, self._io.read_u1()) - self._debug['color_type']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = self._io.read_u1() - self._debug['compression_method']['end'] = self._io.pos() - self._debug['filter_method']['start'] = self._io.pos() - self.filter_method = self._io.read_u1() - self._debug['filter_method']['end'] = self._io.pos() - self._debug['interlace_method']['start'] = self._io.pos() - self.interlace_method = self._io.read_u1() - self._debug['interlace_method']['end'] = self._io.pos() - - - class PlteChunk(KaitaiStruct): - """ - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11PLTE - """ - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Rgb(self._io, self, self._root) - _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() - - - class SrgbChunk(KaitaiStruct): - """ - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11sRGB - """ - - class Intent(Enum): - perceptual = 0 - relative_colorimetric = 1 - saturation = 2 - absolute_colorimetric = 3 - SEQ_FIELDS = ["render_intent"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['render_intent']['start'] = self._io.pos() - self.render_intent = KaitaiStream.resolve_enum(self._root.SrgbChunk.Intent, self._io.read_u1()) - self._debug['render_intent']['end'] = self._io.pos() - - - class CompressedTextChunk(KaitaiStruct): - """Compressed text chunk effectively allows to store key-value - string pairs in PNG container, compressing "value" part (which - can be quite lengthy) with zlib compression. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11zTXt - """ - SEQ_FIELDS = ["keyword", "compression_method", "text_datastream"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['keyword']['start'] = self._io.pos() - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['keyword']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.CompressionMethods, self._io.read_u1()) - self._debug['compression_method']['end'] = self._io.pos() - self._debug['text_datastream']['start'] = self._io.pos() - self._raw_text_datastream = self._io.read_bytes_full() - self.text_datastream = zlib.decompress(self._raw_text_datastream) - self._debug['text_datastream']['end'] = self._io.pos() - - - class BkgdTruecolor(KaitaiStruct): - """Background chunk for truecolor images.""" - SEQ_FIELDS = ["red", "green", "blue"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['red']['start'] = self._io.pos() - self.red = self._io.read_u2be() - self._debug['red']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._io.read_u2be() - self._debug['green']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._io.read_u2be() - self._debug['blue']['end'] = self._io.pos() - - - class GamaChunk(KaitaiStruct): - """ - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11gAMA - """ - SEQ_FIELDS = ["gamma_int"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['gamma_int']['start'] = self._io.pos() - self.gamma_int = self._io.read_u4be() - self._debug['gamma_int']['end'] = self._io.pos() - - @property - def gamma_ratio(self): - if hasattr(self, '_m_gamma_ratio'): - return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None - - self._m_gamma_ratio = (100000.0 / self.gamma_int) - return self._m_gamma_ratio if hasattr(self, '_m_gamma_ratio') else None - - - class BkgdChunk(KaitaiStruct): - """Background chunk stores default background color to display this - image against. Contents depend on `color_type` of the image. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11bKGD - """ - SEQ_FIELDS = ["bkgd"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bkgd']['start'] = self._io.pos() - _on = self._root.ihdr.color_type - if _on == self._root.ColorType.indexed: - self.bkgd = self._root.BkgdIndexed(self._io, self, self._root) - self.bkgd._read() - elif _on == self._root.ColorType.truecolor_alpha: - self.bkgd = self._root.BkgdTruecolor(self._io, self, self._root) - self.bkgd._read() - elif _on == self._root.ColorType.greyscale_alpha: - self.bkgd = self._root.BkgdGreyscale(self._io, self, self._root) - self.bkgd._read() - elif _on == self._root.ColorType.truecolor: - self.bkgd = self._root.BkgdTruecolor(self._io, self, self._root) - self.bkgd._read() - elif _on == self._root.ColorType.greyscale: - self.bkgd = self._root.BkgdGreyscale(self._io, self, self._root) - self.bkgd._read() - self._debug['bkgd']['end'] = self._io.pos() - - - class PhysChunk(KaitaiStruct): - """"Physical size" chunk stores data that allows to translate - logical pixels into physical units (meters, etc) and vice-versa. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11pHYs - """ - SEQ_FIELDS = ["pixels_per_unit_x", "pixels_per_unit_y", "unit"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pixels_per_unit_x']['start'] = self._io.pos() - self.pixels_per_unit_x = self._io.read_u4be() - self._debug['pixels_per_unit_x']['end'] = self._io.pos() - self._debug['pixels_per_unit_y']['start'] = self._io.pos() - self.pixels_per_unit_y = self._io.read_u4be() - self._debug['pixels_per_unit_y']['end'] = self._io.pos() - self._debug['unit']['start'] = self._io.pos() - self.unit = KaitaiStream.resolve_enum(self._root.PhysUnit, self._io.read_u1()) - self._debug['unit']['end'] = self._io.pos() - - - class InternationalTextChunk(KaitaiStruct): - """International text chunk effectively allows to store key-value string pairs in - PNG container. Both "key" (keyword) and "value" (text) parts are - given in pre-defined subset of iso8859-1 without control - characters. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11iTXt - """ - SEQ_FIELDS = ["keyword", "compression_flag", "compression_method", "language_tag", "translated_keyword", "text"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['keyword']['start'] = self._io.pos() - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['keyword']['end'] = self._io.pos() - self._debug['compression_flag']['start'] = self._io.pos() - self.compression_flag = self._io.read_u1() - self._debug['compression_flag']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.CompressionMethods, self._io.read_u1()) - self._debug['compression_method']['end'] = self._io.pos() - self._debug['language_tag']['start'] = self._io.pos() - self.language_tag = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['language_tag']['end'] = self._io.pos() - self._debug['translated_keyword']['start'] = self._io.pos() - self.translated_keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['translated_keyword']['end'] = self._io.pos() - self._debug['text']['start'] = self._io.pos() - self.text = (self._io.read_bytes_full()).decode(u"UTF-8") - self._debug['text']['end'] = self._io.pos() - - - class TextChunk(KaitaiStruct): - """Text chunk effectively allows to store key-value string pairs in - PNG container. Both "key" (keyword) and "value" (text) parts are - given in pre-defined subset of iso8859-1 without control - characters. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11tEXt - """ - SEQ_FIELDS = ["keyword", "text"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['keyword']['start'] = self._io.pos() - self.keyword = (self._io.read_bytes_term(0, False, True, True)).decode(u"iso8859-1") - self._debug['keyword']['end'] = self._io.pos() - self._debug['text']['start'] = self._io.pos() - self.text = (self._io.read_bytes_full()).decode(u"iso8859-1") - self._debug['text']['end'] = self._io.pos() - - - class TimeChunk(KaitaiStruct): - """Time chunk stores time stamp of last modification of this image, - up to 1 second precision in UTC timezone. - - .. seealso:: - Source - https://www.w3.org/TR/PNG/#11tIME - """ - SEQ_FIELDS = ["year", "month", "day", "hour", "minute", "second"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = self._io.read_u2be() - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = self._io.read_u1() - self._debug['month']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = self._io.read_u1() - self._debug['day']['end'] = self._io.pos() - self._debug['hour']['start'] = self._io.pos() - self.hour = self._io.read_u1() - self._debug['hour']['end'] = self._io.pos() - self._debug['minute']['start'] = self._io.pos() - self.minute = self._io.read_u1() - self._debug['minute']['end'] = self._io.pos() - self._debug['second']['start'] = self._io.pos() - self.second = self._io.read_u1() - self._debug['second']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/protocol_body.py b/python/examples/kaitai/protocol_body.py deleted file mode 100644 index 33bcbddc..00000000 --- a/python/examples/kaitai/protocol_body.py +++ /dev/null @@ -1,259 +0,0 @@ -# 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 -import collections - - -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)) - -from . import udp_datagram -from . import icmp_packet -from . import tcp_segment -from . import ipv4_packet -from . import ipv6_packet -class ProtocolBody(KaitaiStruct): - """Protocol body represents particular payload on transport level (OSI - layer 4). - - Typically this payload in encapsulated into network level (OSI layer - 3) packet, which includes "protocol number" field that would be used - to decide what's inside the payload and how to parse it. Thanks to - IANA's standardization effort, multiple network level use the same - IDs for these payloads named "protocol numbers". - - This is effectively a "router" type: it expects to get protocol - number as a parameter, and then invokes relevant type parser based - on that parameter. - - .. seealso:: - Source - http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml - """ - - class ProtocolEnum(Enum): - hopopt = 0 - icmp = 1 - igmp = 2 - ggp = 3 - ipv4 = 4 - st = 5 - tcp = 6 - cbt = 7 - egp = 8 - igp = 9 - bbn_rcc_mon = 10 - nvp_ii = 11 - pup = 12 - argus = 13 - emcon = 14 - xnet = 15 - chaos = 16 - udp = 17 - mux = 18 - dcn_meas = 19 - hmp = 20 - prm = 21 - xns_idp = 22 - trunk_1 = 23 - trunk_2 = 24 - leaf_1 = 25 - leaf_2 = 26 - rdp = 27 - irtp = 28 - iso_tp4 = 29 - netblt = 30 - mfe_nsp = 31 - merit_inp = 32 - dccp = 33 - x_3pc = 34 - idpr = 35 - xtp = 36 - ddp = 37 - idpr_cmtp = 38 - tp_plus_plus = 39 - il = 40 - ipv6 = 41 - sdrp = 42 - ipv6_route = 43 - ipv6_frag = 44 - idrp = 45 - rsvp = 46 - gre = 47 - dsr = 48 - bna = 49 - esp = 50 - ah = 51 - i_nlsp = 52 - swipe = 53 - narp = 54 - mobile = 55 - tlsp = 56 - skip = 57 - ipv6_icmp = 58 - ipv6_nonxt = 59 - ipv6_opts = 60 - any_host_internal_protocol = 61 - cftp = 62 - any_local_network = 63 - sat_expak = 64 - kryptolan = 65 - rvd = 66 - ippc = 67 - any_distributed_file_system = 68 - sat_mon = 69 - visa = 70 - ipcv = 71 - cpnx = 72 - cphb = 73 - wsn = 74 - pvp = 75 - br_sat_mon = 76 - sun_nd = 77 - wb_mon = 78 - wb_expak = 79 - iso_ip = 80 - vmtp = 81 - secure_vmtp = 82 - vines = 83 - ttp_or_iptm = 84 - nsfnet_igp = 85 - dgp = 86 - tcf = 87 - eigrp = 88 - ospfigp = 89 - sprite_rpc = 90 - larp = 91 - mtp = 92 - ax_25 = 93 - ipip = 94 - micp = 95 - scc_sp = 96 - etherip = 97 - encap = 98 - any_private_encryption_scheme = 99 - gmtp = 100 - ifmp = 101 - pnni = 102 - pim = 103 - aris = 104 - scps = 105 - qnx = 106 - a_n = 107 - ipcomp = 108 - snp = 109 - compaq_peer = 110 - ipx_in_ip = 111 - vrrp = 112 - pgm = 113 - any_0_hop = 114 - l2tp = 115 - ddx = 116 - iatp = 117 - stp = 118 - srp = 119 - uti = 120 - smp = 121 - sm = 122 - ptp = 123 - isis_over_ipv4 = 124 - fire = 125 - crtp = 126 - crudp = 127 - sscopmce = 128 - iplt = 129 - sps = 130 - pipe = 131 - sctp = 132 - fc = 133 - rsvp_e2e_ignore = 134 - mobility_header = 135 - udplite = 136 - mpls_in_ip = 137 - manet = 138 - hip = 139 - shim6 = 140 - wesp = 141 - rohc = 142 - reserved_255 = 255 - SEQ_FIELDS = ["body"] - def __init__(self, protocol_num, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.protocol_num = protocol_num - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['body']['start'] = self._io.pos() - _on = self.protocol - if _on == self._root.ProtocolEnum.ipv6_nonxt: - self.body = self._root.NoNextHeader(self._io, self, self._root) - self.body._read() - elif _on == self._root.ProtocolEnum.ipv4: - self.body = ipv4_packet.Ipv4Packet(self._io) - self.body._read() - elif _on == self._root.ProtocolEnum.udp: - self.body = udp_datagram.UdpDatagram(self._io) - self.body._read() - elif _on == self._root.ProtocolEnum.icmp: - self.body = icmp_packet.IcmpPacket(self._io) - self.body._read() - elif _on == self._root.ProtocolEnum.hopopt: - self.body = self._root.OptionHopByHop(self._io, self, self._root) - self.body._read() - elif _on == self._root.ProtocolEnum.ipv6: - self.body = ipv6_packet.Ipv6Packet(self._io) - self.body._read() - elif _on == self._root.ProtocolEnum.tcp: - self.body = tcp_segment.TcpSegment(self._io) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - class NoNextHeader(KaitaiStruct): - """Dummy type for IPv6 "no next header" type, which signifies end of headers chain.""" - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - class OptionHopByHop(KaitaiStruct): - SEQ_FIELDS = ["next_header_type", "hdr_ext_len", "body", "next_header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['next_header_type']['start'] = self._io.pos() - self.next_header_type = self._io.read_u1() - self._debug['next_header_type']['end'] = self._io.pos() - self._debug['hdr_ext_len']['start'] = self._io.pos() - self.hdr_ext_len = self._io.read_u1() - self._debug['hdr_ext_len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes((self.hdr_ext_len - 1)) - self._debug['body']['end'] = self._io.pos() - self._debug['next_header']['start'] = self._io.pos() - self.next_header = ProtocolBody(self.next_header_type, self._io) - self.next_header._read() - self._debug['next_header']['end'] = self._io.pos() - - - @property - def protocol(self): - if hasattr(self, '_m_protocol'): - return self._m_protocol if hasattr(self, '_m_protocol') else None - - self._m_protocol = KaitaiStream.resolve_enum(self._root.ProtocolEnum, self.protocol_num) - return self._m_protocol if hasattr(self, '_m_protocol') else None - - diff --git a/python/examples/kaitai/psx_tim.py b/python/examples/kaitai/psx_tim.py deleted file mode 100644 index 3a3fa0b4..00000000 --- a/python/examples/kaitai/psx_tim.py +++ /dev/null @@ -1,89 +0,0 @@ -# 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 -import collections - - -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 PsxTim(KaitaiStruct): - - class BppType(Enum): - bpp_4 = 0 - bpp_8 = 1 - bpp_16 = 2 - bpp_24 = 3 - SEQ_FIELDS = ["magic", "flags", "clut", "img"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x10\x00\x00\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - if self.has_clut: - self._debug['clut']['start'] = self._io.pos() - self.clut = self._root.Bitmap(self._io, self, self._root) - self.clut._read() - self._debug['clut']['end'] = self._io.pos() - - self._debug['img']['start'] = self._io.pos() - self.img = self._root.Bitmap(self._io, self, self._root) - self.img._read() - self._debug['img']['end'] = self._io.pos() - - class Bitmap(KaitaiStruct): - SEQ_FIELDS = ["len", "origin_x", "origin_y", "width", "height", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u4le() - self._debug['len']['end'] = self._io.pos() - self._debug['origin_x']['start'] = self._io.pos() - self.origin_x = self._io.read_u2le() - self._debug['origin_x']['end'] = self._io.pos() - self._debug['origin_y']['start'] = self._io.pos() - self.origin_y = self._io.read_u2le() - self._debug['origin_y']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes((self.len - 12)) - self._debug['body']['end'] = self._io.pos() - - - @property - def has_clut(self): - if hasattr(self, '_m_has_clut'): - return self._m_has_clut if hasattr(self, '_m_has_clut') else None - - self._m_has_clut = (self.flags & 8) != 0 - return self._m_has_clut if hasattr(self, '_m_has_clut') else None - - @property - def bpp(self): - if hasattr(self, '_m_bpp'): - return self._m_bpp if hasattr(self, '_m_bpp') else None - - self._m_bpp = (self.flags & 3) - return self._m_bpp if hasattr(self, '_m_bpp') else None - - diff --git a/python/examples/kaitai/python_pyc_27.py b/python/examples/kaitai/python_pyc_27.py deleted file mode 100644 index d4c4db01..00000000 --- a/python/examples/kaitai/python_pyc_27.py +++ /dev/null @@ -1,507 +0,0 @@ -# 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 -import collections - - -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 PythonPyc27(KaitaiStruct): - """Python interpreter runs .py files in 2 step process: first, it - produces bytecode, which it then executes. Translation of .py source - into bytecode is time-consuming, so Python dumps compiled bytecode - into .pyc files, to be reused from cache at later time if possible. - - .pyc file is essentially a raw dump of `py_object` (see `body`) with - a simple header prepended. - """ - - class Version(Enum): - v15 = 20121 - v16 = 50428 - v20 = 50823 - v21 = 60202 - v22 = 60717 - v23_a0 = 62011 - v23_a0b = 62021 - v24_a0 = 62041 - v24_a3 = 62051 - v24_b1 = 62061 - v25_a0 = 62071 - v25_a0b = 62081 - v25_a0c = 62091 - v25_a0d = 62092 - v25_b3 = 62101 - v25_b3b = 62111 - v25_c1 = 62121 - v25_c2 = 62131 - v26_a0 = 62151 - v26_a1 = 62161 - v27_a0 = 62171 - v27_a0b = 62181 - v27_a0c = 62191 - v27_a0d = 62201 - v27_a0e = 62211 - SEQ_FIELDS = ["version_magic", "crlf", "modification_timestamp", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version_magic']['start'] = self._io.pos() - self.version_magic = KaitaiStream.resolve_enum(self._root.Version, self._io.read_u2le()) - self._debug['version_magic']['end'] = self._io.pos() - self._debug['crlf']['start'] = self._io.pos() - self.crlf = self._io.read_u2le() - self._debug['crlf']['end'] = self._io.pos() - self._debug['modification_timestamp']['start'] = self._io.pos() - self.modification_timestamp = self._io.read_u4le() - self._debug['modification_timestamp']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._root.PyObject(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - class CodeObject(KaitaiStruct): - - class FlagsEnum(Enum): - has_args = 4 - has_kwargs = 8 - generator = 32 - SEQ_FIELDS = ["arg_count", "local_count", "stack_size", "flags", "code", "consts", "names", "var_names", "free_vars", "cell_vars", "filename", "name", "first_line_no", "lnotab"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['arg_count']['start'] = self._io.pos() - self.arg_count = self._io.read_u4le() - self._debug['arg_count']['end'] = self._io.pos() - self._debug['local_count']['start'] = self._io.pos() - self.local_count = self._io.read_u4le() - self._debug['local_count']['end'] = self._io.pos() - self._debug['stack_size']['start'] = self._io.pos() - self.stack_size = self._io.read_u4le() - self._debug['stack_size']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.CodeObject.FlagsEnum, self._io.read_u4le()) - self._debug['flags']['end'] = self._io.pos() - self._debug['code']['start'] = self._io.pos() - self.code = self._root.Assembly(self._io, self, self._root) - self.code._read() - self._debug['code']['end'] = self._io.pos() - self._debug['consts']['start'] = self._io.pos() - self.consts = self._root.PyObject(self._io, self, self._root) - self.consts._read() - self._debug['consts']['end'] = self._io.pos() - self._debug['names']['start'] = self._io.pos() - self.names = self._root.PyObject(self._io, self, self._root) - self.names._read() - self._debug['names']['end'] = self._io.pos() - self._debug['var_names']['start'] = self._io.pos() - self.var_names = self._root.PyObject(self._io, self, self._root) - self.var_names._read() - self._debug['var_names']['end'] = self._io.pos() - self._debug['free_vars']['start'] = self._io.pos() - self.free_vars = self._root.PyObject(self._io, self, self._root) - self.free_vars._read() - self._debug['free_vars']['end'] = self._io.pos() - self._debug['cell_vars']['start'] = self._io.pos() - self.cell_vars = self._root.PyObject(self._io, self, self._root) - self.cell_vars._read() - self._debug['cell_vars']['end'] = self._io.pos() - self._debug['filename']['start'] = self._io.pos() - self.filename = self._root.PyObject(self._io, self, self._root) - self.filename._read() - self._debug['filename']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = self._root.PyObject(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['first_line_no']['start'] = self._io.pos() - self.first_line_no = self._io.read_u4le() - self._debug['first_line_no']['end'] = self._io.pos() - self._debug['lnotab']['start'] = self._io.pos() - self.lnotab = self._root.PyObject(self._io, self, self._root) - self.lnotab._read() - self._debug['lnotab']['end'] = self._io.pos() - - - class Assembly(KaitaiStruct): - SEQ_FIELDS = ["string_magic", "length", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['string_magic']['start'] = self._io.pos() - self.string_magic = self._io.ensure_fixed_contents(b"\x73") - self._debug['string_magic']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self._raw_items = self._io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw_items)) - self.items = self._root.OpArgs(io, self, self._root) - self.items._read() - self._debug['items']['end'] = self._io.pos() - - - class OpArg(KaitaiStruct): - - class OpCodeEnum(Enum): - stop_code = 0 - pop_top = 1 - rot_two = 2 - rot_three = 3 - dup_top = 4 - rot_four = 5 - nop = 9 - unary_positive = 10 - unary_negative = 11 - unary_not = 12 - unary_convert = 13 - unary_invert = 15 - binary_power = 19 - binary_multiply = 20 - binary_divide = 21 - binary_modulo = 22 - binary_add = 23 - binary_subtract = 24 - binary_subscr = 25 - binary_floor_divide = 26 - binary_true_divide = 27 - inplace_floor_divide = 28 - inplace_true_divide = 29 - slice_0 = 30 - slice_1 = 31 - slice_2 = 32 - slice_3 = 33 - store_slice_0 = 40 - store_slice_1 = 41 - store_slice_2 = 42 - store_slice_3 = 43 - delete_slice_0 = 50 - delete_slice_1 = 51 - delete_slice_2 = 52 - delete_slice_3 = 53 - store_map = 54 - inplace_add = 55 - inplace_subtract = 56 - inplace_multiply = 57 - inplace_divide = 58 - inplace_modulo = 59 - store_subscr = 60 - delete_subscr = 61 - binary_lshift = 62 - binary_rshift = 63 - binary_and = 64 - binary_xor = 65 - binary_or = 66 - inplace_power = 67 - get_iter = 68 - print_expr = 70 - print_item = 71 - print_newline = 72 - print_item_to = 73 - print_newline_to = 74 - inplace_lshift = 75 - inplace_rshift = 76 - inplace_and = 77 - inplace_xor = 78 - inplace_or = 79 - break_loop = 80 - with_cleanup = 81 - load_locals = 82 - return_value = 83 - import_star = 84 - exec_stmt = 85 - yield_value = 86 - pop_block = 87 - end_finally = 88 - build_class = 89 - store_name = 90 - delete_name = 91 - unpack_sequence = 92 - for_iter = 93 - list_append = 94 - store_attr = 95 - delete_attr = 96 - store_global = 97 - delete_global = 98 - dup_topx = 99 - load_const = 100 - load_name = 101 - build_tuple = 102 - build_list = 103 - build_set = 104 - build_map = 105 - load_attr = 106 - compare_op = 107 - import_name = 108 - import_from = 109 - jump_forward = 110 - jump_if_false_or_pop = 111 - jump_if_true_or_pop = 112 - jump_absolute = 113 - pop_jump_if_false = 114 - pop_jump_if_true = 115 - load_global = 116 - continue_loop = 119 - setup_loop = 120 - setup_except = 121 - setup_finally = 122 - load_fast = 124 - store_fast = 125 - delete_fast = 126 - raise_varargs = 130 - call_function = 131 - make_function = 132 - build_slice = 133 - make_closure = 134 - load_closure = 135 - load_deref = 136 - store_deref = 137 - call_function_var = 140 - call_function_kw = 141 - call_function_var_kw = 142 - setup_with = 143 - extended_arg = 145 - set_add = 146 - map_add = 147 - SEQ_FIELDS = ["op_code", "arg"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['op_code']['start'] = self._io.pos() - self.op_code = KaitaiStream.resolve_enum(self._root.OpArg.OpCodeEnum, self._io.read_u1()) - self._debug['op_code']['end'] = self._io.pos() - if self.op_code.value >= self._root.OpArg.OpCodeEnum.store_name.value: - self._debug['arg']['start'] = self._io.pos() - self.arg = self._io.read_u2le() - self._debug['arg']['end'] = self._io.pos() - - - - class PyObject(KaitaiStruct): - - class ObjectType(Enum): - tuple = 40 - py_false = 70 - none = 78 - string_ref = 82 - py_true = 84 - code_object = 99 - int = 105 - string = 115 - interned = 116 - unicode_string = 117 - SEQ_FIELDS = ["type", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.PyObject.ObjectType, self._io.read_u1()) - self._debug['type']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - _on = self.type - if _on == self._root.PyObject.ObjectType.string: - self.value = self._root.PyObject.PyString(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.tuple: - self.value = self._root.PyObject.Tuple(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.int: - self.value = self._io.read_u4le() - elif _on == self._root.PyObject.ObjectType.py_true: - self.value = self._root.PyObject.PyTrue(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.py_false: - self.value = self._root.PyObject.PyFalse(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.none: - self.value = self._root.PyObject.PyNone(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.string_ref: - self.value = self._root.PyObject.StringRef(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.code_object: - self.value = self._root.CodeObject(self._io, self, self._root) - self.value._read() - elif _on == self._root.PyObject.ObjectType.interned: - self.value = self._root.PyObject.InternedString(self._io, self, self._root) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - class PyNone(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - class PyFalse(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - class StringRef(KaitaiStruct): - SEQ_FIELDS = ["interned_list_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['interned_list_index']['start'] = self._io.pos() - self.interned_list_index = self._io.read_u4le() - self._debug['interned_list_index']['end'] = self._io.pos() - - - class PyTrue(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - class Tuple(KaitaiStruct): - SEQ_FIELDS = ["count", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u4le() - self._debug['count']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.PyObject(self._io, self, self._root) - _t_items._read() - self.items[i] = _t_items - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - - class UnicodeString(KaitaiStruct): - SEQ_FIELDS = ["length", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = (self._io.read_bytes(self.length)).decode(u"utf-8") - self._debug['data']['end'] = self._io.pos() - - - class InternedString(KaitaiStruct): - SEQ_FIELDS = ["length", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = (self._io.read_bytes(self.length)).decode(u"utf-8") - self._debug['data']['end'] = self._io.pos() - - - class PyString(KaitaiStruct): - SEQ_FIELDS = ["length", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4le() - self._debug['length']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.length) - self._debug['data']['end'] = self._io.pos() - - - - class OpArgs(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.OpArg(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/quake_mdl.py b/python/examples/kaitai/quake_mdl.py deleted file mode 100644 index 2a6ec048..00000000 --- a/python/examples/kaitai/quake_mdl.py +++ /dev/null @@ -1,376 +0,0 @@ -# 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 -import collections - - -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 QuakeMdl(KaitaiStruct): - SEQ_FIELDS = ["header", "skins", "texture_coordinates", "triangles", "frames"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.MdlHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['skins']['start'] = self._io.pos() - self.skins = [None] * (self.header.num_skins) - for i in range(self.header.num_skins): - if not 'arr' in self._debug['skins']: - self._debug['skins']['arr'] = [] - self._debug['skins']['arr'].append({'start': self._io.pos()}) - _t_skins = self._root.MdlSkin(self._io, self, self._root) - _t_skins._read() - self.skins[i] = _t_skins - self._debug['skins']['arr'][i]['end'] = self._io.pos() - - self._debug['skins']['end'] = self._io.pos() - self._debug['texture_coordinates']['start'] = self._io.pos() - self.texture_coordinates = [None] * (self.header.num_verts) - for i in range(self.header.num_verts): - if not 'arr' in self._debug['texture_coordinates']: - self._debug['texture_coordinates']['arr'] = [] - self._debug['texture_coordinates']['arr'].append({'start': self._io.pos()}) - _t_texture_coordinates = self._root.MdlTexcoord(self._io, self, self._root) - _t_texture_coordinates._read() - self.texture_coordinates[i] = _t_texture_coordinates - self._debug['texture_coordinates']['arr'][i]['end'] = self._io.pos() - - self._debug['texture_coordinates']['end'] = self._io.pos() - self._debug['triangles']['start'] = self._io.pos() - self.triangles = [None] * (self.header.num_tris) - for i in range(self.header.num_tris): - if not 'arr' in self._debug['triangles']: - self._debug['triangles']['arr'] = [] - self._debug['triangles']['arr'].append({'start': self._io.pos()}) - _t_triangles = self._root.MdlTriangle(self._io, self, self._root) - _t_triangles._read() - self.triangles[i] = _t_triangles - self._debug['triangles']['arr'][i]['end'] = self._io.pos() - - self._debug['triangles']['end'] = self._io.pos() - self._debug['frames']['start'] = self._io.pos() - self.frames = [None] * (self.header.num_frames) - for i in range(self.header.num_frames): - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.MdlFrame(self._io, self, self._root) - _t_frames._read() - self.frames[i] = _t_frames - self._debug['frames']['arr'][i]['end'] = self._io.pos() - - self._debug['frames']['end'] = self._io.pos() - - class MdlVertex(KaitaiStruct): - SEQ_FIELDS = ["values", "normal_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['values']['start'] = self._io.pos() - self.values = [None] * (3) - for i in range(3): - if not 'arr' in self._debug['values']: - self._debug['values']['arr'] = [] - self._debug['values']['arr'].append({'start': self._io.pos()}) - self.values[i] = self._io.read_u1() - self._debug['values']['arr'][i]['end'] = self._io.pos() - - self._debug['values']['end'] = self._io.pos() - self._debug['normal_index']['start'] = self._io.pos() - self.normal_index = self._io.read_u1() - self._debug['normal_index']['end'] = self._io.pos() - - - class MdlTexcoord(KaitaiStruct): - SEQ_FIELDS = ["on_seam", "s", "t"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['on_seam']['start'] = self._io.pos() - self.on_seam = self._io.read_s4le() - self._debug['on_seam']['end'] = self._io.pos() - self._debug['s']['start'] = self._io.pos() - self.s = self._io.read_s4le() - self._debug['s']['end'] = self._io.pos() - self._debug['t']['start'] = self._io.pos() - self.t = self._io.read_s4le() - self._debug['t']['end'] = self._io.pos() - - - class MdlHeader(KaitaiStruct): - SEQ_FIELDS = ["ident", "version_must_be_6", "scale", "origin", "radius", "eye_position", "num_skins", "skin_width", "skin_height", "num_verts", "num_tris", "num_frames", "synctype", "flags", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ident']['start'] = self._io.pos() - self.ident = self._io.ensure_fixed_contents(b"\x49\x44\x50\x4F") - self._debug['ident']['end'] = self._io.pos() - self._debug['version_must_be_6']['start'] = self._io.pos() - self.version_must_be_6 = self._io.ensure_fixed_contents(b"\x06\x00\x00\x00") - self._debug['version_must_be_6']['end'] = self._io.pos() - self._debug['scale']['start'] = self._io.pos() - self.scale = self._root.Vec3(self._io, self, self._root) - self.scale._read() - self._debug['scale']['end'] = self._io.pos() - self._debug['origin']['start'] = self._io.pos() - self.origin = self._root.Vec3(self._io, self, self._root) - self.origin._read() - self._debug['origin']['end'] = self._io.pos() - self._debug['radius']['start'] = self._io.pos() - self.radius = self._io.read_f4le() - self._debug['radius']['end'] = self._io.pos() - self._debug['eye_position']['start'] = self._io.pos() - self.eye_position = self._root.Vec3(self._io, self, self._root) - self.eye_position._read() - self._debug['eye_position']['end'] = self._io.pos() - self._debug['num_skins']['start'] = self._io.pos() - self.num_skins = self._io.read_s4le() - self._debug['num_skins']['end'] = self._io.pos() - self._debug['skin_width']['start'] = self._io.pos() - self.skin_width = self._io.read_s4le() - self._debug['skin_width']['end'] = self._io.pos() - self._debug['skin_height']['start'] = self._io.pos() - self.skin_height = self._io.read_s4le() - self._debug['skin_height']['end'] = self._io.pos() - self._debug['num_verts']['start'] = self._io.pos() - self.num_verts = self._io.read_s4le() - self._debug['num_verts']['end'] = self._io.pos() - self._debug['num_tris']['start'] = self._io.pos() - self.num_tris = self._io.read_s4le() - self._debug['num_tris']['end'] = self._io.pos() - self._debug['num_frames']['start'] = self._io.pos() - self.num_frames = self._io.read_s4le() - self._debug['num_frames']['end'] = self._io.pos() - self._debug['synctype']['start'] = self._io.pos() - self.synctype = self._io.read_s4le() - self._debug['synctype']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_s4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_f4le() - self._debug['size']['end'] = self._io.pos() - - @property - def version(self): - if hasattr(self, '_m_version'): - return self._m_version if hasattr(self, '_m_version') else None - - self._m_version = 6 - return self._m_version if hasattr(self, '_m_version') else None - - @property - def skin_size(self): - if hasattr(self, '_m_skin_size'): - return self._m_skin_size if hasattr(self, '_m_skin_size') else None - - self._m_skin_size = (self.skin_width * self.skin_height) - return self._m_skin_size if hasattr(self, '_m_skin_size') else None - - - class MdlSkin(KaitaiStruct): - SEQ_FIELDS = ["group", "single_texture_data", "num_frames", "frame_times", "group_texture_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['group']['start'] = self._io.pos() - self.group = self._io.read_s4le() - self._debug['group']['end'] = self._io.pos() - if self.group == 0: - self._debug['single_texture_data']['start'] = self._io.pos() - self.single_texture_data = self._io.read_bytes(self._root.header.skin_size) - self._debug['single_texture_data']['end'] = self._io.pos() - - if self.group != 0: - self._debug['num_frames']['start'] = self._io.pos() - self.num_frames = self._io.read_u4le() - self._debug['num_frames']['end'] = self._io.pos() - - if self.group != 0: - self._debug['frame_times']['start'] = self._io.pos() - self.frame_times = [None] * (self.num_frames) - for i in range(self.num_frames): - if not 'arr' in self._debug['frame_times']: - self._debug['frame_times']['arr'] = [] - self._debug['frame_times']['arr'].append({'start': self._io.pos()}) - self.frame_times[i] = self._io.read_f4le() - self._debug['frame_times']['arr'][i]['end'] = self._io.pos() - - self._debug['frame_times']['end'] = self._io.pos() - - if self.group != 0: - self._debug['group_texture_data']['start'] = self._io.pos() - self.group_texture_data = [None] * (self.num_frames) - for i in range(self.num_frames): - if not 'arr' in self._debug['group_texture_data']: - self._debug['group_texture_data']['arr'] = [] - self._debug['group_texture_data']['arr'].append({'start': self._io.pos()}) - self.group_texture_data[i] = self._io.read_bytes(self._root.header.skin_size) - self._debug['group_texture_data']['arr'][i]['end'] = self._io.pos() - - self._debug['group_texture_data']['end'] = self._io.pos() - - - - class MdlFrame(KaitaiStruct): - SEQ_FIELDS = ["type", "min", "max", "time", "frames"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_s4le() - self._debug['type']['end'] = self._io.pos() - if self.type != 0: - self._debug['min']['start'] = self._io.pos() - self.min = self._root.MdlVertex(self._io, self, self._root) - self.min._read() - self._debug['min']['end'] = self._io.pos() - - if self.type != 0: - self._debug['max']['start'] = self._io.pos() - self.max = self._root.MdlVertex(self._io, self, self._root) - self.max._read() - self._debug['max']['end'] = self._io.pos() - - if self.type != 0: - self._debug['time']['start'] = self._io.pos() - self.time = [None] * (self.type) - for i in range(self.type): - if not 'arr' in self._debug['time']: - self._debug['time']['arr'] = [] - self._debug['time']['arr'].append({'start': self._io.pos()}) - self.time[i] = self._io.read_f4le() - self._debug['time']['arr'][i]['end'] = self._io.pos() - - self._debug['time']['end'] = self._io.pos() - - self._debug['frames']['start'] = self._io.pos() - self.frames = [None] * (self.num_simple_frames) - for i in range(self.num_simple_frames): - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.MdlSimpleFrame(self._io, self, self._root) - _t_frames._read() - self.frames[i] = _t_frames - self._debug['frames']['arr'][i]['end'] = self._io.pos() - - self._debug['frames']['end'] = self._io.pos() - - @property - def num_simple_frames(self): - if hasattr(self, '_m_num_simple_frames'): - return self._m_num_simple_frames if hasattr(self, '_m_num_simple_frames') else None - - self._m_num_simple_frames = (1 if self.type == 0 else self.type) - return self._m_num_simple_frames if hasattr(self, '_m_num_simple_frames') else None - - - class MdlSimpleFrame(KaitaiStruct): - SEQ_FIELDS = ["bbox_min", "bbox_max", "name", "vertices"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bbox_min']['start'] = self._io.pos() - self.bbox_min = self._root.MdlVertex(self._io, self, self._root) - self.bbox_min._read() - self._debug['bbox_min']['end'] = self._io.pos() - self._debug['bbox_max']['start'] = self._io.pos() - self.bbox_max = self._root.MdlVertex(self._io, self, self._root) - self.bbox_max._read() - self._debug['bbox_max']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0), 0, False)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - self._debug['vertices']['start'] = self._io.pos() - self.vertices = [None] * (self._root.header.num_verts) - for i in range(self._root.header.num_verts): - if not 'arr' in self._debug['vertices']: - self._debug['vertices']['arr'] = [] - self._debug['vertices']['arr'].append({'start': self._io.pos()}) - _t_vertices = self._root.MdlVertex(self._io, self, self._root) - _t_vertices._read() - self.vertices[i] = _t_vertices - self._debug['vertices']['arr'][i]['end'] = self._io.pos() - - self._debug['vertices']['end'] = self._io.pos() - - - class MdlTriangle(KaitaiStruct): - SEQ_FIELDS = ["faces_front", "vertices"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['faces_front']['start'] = self._io.pos() - self.faces_front = self._io.read_s4le() - self._debug['faces_front']['end'] = self._io.pos() - self._debug['vertices']['start'] = self._io.pos() - self.vertices = [None] * (3) - for i in range(3): - if not 'arr' in self._debug['vertices']: - self._debug['vertices']['arr'] = [] - self._debug['vertices']['arr'].append({'start': self._io.pos()}) - self.vertices[i] = self._io.read_s4le() - self._debug['vertices']['arr'][i]['end'] = self._io.pos() - - self._debug['vertices']['end'] = self._io.pos() - - - class Vec3(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f4le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f4le() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_f4le() - self._debug['z']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/quake_pak.py b/python/examples/kaitai/quake_pak.py deleted file mode 100644 index 7eea7b3c..00000000 --- a/python/examples/kaitai/quake_pak.py +++ /dev/null @@ -1,109 +0,0 @@ -# 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 -import collections - - -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 QuakePak(KaitaiStruct): - """ - .. seealso:: - Source - https://quakewiki.org/wiki/.pak#Format_specification - """ - SEQ_FIELDS = ["magic", "ofs_index", "len_index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x50\x41\x43\x4B") - self._debug['magic']['end'] = self._io.pos() - self._debug['ofs_index']['start'] = self._io.pos() - self.ofs_index = self._io.read_u4le() - self._debug['ofs_index']['end'] = self._io.pos() - self._debug['len_index']['start'] = self._io.pos() - self.len_index = self._io.read_u4le() - self._debug['len_index']['end'] = self._io.pos() - - class IndexStruct(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.IndexEntry(self._io, self, self._root) - _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() - - - class IndexEntry(KaitaiStruct): - SEQ_FIELDS = ["name", "ofs", "size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(KaitaiStream.bytes_strip_right(self._io.read_bytes(56), 0), 0, False)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - self._debug['ofs']['start'] = self._io.pos() - self.ofs = self._io.read_u4le() - self._debug['ofs']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs) - self._debug['_m_body']['start'] = io.pos() - self._m_body = io.read_bytes(self.size) - self._debug['_m_body']['end'] = io.pos() - io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - @property - def index(self): - if hasattr(self, '_m_index'): - return self._m_index if hasattr(self, '_m_index') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_index) - self._debug['_m_index']['start'] = self._io.pos() - self._raw__m_index = self._io.read_bytes(self.len_index) - io = KaitaiStream(BytesIO(self._raw__m_index)) - self._m_index = self._root.IndexStruct(io, self, self._root) - self._m_index._read() - self._debug['_m_index']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_index if hasattr(self, '_m_index') else None - - diff --git a/python/examples/kaitai/quicktime_mov.py b/python/examples/kaitai/quicktime_mov.py deleted file mode 100644 index 77733656..00000000 --- a/python/examples/kaitai/quicktime_mov.py +++ /dev/null @@ -1,478 +0,0 @@ -# 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 -import collections - - -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 QuicktimeMov(KaitaiStruct): - """ - .. seealso:: - Source - https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-BBCGDDDF - """ - - class AtomType(Enum): - xtra = 1484026465 - dinf = 1684631142 - dref = 1685218662 - edts = 1701082227 - elst = 1701606260 - free = 1718773093 - ftyp = 1718909296 - hdlr = 1751411826 - iods = 1768907891 - mdat = 1835295092 - mdhd = 1835296868 - mdia = 1835297121 - meta = 1835365473 - minf = 1835626086 - moof = 1836019558 - moov = 1836019574 - mvhd = 1836476516 - smhd = 1936549988 - stbl = 1937007212 - stco = 1937007471 - stsc = 1937011555 - stsd = 1937011556 - stsz = 1937011578 - stts = 1937011827 - tkhd = 1953196132 - traf = 1953653094 - trak = 1953653099 - tref = 1953654118 - udta = 1969517665 - vmhd = 1986881636 - - class Brand(Enum): - x_3g2a = 862401121 - x_3ge6 = 862414134 - x_3ge9 = 862414137 - x_3gf9 = 862414393 - x_3gg6 = 862414646 - x_3gg9 = 862414649 - x_3gh9 = 862414905 - x_3gm9 = 862416185 - x_3gp4 = 862416948 - x_3gp5 = 862416949 - x_3gp6 = 862416950 - x_3gp7 = 862416951 - x_3gp8 = 862416952 - x_3gp9 = 862416953 - x_3gr6 = 862417462 - x_3gr9 = 862417465 - x_3gs6 = 862417718 - x_3gs9 = 862417721 - x_3gt9 = 862417977 - arri = 1095914057 - caep = 1128351056 - cdes = 1128555891 - j2p0 = 1244811312 - j2p1 = 1244811313 - lcag = 1279476039 - m4a = 1295270176 - m4b = 1295270432 - m4p = 1295274016 - m4v = 1295275552 - mfsm = 1296454477 - mgsv = 1296520022 - mppi = 1297109065 - msnv = 1297305174 - ross = 1380930387 - seau = 1397047637 - sebk = 1397047883 - xavc = 1480676931 - avc1 = 1635148593 - bbxm = 1650620525 - caqv = 1667330422 - ccff = 1667458662 - da0a = 1684090977 - da0b = 1684090978 - da1a = 1684091233 - da1b = 1684091234 - da2a = 1684091489 - da2b = 1684091490 - da3a = 1684091745 - da3b = 1684091746 - dash = 1684108136 - dby1 = 1684175153 - dmb1 = 1684890161 - dsms = 1685286259 - dv1a = 1685467489 - dv1b = 1685467490 - dv2a = 1685467745 - dv2b = 1685467746 - dv3a = 1685468001 - dv3b = 1685468002 - dvr1 = 1685484081 - dvt1 = 1685484593 - dxo = 1685614368 - emsg = 1701671783 - ifrm = 1768321645 - isc2 = 1769169714 - iso2 = 1769172786 - iso3 = 1769172787 - iso4 = 1769172788 - iso5 = 1769172789 - iso6 = 1769172790 - isom = 1769172845 - jp2 = 1785737760 - jpm = 1785752864 - jpsi = 1785754473 - jpx = 1785755680 - jpxb = 1785755746 - lmsg = 1819112295 - mj2s = 1835676275 - mjp2 = 1835692082 - mp21 = 1836069425 - mp41 = 1836069937 - mp42 = 1836069938 - mp71 = 1836070705 - msdh = 1836278888 - msix = 1836280184 - niko = 1852402543 - odcf = 1868850022 - opf2 = 1869637170 - opx2 = 1869641778 - pana = 1885433441 - piff = 1885955686 - pnvi = 1886287465 - qt = 1903435808 - risx = 1919513464 - sdv = 1935963680 - senv = 1936027254 - sims = 1936289139 - sisx = 1936290680 - ssss = 1936946035 - uvvu = 1970697845 - SEQ_FIELDS = ["atoms"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['atoms']['start'] = self._io.pos() - self.atoms = self._root.AtomList(self._io, self, self._root) - self.atoms._read() - self._debug['atoms']['end'] = self._io.pos() - - class MvhdBody(KaitaiStruct): - """ - .. seealso:: - Source - https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-BBCGFGJG - """ - SEQ_FIELDS = ["version", "flags", "creation_time", "modification_time", "time_scale", "duration", "preferred_rate", "preferred_volume", "reserved1", "matrix", "preview_time", "preview_duration", "poster_time", "selection_time", "selection_duration", "current_time", "next_track_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes(3) - self._debug['flags']['end'] = self._io.pos() - self._debug['creation_time']['start'] = self._io.pos() - self.creation_time = self._io.read_u4be() - self._debug['creation_time']['end'] = self._io.pos() - self._debug['modification_time']['start'] = self._io.pos() - self.modification_time = self._io.read_u4be() - self._debug['modification_time']['end'] = self._io.pos() - self._debug['time_scale']['start'] = self._io.pos() - self.time_scale = self._io.read_u4be() - self._debug['time_scale']['end'] = self._io.pos() - self._debug['duration']['start'] = self._io.pos() - self.duration = self._io.read_u4be() - self._debug['duration']['end'] = self._io.pos() - self._debug['preferred_rate']['start'] = self._io.pos() - self.preferred_rate = self._root.Fixed32(self._io, self, self._root) - self.preferred_rate._read() - self._debug['preferred_rate']['end'] = self._io.pos() - self._debug['preferred_volume']['start'] = self._io.pos() - self.preferred_volume = self._root.Fixed16(self._io, self, self._root) - self.preferred_volume._read() - self._debug['preferred_volume']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(10) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['matrix']['start'] = self._io.pos() - self.matrix = self._io.read_bytes(36) - self._debug['matrix']['end'] = self._io.pos() - self._debug['preview_time']['start'] = self._io.pos() - self.preview_time = self._io.read_u4be() - self._debug['preview_time']['end'] = self._io.pos() - self._debug['preview_duration']['start'] = self._io.pos() - self.preview_duration = self._io.read_u4be() - self._debug['preview_duration']['end'] = self._io.pos() - self._debug['poster_time']['start'] = self._io.pos() - self.poster_time = self._io.read_u4be() - self._debug['poster_time']['end'] = self._io.pos() - self._debug['selection_time']['start'] = self._io.pos() - self.selection_time = self._io.read_u4be() - self._debug['selection_time']['end'] = self._io.pos() - self._debug['selection_duration']['start'] = self._io.pos() - self.selection_duration = self._io.read_u4be() - self._debug['selection_duration']['end'] = self._io.pos() - self._debug['current_time']['start'] = self._io.pos() - self.current_time = self._io.read_u4be() - self._debug['current_time']['end'] = self._io.pos() - self._debug['next_track_id']['start'] = self._io.pos() - self.next_track_id = self._io.read_u4be() - self._debug['next_track_id']['end'] = self._io.pos() - - - class FtypBody(KaitaiStruct): - """ - .. seealso:: - Source - https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-CJBCBIFF - """ - SEQ_FIELDS = ["major_brand", "minor_version", "compatible_brands"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['major_brand']['start'] = self._io.pos() - self.major_brand = KaitaiStream.resolve_enum(self._root.Brand, self._io.read_u4be()) - self._debug['major_brand']['end'] = self._io.pos() - self._debug['minor_version']['start'] = self._io.pos() - self.minor_version = self._io.read_bytes(4) - self._debug['minor_version']['end'] = self._io.pos() - self._debug['compatible_brands']['start'] = self._io.pos() - self.compatible_brands = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['compatible_brands']: - self._debug['compatible_brands']['arr'] = [] - self._debug['compatible_brands']['arr'].append({'start': self._io.pos()}) - self.compatible_brands.append(KaitaiStream.resolve_enum(self._root.Brand, self._io.read_u4be())) - self._debug['compatible_brands']['arr'][len(self.compatible_brands) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['compatible_brands']['end'] = self._io.pos() - - - class Fixed32(KaitaiStruct): - """Fixed-point 32-bit number.""" - SEQ_FIELDS = ["int_part", "frac_part"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['int_part']['start'] = self._io.pos() - self.int_part = self._io.read_s2be() - self._debug['int_part']['end'] = self._io.pos() - self._debug['frac_part']['start'] = self._io.pos() - self.frac_part = self._io.read_u2be() - self._debug['frac_part']['end'] = self._io.pos() - - - class Fixed16(KaitaiStruct): - """Fixed-point 16-bit number.""" - SEQ_FIELDS = ["int_part", "frac_part"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['int_part']['start'] = self._io.pos() - self.int_part = self._io.read_s1() - self._debug['int_part']['end'] = self._io.pos() - self._debug['frac_part']['start'] = self._io.pos() - self.frac_part = self._io.read_u1() - self._debug['frac_part']['end'] = self._io.pos() - - - class Atom(KaitaiStruct): - SEQ_FIELDS = ["len32", "atom_type", "len64", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len32']['start'] = self._io.pos() - self.len32 = self._io.read_u4be() - self._debug['len32']['end'] = self._io.pos() - self._debug['atom_type']['start'] = self._io.pos() - self.atom_type = KaitaiStream.resolve_enum(self._root.AtomType, self._io.read_u4be()) - self._debug['atom_type']['end'] = self._io.pos() - if self.len32 == 1: - self._debug['len64']['start'] = self._io.pos() - self.len64 = self._io.read_u8be() - self._debug['len64']['end'] = self._io.pos() - - self._debug['body']['start'] = self._io.pos() - _on = self.atom_type - if _on == self._root.AtomType.moof: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.tkhd: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.TkhdBody(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.stbl: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.traf: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.minf: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.trak: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.moov: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.mdia: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.dinf: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.AtomList(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.mvhd: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.MvhdBody(io, self, self._root) - self.body._read() - elif _on == self._root.AtomType.ftyp: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.FtypBody(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.len) - self._debug['body']['end'] = self._io.pos() - - @property - def len(self): - if hasattr(self, '_m_len'): - return self._m_len if hasattr(self, '_m_len') else None - - self._m_len = ((self._io.size() - 8) if self.len32 == 0 else ((self.len64 - 16) if self.len32 == 1 else (self.len32 - 8))) - return self._m_len if hasattr(self, '_m_len') else None - - - class TkhdBody(KaitaiStruct): - """ - .. seealso:: - Source - https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-25550 - """ - SEQ_FIELDS = ["version", "flags", "creation_time", "modification_time", "track_id", "reserved1", "duration", "reserved2", "layer", "alternative_group", "volume", "reserved3", "matrix", "width", "height"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_bytes(3) - self._debug['flags']['end'] = self._io.pos() - self._debug['creation_time']['start'] = self._io.pos() - self.creation_time = self._io.read_u4be() - self._debug['creation_time']['end'] = self._io.pos() - self._debug['modification_time']['start'] = self._io.pos() - self.modification_time = self._io.read_u4be() - self._debug['modification_time']['end'] = self._io.pos() - self._debug['track_id']['start'] = self._io.pos() - self.track_id = self._io.read_u4be() - self._debug['track_id']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(4) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['duration']['start'] = self._io.pos() - self.duration = self._io.read_u4be() - self._debug['duration']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(8) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['layer']['start'] = self._io.pos() - self.layer = self._io.read_u2be() - self._debug['layer']['end'] = self._io.pos() - self._debug['alternative_group']['start'] = self._io.pos() - self.alternative_group = self._io.read_u2be() - self._debug['alternative_group']['end'] = self._io.pos() - self._debug['volume']['start'] = self._io.pos() - self.volume = self._io.read_u2be() - self._debug['volume']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_u2be() - self._debug['reserved3']['end'] = self._io.pos() - self._debug['matrix']['start'] = self._io.pos() - self.matrix = self._io.read_bytes(36) - self._debug['matrix']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._root.Fixed32(self._io, self, self._root) - self.width._read() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._root.Fixed32(self._io, self, self._root) - self.height._read() - self._debug['height']['end'] = self._io.pos() - - - class AtomList(KaitaiStruct): - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.Atom(self._io, self, self._root) - _t_items._read() - self.items.append(_t_items) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['items']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/rar.py b/python/examples/kaitai/rar.py deleted file mode 100644 index 88548a4b..00000000 --- a/python/examples/kaitai/rar.py +++ /dev/null @@ -1,322 +0,0 @@ -# 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 -import collections - - -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 Rar(KaitaiStruct): - """RAR is a archive format used by popular proprietary RAR archiver, - created by Eugene Roshal. There are two major versions of format - (v1.5-4.0 and RAR v5+). - - File format essentially consists of a linear sequence of - blocks. Each block has fixed header and custom body (that depends on - block type), so it's possible to skip block even if one doesn't know - how to process a certain block type. - - .. seealso:: - - http://acritum.com/winrar/rar-format - """ - - class BlockTypes(Enum): - marker = 114 - archive_header = 115 - file_header = 116 - old_style_comment_header = 117 - old_style_authenticity_info_76 = 118 - old_style_subblock = 119 - old_style_recovery_record = 120 - old_style_authenticity_info_79 = 121 - subblock = 122 - terminator = 123 - - class Oses(Enum): - ms_dos = 0 - os_2 = 1 - windows = 2 - unix = 3 - mac_os = 4 - beos = 5 - - class Methods(Enum): - store = 48 - fastest = 49 - fast = 50 - normal = 51 - good = 52 - best = 53 - SEQ_FIELDS = ["magic", "blocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._root.MagicSignature(self._io, self, self._root) - self.magic._read() - self._debug['magic']['end'] = self._io.pos() - self._debug['blocks']['start'] = self._io.pos() - self.blocks = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _on = self.magic.version - if _on == 0: - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _t_blocks = self._root.Block(self._io, self, self._root) - _t_blocks._read() - self.blocks.append(_t_blocks) - self._debug['blocks']['arr'][len(self.blocks) - 1]['end'] = self._io.pos() - elif _on == 1: - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _t_blocks = self._root.BlockV5(self._io, self, self._root) - _t_blocks._read() - self.blocks.append(_t_blocks) - self._debug['blocks']['arr'][len(self.blocks) - 1]['end'] = self._io.pos() - self._debug['blocks']['arr'][len(self.blocks) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['blocks']['end'] = self._io.pos() - - class BlockV5(KaitaiStruct): - SEQ_FIELDS = [] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - pass - - - class Block(KaitaiStruct): - """Basic block that RAR files consist of. There are several block - types (see `block_type`), which have different `body` and - `add_body`. - """ - SEQ_FIELDS = ["crc16", "block_type", "flags", "block_size", "add_size", "body", "add_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['crc16']['start'] = self._io.pos() - self.crc16 = self._io.read_u2le() - self._debug['crc16']['end'] = self._io.pos() - self._debug['block_type']['start'] = self._io.pos() - self.block_type = KaitaiStream.resolve_enum(self._root.BlockTypes, self._io.read_u1()) - self._debug['block_type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['block_size']['start'] = self._io.pos() - self.block_size = self._io.read_u2le() - self._debug['block_size']['end'] = self._io.pos() - if self.has_add: - self._debug['add_size']['start'] = self._io.pos() - self.add_size = self._io.read_u4le() - self._debug['add_size']['end'] = self._io.pos() - - self._debug['body']['start'] = self._io.pos() - _on = self.block_type - if _on == self._root.BlockTypes.file_header: - self._raw_body = self._io.read_bytes(self.body_size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.BlockFileHeader(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.body_size) - self._debug['body']['end'] = self._io.pos() - if self.has_add: - self._debug['add_body']['start'] = self._io.pos() - self.add_body = self._io.read_bytes(self.add_size) - self._debug['add_body']['end'] = self._io.pos() - - - @property - def has_add(self): - """True if block has additional content attached to it.""" - if hasattr(self, '_m_has_add'): - return self._m_has_add if hasattr(self, '_m_has_add') else None - - self._m_has_add = (self.flags & 32768) != 0 - return self._m_has_add if hasattr(self, '_m_has_add') else None - - @property - def header_size(self): - if hasattr(self, '_m_header_size'): - return self._m_header_size if hasattr(self, '_m_header_size') else None - - self._m_header_size = (11 if self.has_add else 7) - return self._m_header_size if hasattr(self, '_m_header_size') else None - - @property - def body_size(self): - if hasattr(self, '_m_body_size'): - return self._m_body_size if hasattr(self, '_m_body_size') else None - - self._m_body_size = (self.block_size - self.header_size) - return self._m_body_size if hasattr(self, '_m_body_size') else None - - - class BlockFileHeader(KaitaiStruct): - SEQ_FIELDS = ["low_unp_size", "host_os", "file_crc32", "file_time", "rar_version", "method", "name_size", "attr", "high_pack_size", "file_name", "salt"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['low_unp_size']['start'] = self._io.pos() - self.low_unp_size = self._io.read_u4le() - self._debug['low_unp_size']['end'] = self._io.pos() - self._debug['host_os']['start'] = self._io.pos() - self.host_os = KaitaiStream.resolve_enum(self._root.Oses, self._io.read_u1()) - self._debug['host_os']['end'] = self._io.pos() - self._debug['file_crc32']['start'] = self._io.pos() - self.file_crc32 = self._io.read_u4le() - self._debug['file_crc32']['end'] = self._io.pos() - self._debug['file_time']['start'] = self._io.pos() - self.file_time = self._root.DosTime(self._io, self, self._root) - self.file_time._read() - self._debug['file_time']['end'] = self._io.pos() - self._debug['rar_version']['start'] = self._io.pos() - self.rar_version = self._io.read_u1() - self._debug['rar_version']['end'] = self._io.pos() - self._debug['method']['start'] = self._io.pos() - self.method = KaitaiStream.resolve_enum(self._root.Methods, self._io.read_u1()) - self._debug['method']['end'] = self._io.pos() - self._debug['name_size']['start'] = self._io.pos() - self.name_size = self._io.read_u2le() - self._debug['name_size']['end'] = self._io.pos() - self._debug['attr']['start'] = self._io.pos() - self.attr = self._io.read_u4le() - self._debug['attr']['end'] = self._io.pos() - if (self._parent.flags & 256) != 0: - self._debug['high_pack_size']['start'] = self._io.pos() - self.high_pack_size = self._io.read_u4le() - self._debug['high_pack_size']['end'] = self._io.pos() - - self._debug['file_name']['start'] = self._io.pos() - self.file_name = self._io.read_bytes(self.name_size) - self._debug['file_name']['end'] = self._io.pos() - if (self._parent.flags & 1024) != 0: - self._debug['salt']['start'] = self._io.pos() - self.salt = self._io.read_u8le() - self._debug['salt']['end'] = self._io.pos() - - - - class MagicSignature(KaitaiStruct): - """RAR uses either 7-byte magic for RAR versions 1.5 to 4.0, and - 8-byte magic (and pretty different block format) for v5+. This - type would parse and validate both versions of signature. Note - that actually this signature is a valid RAR "block": in theory, - one can omit signature reading at all, and read this normally, - as a block, if exact RAR version is known (and thus it's - possible to choose correct block format). - """ - SEQ_FIELDS = ["magic1", "version", "magic3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic1']['start'] = self._io.pos() - self.magic1 = self._io.ensure_fixed_contents(b"\x52\x61\x72\x21\x1A\x07") - self._debug['magic1']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - if self.version == 1: - self._debug['magic3']['start'] = self._io.pos() - self.magic3 = self._io.ensure_fixed_contents(b"\x00") - self._debug['magic3']['end'] = self._io.pos() - - - - class DosTime(KaitaiStruct): - SEQ_FIELDS = ["time", "date"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['time']['start'] = self._io.pos() - self.time = self._io.read_u2le() - self._debug['time']['end'] = self._io.pos() - self._debug['date']['start'] = self._io.pos() - self.date = self._io.read_u2le() - self._debug['date']['end'] = self._io.pos() - - @property - def month(self): - if hasattr(self, '_m_month'): - return self._m_month if hasattr(self, '_m_month') else None - - self._m_month = ((self.date & 480) >> 5) - return self._m_month if hasattr(self, '_m_month') else None - - @property - def seconds(self): - if hasattr(self, '_m_seconds'): - return self._m_seconds if hasattr(self, '_m_seconds') else None - - self._m_seconds = ((self.time & 31) * 2) - return self._m_seconds if hasattr(self, '_m_seconds') else None - - @property - def year(self): - if hasattr(self, '_m_year'): - return self._m_year if hasattr(self, '_m_year') else None - - self._m_year = (((self.date & 65024) >> 9) + 1980) - return self._m_year if hasattr(self, '_m_year') else None - - @property - def minutes(self): - if hasattr(self, '_m_minutes'): - return self._m_minutes if hasattr(self, '_m_minutes') else None - - self._m_minutes = ((self.time & 2016) >> 5) - return self._m_minutes if hasattr(self, '_m_minutes') else None - - @property - def day(self): - if hasattr(self, '_m_day'): - return self._m_day if hasattr(self, '_m_day') else None - - self._m_day = (self.date & 31) - return self._m_day if hasattr(self, '_m_day') else None - - @property - def hours(self): - if hasattr(self, '_m_hours'): - return self._m_hours if hasattr(self, '_m_hours') else None - - self._m_hours = ((self.time & 63488) >> 11) - return self._m_hours if hasattr(self, '_m_hours') else None - - - diff --git a/python/examples/kaitai/regf.py b/python/examples/kaitai/regf.py deleted file mode 100644 index 6eb96b0d..00000000 --- a/python/examples/kaitai/regf.py +++ /dev/null @@ -1,545 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Regf(KaitaiStruct): - SEQ_FIELDS = ["header", "hive_bins"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.FileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['hive_bins']['start'] = self._io.pos() - self._raw_hive_bins = [] - self.hive_bins = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['hive_bins']: - self._debug['hive_bins']['arr'] = [] - self._debug['hive_bins']['arr'].append({'start': self._io.pos()}) - self._raw_hive_bins.append(self._io.read_bytes(4096)) - io = KaitaiStream(BytesIO(self._raw_hive_bins[-1])) - _t_hive_bins = self._root.HiveBin(io, self, self._root) - _t_hive_bins._read() - self.hive_bins.append(_t_hive_bins) - self._debug['hive_bins']['arr'][len(self.hive_bins) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['hive_bins']['end'] = self._io.pos() - - class Filetime(KaitaiStruct): - SEQ_FIELDS = ["value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u8le() - self._debug['value']['end'] = self._io.pos() - - - class HiveBin(KaitaiStruct): - SEQ_FIELDS = ["header", "cells"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.HiveBinHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['cells']['start'] = self._io.pos() - self.cells = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['cells']: - self._debug['cells']['arr'] = [] - self._debug['cells']['arr'].append({'start': self._io.pos()}) - _t_cells = self._root.HiveBinCell(self._io, self, self._root) - _t_cells._read() - self.cells.append(_t_cells) - self._debug['cells']['arr'][len(self.cells) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['cells']['end'] = self._io.pos() - - - class HiveBinHeader(KaitaiStruct): - SEQ_FIELDS = ["signature", "offset", "size", "unknown1", "unknown2", "timestamp", "unknown4"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x68\x62\x69\x6E") - self._debug['signature']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4le() - self._debug['offset']['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['unknown1']['start'] = self._io.pos() - self.unknown1 = self._io.read_u4le() - self._debug['unknown1']['end'] = self._io.pos() - self._debug['unknown2']['start'] = self._io.pos() - self.unknown2 = self._io.read_u4le() - self._debug['unknown2']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._root.Filetime(self._io, self, self._root) - self.timestamp._read() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['unknown4']['start'] = self._io.pos() - self.unknown4 = self._io.read_u4le() - self._debug['unknown4']['end'] = self._io.pos() - - - class HiveBinCell(KaitaiStruct): - SEQ_FIELDS = ["cell_size_raw", "identifier", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cell_size_raw']['start'] = self._io.pos() - self.cell_size_raw = self._io.read_s4le() - self._debug['cell_size_raw']['end'] = self._io.pos() - self._debug['identifier']['start'] = self._io.pos() - self.identifier = (self._io.read_bytes(2)).decode(u"ascii") - self._debug['identifier']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - _on = self.identifier - if _on == u"li": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListLi(io, self, self._root) - self.data._read() - elif _on == u"vk": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListVk(io, self, self._root) - self.data._read() - elif _on == u"lf": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListLhLf(io, self, self._root) - self.data._read() - elif _on == u"ri": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListRi(io, self, self._root) - self.data._read() - elif _on == u"lh": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListLhLf(io, self, self._root) - self.data._read() - elif _on == u"nk": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.NamedKey(io, self, self._root) - self.data._read() - elif _on == u"sk": - self._raw_data = self._io.read_bytes(((self.cell_size - 2) - 4)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.HiveBinCell.SubKeyListSk(io, self, self._root) - self.data._read() - else: - self.data = self._io.read_bytes(((self.cell_size - 2) - 4)) - self._debug['data']['end'] = self._io.pos() - - class SubKeyListVk(KaitaiStruct): - - class DataTypeEnum(Enum): - reg_none = 0 - reg_sz = 1 - reg_expand_sz = 2 - reg_binary = 3 - reg_dword = 4 - reg_dword_big_endian = 5 - reg_link = 6 - reg_multi_sz = 7 - reg_resource_list = 8 - reg_full_resource_descriptor = 9 - reg_resource_requirements_list = 10 - reg_qword = 11 - - class VkFlags(Enum): - value_comp_name = 1 - SEQ_FIELDS = ["value_name_size", "data_size", "data_offset", "data_type", "flags", "padding", "value_name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value_name_size']['start'] = self._io.pos() - self.value_name_size = self._io.read_u2le() - self._debug['value_name_size']['end'] = self._io.pos() - self._debug['data_size']['start'] = self._io.pos() - self.data_size = self._io.read_u4le() - self._debug['data_size']['end'] = self._io.pos() - self._debug['data_offset']['start'] = self._io.pos() - self.data_offset = self._io.read_u4le() - self._debug['data_offset']['end'] = self._io.pos() - self._debug['data_type']['start'] = self._io.pos() - self.data_type = KaitaiStream.resolve_enum(self._root.HiveBinCell.SubKeyListVk.DataTypeEnum, self._io.read_u4le()) - self._debug['data_type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.HiveBinCell.SubKeyListVk.VkFlags, self._io.read_u2le()) - self._debug['flags']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_u2le() - self._debug['padding']['end'] = self._io.pos() - if self.flags == self._root.HiveBinCell.SubKeyListVk.VkFlags.value_comp_name: - self._debug['value_name']['start'] = self._io.pos() - self.value_name = (self._io.read_bytes(self.value_name_size)).decode(u"ascii") - self._debug['value_name']['end'] = self._io.pos() - - - - class SubKeyListLhLf(KaitaiStruct): - SEQ_FIELDS = ["count", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u2le() - self._debug['count']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.HiveBinCell.SubKeyListLhLf.Item(self._io, self, self._root) - _t_items._read() - self.items[i] = _t_items - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - class Item(KaitaiStruct): - SEQ_FIELDS = ["named_key_offset", "hash_value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['named_key_offset']['start'] = self._io.pos() - self.named_key_offset = self._io.read_u4le() - self._debug['named_key_offset']['end'] = self._io.pos() - self._debug['hash_value']['start'] = self._io.pos() - self.hash_value = self._io.read_u4le() - self._debug['hash_value']['end'] = self._io.pos() - - - - class SubKeyListSk(KaitaiStruct): - SEQ_FIELDS = ["unknown1", "previous_security_key_offset", "next_security_key_offset", "reference_count"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['unknown1']['start'] = self._io.pos() - self.unknown1 = self._io.read_u2le() - self._debug['unknown1']['end'] = self._io.pos() - self._debug['previous_security_key_offset']['start'] = self._io.pos() - self.previous_security_key_offset = self._io.read_u4le() - self._debug['previous_security_key_offset']['end'] = self._io.pos() - self._debug['next_security_key_offset']['start'] = self._io.pos() - self.next_security_key_offset = self._io.read_u4le() - self._debug['next_security_key_offset']['end'] = self._io.pos() - self._debug['reference_count']['start'] = self._io.pos() - self.reference_count = self._io.read_u4le() - self._debug['reference_count']['end'] = self._io.pos() - - - class SubKeyListLi(KaitaiStruct): - SEQ_FIELDS = ["count", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u2le() - self._debug['count']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.HiveBinCell.SubKeyListLi.Item(self._io, self, self._root) - _t_items._read() - self.items[i] = _t_items - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - class Item(KaitaiStruct): - SEQ_FIELDS = ["named_key_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['named_key_offset']['start'] = self._io.pos() - self.named_key_offset = self._io.read_u4le() - self._debug['named_key_offset']['end'] = self._io.pos() - - - - class NamedKey(KaitaiStruct): - - class NkFlags(Enum): - key_is_volatile = 1 - key_hive_exit = 2 - key_hive_entry = 4 - key_no_delete = 8 - key_sym_link = 16 - key_comp_name = 32 - key_prefef_handle = 64 - key_virt_mirrored = 128 - key_virt_target = 256 - key_virtual_store = 512 - unknown1 = 4096 - unknown2 = 16384 - SEQ_FIELDS = ["flags", "last_key_written_date_and_time", "unknown1", "parent_key_offset", "number_of_sub_keys", "number_of_volatile_sub_keys", "sub_keys_list_offset", "number_of_values", "values_list_offset", "security_key_offset", "class_name_offset", "largest_sub_key_name_size", "largest_sub_key_class_name_size", "largest_value_name_size", "largest_value_data_size", "unknown2", "key_name_size", "class_name_size", "unknown_string_size", "unknown_string"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.HiveBinCell.NamedKey.NkFlags, self._io.read_u2le()) - self._debug['flags']['end'] = self._io.pos() - self._debug['last_key_written_date_and_time']['start'] = self._io.pos() - self.last_key_written_date_and_time = self._root.Filetime(self._io, self, self._root) - self.last_key_written_date_and_time._read() - self._debug['last_key_written_date_and_time']['end'] = self._io.pos() - self._debug['unknown1']['start'] = self._io.pos() - self.unknown1 = self._io.read_u4le() - self._debug['unknown1']['end'] = self._io.pos() - self._debug['parent_key_offset']['start'] = self._io.pos() - self.parent_key_offset = self._io.read_u4le() - self._debug['parent_key_offset']['end'] = self._io.pos() - self._debug['number_of_sub_keys']['start'] = self._io.pos() - self.number_of_sub_keys = self._io.read_u4le() - self._debug['number_of_sub_keys']['end'] = self._io.pos() - self._debug['number_of_volatile_sub_keys']['start'] = self._io.pos() - self.number_of_volatile_sub_keys = self._io.read_u4le() - self._debug['number_of_volatile_sub_keys']['end'] = self._io.pos() - self._debug['sub_keys_list_offset']['start'] = self._io.pos() - self.sub_keys_list_offset = self._io.read_u4le() - self._debug['sub_keys_list_offset']['end'] = self._io.pos() - self._debug['number_of_values']['start'] = self._io.pos() - self.number_of_values = self._io.read_u4le() - self._debug['number_of_values']['end'] = self._io.pos() - self._debug['values_list_offset']['start'] = self._io.pos() - self.values_list_offset = self._io.read_u4le() - self._debug['values_list_offset']['end'] = self._io.pos() - self._debug['security_key_offset']['start'] = self._io.pos() - self.security_key_offset = self._io.read_u4le() - self._debug['security_key_offset']['end'] = self._io.pos() - self._debug['class_name_offset']['start'] = self._io.pos() - self.class_name_offset = self._io.read_u4le() - self._debug['class_name_offset']['end'] = self._io.pos() - self._debug['largest_sub_key_name_size']['start'] = self._io.pos() - self.largest_sub_key_name_size = self._io.read_u4le() - self._debug['largest_sub_key_name_size']['end'] = self._io.pos() - self._debug['largest_sub_key_class_name_size']['start'] = self._io.pos() - self.largest_sub_key_class_name_size = self._io.read_u4le() - self._debug['largest_sub_key_class_name_size']['end'] = self._io.pos() - self._debug['largest_value_name_size']['start'] = self._io.pos() - self.largest_value_name_size = self._io.read_u4le() - self._debug['largest_value_name_size']['end'] = self._io.pos() - self._debug['largest_value_data_size']['start'] = self._io.pos() - self.largest_value_data_size = self._io.read_u4le() - self._debug['largest_value_data_size']['end'] = self._io.pos() - self._debug['unknown2']['start'] = self._io.pos() - self.unknown2 = self._io.read_u4le() - self._debug['unknown2']['end'] = self._io.pos() - self._debug['key_name_size']['start'] = self._io.pos() - self.key_name_size = self._io.read_u2le() - self._debug['key_name_size']['end'] = self._io.pos() - self._debug['class_name_size']['start'] = self._io.pos() - self.class_name_size = self._io.read_u2le() - self._debug['class_name_size']['end'] = self._io.pos() - self._debug['unknown_string_size']['start'] = self._io.pos() - self.unknown_string_size = self._io.read_u4le() - self._debug['unknown_string_size']['end'] = self._io.pos() - self._debug['unknown_string']['start'] = self._io.pos() - self.unknown_string = (self._io.read_bytes(self.unknown_string_size)).decode(u"ascii") - self._debug['unknown_string']['end'] = self._io.pos() - - - class SubKeyListRi(KaitaiStruct): - SEQ_FIELDS = ["count", "items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['count']['start'] = self._io.pos() - self.count = self._io.read_u2le() - self._debug['count']['end'] = self._io.pos() - self._debug['items']['start'] = self._io.pos() - self.items = [None] * (self.count) - for i in range(self.count): - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.HiveBinCell.SubKeyListRi.Item(self._io, self, self._root) - _t_items._read() - self.items[i] = _t_items - self._debug['items']['arr'][i]['end'] = self._io.pos() - - self._debug['items']['end'] = self._io.pos() - - class Item(KaitaiStruct): - SEQ_FIELDS = ["sub_key_list_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sub_key_list_offset']['start'] = self._io.pos() - self.sub_key_list_offset = self._io.read_u4le() - self._debug['sub_key_list_offset']['end'] = self._io.pos() - - - - @property - def cell_size(self): - if hasattr(self, '_m_cell_size'): - return self._m_cell_size if hasattr(self, '_m_cell_size') else None - - self._m_cell_size = ((-1 if self.cell_size_raw < 0 else 1) * self.cell_size_raw) - return self._m_cell_size if hasattr(self, '_m_cell_size') else None - - @property - def is_allocated(self): - if hasattr(self, '_m_is_allocated'): - return self._m_is_allocated if hasattr(self, '_m_is_allocated') else None - - self._m_is_allocated = self.cell_size_raw < 0 - return self._m_is_allocated if hasattr(self, '_m_is_allocated') else None - - - class FileHeader(KaitaiStruct): - - class FileType(Enum): - normal = 0 - transaction_log = 1 - - class FileFormat(Enum): - direct_memory_load = 1 - SEQ_FIELDS = ["signature", "primary_sequence_number", "secondary_sequence_number", "last_modification_date_and_time", "major_version", "minor_version", "type", "format", "root_key_offset", "hive_bins_data_size", "clustering_factor", "unknown1", "unknown2", "checksum", "reserved", "boot_type", "boot_recover"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x72\x65\x67\x66") - self._debug['signature']['end'] = self._io.pos() - self._debug['primary_sequence_number']['start'] = self._io.pos() - self.primary_sequence_number = self._io.read_u4le() - self._debug['primary_sequence_number']['end'] = self._io.pos() - self._debug['secondary_sequence_number']['start'] = self._io.pos() - self.secondary_sequence_number = self._io.read_u4le() - self._debug['secondary_sequence_number']['end'] = self._io.pos() - self._debug['last_modification_date_and_time']['start'] = self._io.pos() - self.last_modification_date_and_time = self._root.Filetime(self._io, self, self._root) - self.last_modification_date_and_time._read() - self._debug['last_modification_date_and_time']['end'] = self._io.pos() - self._debug['major_version']['start'] = self._io.pos() - self.major_version = self._io.read_u4le() - self._debug['major_version']['end'] = self._io.pos() - self._debug['minor_version']['start'] = self._io.pos() - self.minor_version = self._io.read_u4le() - self._debug['minor_version']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.FileHeader.FileType, self._io.read_u4le()) - self._debug['type']['end'] = self._io.pos() - self._debug['format']['start'] = self._io.pos() - self.format = KaitaiStream.resolve_enum(self._root.FileHeader.FileFormat, self._io.read_u4le()) - self._debug['format']['end'] = self._io.pos() - self._debug['root_key_offset']['start'] = self._io.pos() - self.root_key_offset = self._io.read_u4le() - self._debug['root_key_offset']['end'] = self._io.pos() - self._debug['hive_bins_data_size']['start'] = self._io.pos() - self.hive_bins_data_size = self._io.read_u4le() - self._debug['hive_bins_data_size']['end'] = self._io.pos() - self._debug['clustering_factor']['start'] = self._io.pos() - self.clustering_factor = self._io.read_u4le() - self._debug['clustering_factor']['end'] = self._io.pos() - self._debug['unknown1']['start'] = self._io.pos() - self.unknown1 = self._io.read_bytes(64) - self._debug['unknown1']['end'] = self._io.pos() - self._debug['unknown2']['start'] = self._io.pos() - self.unknown2 = self._io.read_bytes(396) - self._debug['unknown2']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u4le() - self._debug['checksum']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(3576) - self._debug['reserved']['end'] = self._io.pos() - self._debug['boot_type']['start'] = self._io.pos() - self.boot_type = self._io.read_u4le() - self._debug['boot_type']['end'] = self._io.pos() - self._debug['boot_recover']['start'] = self._io.pos() - self.boot_recover = self._io.read_u4le() - self._debug['boot_recover']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/renderware_binary_stream.py b/python/examples/kaitai/renderware_binary_stream.py deleted file mode 100644 index 00b36934..00000000 --- a/python/examples/kaitai/renderware_binary_stream.py +++ /dev/null @@ -1,773 +0,0 @@ -# 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 -import collections - - -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 RenderwareBinaryStream(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/RenderWare_binary_stream_file - """ - - class Sections(Enum): - struct = 1 - string = 2 - extension = 3 - camera = 5 - texture = 6 - material = 7 - material_list = 8 - atomic_section = 9 - plane_section = 10 - world = 11 - spline = 12 - matrix = 13 - frame_list = 14 - geometry = 15 - clump = 16 - light = 18 - unicode_string = 19 - atomic = 20 - texture_native = 21 - texture_dictionary = 22 - animation_database = 23 - image = 24 - skin_animation = 25 - geometry_list = 26 - anim_animation = 27 - team = 28 - crowd = 29 - delta_morph_animation = 30 - right_to_render = 31 - multitexture_effect_native = 32 - multitexture_effect_dictionary = 33 - team_dictionary = 34 - platform_independent_texture_dictionary = 35 - table_of_contents = 36 - particle_standard_global_data = 37 - altpipe = 38 - platform_independent_peds = 39 - patch_mesh = 40 - chunk_group_start = 41 - chunk_group_end = 42 - uv_animation_dictionary = 43 - coll_tree = 44 - metrics_plg = 257 - spline_plg = 258 - stereo_plg = 259 - vrml_plg = 260 - morph_plg = 261 - pvs_plg = 262 - memory_leak_plg = 263 - animation_plg = 264 - gloss_plg = 265 - logo_plg = 266 - memory_info_plg = 267 - random_plg = 268 - png_image_plg = 269 - bone_plg = 270 - vrml_anim_plg = 271 - sky_mipmap_val = 272 - mrm_plg = 273 - lod_atomic_plg = 274 - me_plg = 275 - lightmap_plg = 276 - refine_plg = 277 - skin_plg = 278 - label_plg = 279 - particles_plg = 280 - geomtx_plg = 281 - synth_core_plg = 282 - stqpp_plg = 283 - part_pp_plg = 284 - collision_plg = 285 - hanim_plg = 286 - user_data_plg = 287 - material_effects_plg = 288 - particle_system_plg = 289 - delta_morph_plg = 290 - patch_plg = 291 - team_plg = 292 - crowd_pp_plg = 293 - mip_split_plg = 294 - anisotropy_plg = 295 - gcn_material_plg = 297 - geometric_pvs_plg = 298 - xbox_material_plg = 299 - multi_texture_plg = 300 - chain_plg = 301 - toon_plg = 302 - ptank_plg = 303 - particle_standard_plg = 304 - pds_plg = 305 - prtadv_plg = 306 - normal_map_plg = 307 - adc_plg = 308 - uv_animation_plg = 309 - character_set_plg = 384 - nohs_world_plg = 385 - import_util_plg = 386 - slerp_plg = 387 - optim_plg = 388 - tl_world_plg = 389 - database_plg = 390 - raytrace_plg = 391 - ray_plg = 392 - library_plg = 393 - plg_2d = 400 - tile_render_plg = 401 - jpeg_image_plg = 402 - tga_image_plg = 403 - gif_image_plg = 404 - quat_plg = 405 - spline_pvs_plg = 406 - mipmap_plg = 407 - mipmapk_plg = 408 - font_2d = 409 - intersection_plg = 410 - tiff_image_plg = 411 - pick_plg = 412 - bmp_image_plg = 413 - ras_image_plg = 414 - skin_fx_plg = 415 - vcat_plg = 416 - path_2d = 417 - brush_2d = 418 - object_2d = 419 - shape_2d = 420 - scene_2d = 421 - pick_region_2d = 422 - object_string_2d = 423 - animation_plg_2d = 424 - animation_2d = 425 - keyframe_2d = 432 - maestro_2d = 433 - barycentric = 434 - platform_independent_texture_dictionary_tk = 435 - toc_tk = 436 - tpl_tk = 437 - altpipe_tk = 438 - animation_tk = 439 - skin_split_tookit = 440 - compressed_key_tk = 441 - geometry_conditioning_plg = 442 - wing_plg = 443 - generic_pipeline_tk = 444 - lightmap_conversion_tk = 445 - filesystem_plg = 446 - dictionary_tk = 447 - uv_animation_linear = 448 - uv_animation_parameter = 449 - bin_mesh_plg = 1294 - native_data_plg = 1296 - zmodeler_lock = 61982 - atomic_visibility_distance = 39055872 - clump_visibility_distance = 39055873 - frame_visibility_distance = 39055874 - pipeline_set = 39056115 - unused_5 = 39056116 - texdictionary_link = 39056117 - specular_material = 39056118 - unused_8 = 39056119 - effect_2d = 39056120 - extra_vert_colour = 39056121 - collision_model = 39056122 - gta_hanim = 39056123 - reflection_material = 39056124 - breakable = 39056125 - frame = 39056126 - unused_16 = 39056127 - SEQ_FIELDS = ["code", "size", "version", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = KaitaiStream.resolve_enum(self._root.Sections, self._io.read_u4le()) - self._debug['code']['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['version']['start'] = self._io.pos() - self.version = self._io.read_u4le() - self._debug['version']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.code - if _on == self._root.Sections.geometry: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - elif _on == self._root.Sections.texture_dictionary: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - elif _on == self._root.Sections.geometry_list: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - elif _on == self._root.Sections.texture_native: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - elif _on == self._root.Sections.clump: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - elif _on == self._root.Sections.frame_list: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ListWithHeader(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.size) - self._debug['body']['end'] = self._io.pos() - - class StructClump(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/RpClump - """ - SEQ_FIELDS = ["num_atomics", "num_lights", "num_cameras"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_atomics']['start'] = self._io.pos() - self.num_atomics = self._io.read_u4le() - self._debug['num_atomics']['end'] = self._io.pos() - if self._parent.version >= 208896: - self._debug['num_lights']['start'] = self._io.pos() - self.num_lights = self._io.read_u4le() - self._debug['num_lights']['end'] = self._io.pos() - - if self._parent.version >= 208896: - self._debug['num_cameras']['start'] = self._io.pos() - self.num_cameras = self._io.read_u4le() - self._debug['num_cameras']['end'] = self._io.pos() - - - - class StructGeometry(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/RpGeometry - """ - SEQ_FIELDS = ["format", "num_triangles", "num_vertices", "num_morph_targets", "surf_prop", "geometry", "morph_targets"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['format']['start'] = self._io.pos() - self.format = self._io.read_u4le() - self._debug['format']['end'] = self._io.pos() - self._debug['num_triangles']['start'] = self._io.pos() - self.num_triangles = self._io.read_u4le() - self._debug['num_triangles']['end'] = self._io.pos() - self._debug['num_vertices']['start'] = self._io.pos() - self.num_vertices = self._io.read_u4le() - self._debug['num_vertices']['end'] = self._io.pos() - self._debug['num_morph_targets']['start'] = self._io.pos() - self.num_morph_targets = self._io.read_u4le() - self._debug['num_morph_targets']['end'] = self._io.pos() - if self._parent.version < 212992: - self._debug['surf_prop']['start'] = self._io.pos() - self.surf_prop = self._root.SurfaceProperties(self._io, self, self._root) - self.surf_prop._read() - self._debug['surf_prop']['end'] = self._io.pos() - - if not (self.is_native): - self._debug['geometry']['start'] = self._io.pos() - self.geometry = self._root.GeometryNonNative(self._io, self, self._root) - self.geometry._read() - self._debug['geometry']['end'] = self._io.pos() - - self._debug['morph_targets']['start'] = self._io.pos() - self.morph_targets = [None] * (self.num_morph_targets) - for i in range(self.num_morph_targets): - if not 'arr' in self._debug['morph_targets']: - self._debug['morph_targets']['arr'] = [] - self._debug['morph_targets']['arr'].append({'start': self._io.pos()}) - _t_morph_targets = self._root.MorphTarget(self._io, self, self._root) - _t_morph_targets._read() - self.morph_targets[i] = _t_morph_targets - self._debug['morph_targets']['arr'][i]['end'] = self._io.pos() - - self._debug['morph_targets']['end'] = self._io.pos() - - @property - def is_textured(self): - if hasattr(self, '_m_is_textured'): - return self._m_is_textured if hasattr(self, '_m_is_textured') else None - - self._m_is_textured = (self.format & 4) != 0 - return self._m_is_textured if hasattr(self, '_m_is_textured') else None - - @property - def is_prelit(self): - if hasattr(self, '_m_is_prelit'): - return self._m_is_prelit if hasattr(self, '_m_is_prelit') else None - - self._m_is_prelit = (self.format & 8) != 0 - return self._m_is_prelit if hasattr(self, '_m_is_prelit') else None - - @property - def is_textured2(self): - if hasattr(self, '_m_is_textured2'): - return self._m_is_textured2 if hasattr(self, '_m_is_textured2') else None - - self._m_is_textured2 = (self.format & 128) != 0 - return self._m_is_textured2 if hasattr(self, '_m_is_textured2') else None - - @property - def is_native(self): - if hasattr(self, '_m_is_native'): - return self._m_is_native if hasattr(self, '_m_is_native') else None - - self._m_is_native = (self.format & 16777216) != 0 - return self._m_is_native if hasattr(self, '_m_is_native') else None - - - class GeometryNonNative(KaitaiStruct): - SEQ_FIELDS = ["prelit_colors", "tex_coords", "triangles"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - if self._parent.is_prelit: - self._debug['prelit_colors']['start'] = self._io.pos() - self.prelit_colors = [None] * (self._parent.num_vertices) - for i in range(self._parent.num_vertices): - if not 'arr' in self._debug['prelit_colors']: - self._debug['prelit_colors']['arr'] = [] - self._debug['prelit_colors']['arr'].append({'start': self._io.pos()}) - _t_prelit_colors = self._root.Rgba(self._io, self, self._root) - _t_prelit_colors._read() - self.prelit_colors[i] = _t_prelit_colors - self._debug['prelit_colors']['arr'][i]['end'] = self._io.pos() - - self._debug['prelit_colors']['end'] = self._io.pos() - - if ((self._parent.is_textured) or (self._parent.is_textured2)) : - self._debug['tex_coords']['start'] = self._io.pos() - self.tex_coords = [None] * (self._parent.num_vertices) - for i in range(self._parent.num_vertices): - if not 'arr' in self._debug['tex_coords']: - self._debug['tex_coords']['arr'] = [] - self._debug['tex_coords']['arr'].append({'start': self._io.pos()}) - _t_tex_coords = self._root.TexCoord(self._io, self, self._root) - _t_tex_coords._read() - self.tex_coords[i] = _t_tex_coords - self._debug['tex_coords']['arr'][i]['end'] = self._io.pos() - - self._debug['tex_coords']['end'] = self._io.pos() - - self._debug['triangles']['start'] = self._io.pos() - self.triangles = [None] * (self._parent.num_triangles) - for i in range(self._parent.num_triangles): - if not 'arr' in self._debug['triangles']: - self._debug['triangles']['arr'] = [] - self._debug['triangles']['arr'].append({'start': self._io.pos()}) - _t_triangles = self._root.Triangle(self._io, self, self._root) - _t_triangles._read() - self.triangles[i] = _t_triangles - self._debug['triangles']['arr'][i]['end'] = self._io.pos() - - self._debug['triangles']['end'] = self._io.pos() - - - class StructGeometryList(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/Geometry_List_(RW_Section)#Structure - """ - SEQ_FIELDS = ["num_geometries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_geometries']['start'] = self._io.pos() - self.num_geometries = self._io.read_u4le() - self._debug['num_geometries']['end'] = self._io.pos() - - - class Rgba(KaitaiStruct): - SEQ_FIELDS = ["r", "g", "b", "a"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['r']['start'] = self._io.pos() - self.r = self._io.read_u1() - self._debug['r']['end'] = self._io.pos() - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_u1() - self._debug['g']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - self._debug['a']['start'] = self._io.pos() - self.a = self._io.read_u1() - self._debug['a']['end'] = self._io.pos() - - - class Sphere(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z", "radius"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f4le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f4le() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_f4le() - self._debug['z']['end'] = self._io.pos() - self._debug['radius']['start'] = self._io.pos() - self.radius = self._io.read_f4le() - self._debug['radius']['end'] = self._io.pos() - - - class MorphTarget(KaitaiStruct): - SEQ_FIELDS = ["bounding_sphere", "has_vertices", "has_normals", "vertices", "normals"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_sphere']['start'] = self._io.pos() - self.bounding_sphere = self._root.Sphere(self._io, self, self._root) - self.bounding_sphere._read() - self._debug['bounding_sphere']['end'] = self._io.pos() - self._debug['has_vertices']['start'] = self._io.pos() - self.has_vertices = self._io.read_u4le() - self._debug['has_vertices']['end'] = self._io.pos() - self._debug['has_normals']['start'] = self._io.pos() - self.has_normals = self._io.read_u4le() - self._debug['has_normals']['end'] = self._io.pos() - if self.has_vertices != 0: - self._debug['vertices']['start'] = self._io.pos() - self.vertices = [None] * (self._parent.num_vertices) - for i in range(self._parent.num_vertices): - if not 'arr' in self._debug['vertices']: - self._debug['vertices']['arr'] = [] - self._debug['vertices']['arr'].append({'start': self._io.pos()}) - _t_vertices = self._root.Vector3d(self._io, self, self._root) - _t_vertices._read() - self.vertices[i] = _t_vertices - self._debug['vertices']['arr'][i]['end'] = self._io.pos() - - self._debug['vertices']['end'] = self._io.pos() - - if self.has_normals != 0: - self._debug['normals']['start'] = self._io.pos() - self.normals = [None] * (self._parent.num_vertices) - for i in range(self._parent.num_vertices): - if not 'arr' in self._debug['normals']: - self._debug['normals']['arr'] = [] - self._debug['normals']['arr'].append({'start': self._io.pos()}) - _t_normals = self._root.Vector3d(self._io, self, self._root) - _t_normals._read() - self.normals[i] = _t_normals - self._debug['normals']['arr'][i]['end'] = self._io.pos() - - self._debug['normals']['end'] = self._io.pos() - - - - class SurfaceProperties(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/RpGeometry - """ - SEQ_FIELDS = ["ambient", "specular", "diffuse"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ambient']['start'] = self._io.pos() - self.ambient = self._io.read_f4le() - self._debug['ambient']['end'] = self._io.pos() - self._debug['specular']['start'] = self._io.pos() - self.specular = self._io.read_f4le() - self._debug['specular']['end'] = self._io.pos() - self._debug['diffuse']['start'] = self._io.pos() - self.diffuse = self._io.read_f4le() - self._debug['diffuse']['end'] = self._io.pos() - - - class StructFrameList(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/Frame_List_(RW_Section)#Structure - """ - SEQ_FIELDS = ["num_frames", "frames"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_frames']['start'] = self._io.pos() - self.num_frames = self._io.read_u4le() - self._debug['num_frames']['end'] = self._io.pos() - self._debug['frames']['start'] = self._io.pos() - self.frames = [None] * (self.num_frames) - for i in range(self.num_frames): - if not 'arr' in self._debug['frames']: - self._debug['frames']['arr'] = [] - self._debug['frames']['arr'].append({'start': self._io.pos()}) - _t_frames = self._root.Frame(self._io, self, self._root) - _t_frames._read() - self.frames[i] = _t_frames - self._debug['frames']['arr'][i]['end'] = self._io.pos() - - self._debug['frames']['end'] = self._io.pos() - - - class Matrix(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/Frame_List_(RW_Section)#Structure - """ - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entries']['start'] = self._io.pos() - self.entries = [None] * (3) - for i in range(3): - if not 'arr' in self._debug['entries']: - self._debug['entries']['arr'] = [] - self._debug['entries']['arr'].append({'start': self._io.pos()}) - _t_entries = self._root.Vector3d(self._io, self, self._root) - _t_entries._read() - self.entries[i] = _t_entries - self._debug['entries']['arr'][i]['end'] = self._io.pos() - - self._debug['entries']['end'] = self._io.pos() - - - class Vector3d(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/Frame_List_(RW_Section)#Structure - """ - SEQ_FIELDS = ["x", "y", "z"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f4le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f4le() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_f4le() - self._debug['z']['end'] = self._io.pos() - - - class ListWithHeader(KaitaiStruct): - """Typical structure used by many data types in RenderWare binary - stream. Substream contains a list of binary stream entries, - first entry always has type "struct" and carries some specific - binary data it in, determined by the type of parent. All other - entries, beside the first one, are normal, self-describing - records. - """ - SEQ_FIELDS = ["code", "header_size", "version", "header", "entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = self._io.ensure_fixed_contents(b"\x01\x00\x00\x00") - self._debug['code']['end'] = self._io.pos() - 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['version']['start'] = self._io.pos() - self.version = self._io.read_u4le() - self._debug['version']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - _on = self._parent.code - if _on == self._root.Sections.geometry: - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.StructGeometry(io, self, self._root) - self.header._read() - elif _on == self._root.Sections.texture_dictionary: - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.StructTextureDictionary(io, self, self._root) - self.header._read() - elif _on == self._root.Sections.geometry_list: - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.StructGeometryList(io, self, self._root) - self.header._read() - elif _on == self._root.Sections.clump: - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.StructClump(io, self, self._root) - self.header._read() - elif _on == self._root.Sections.frame_list: - self._raw_header = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.StructFrameList(io, 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() - - - class Triangle(KaitaiStruct): - SEQ_FIELDS = ["vertex2", "vertex1", "material_id", "vertex3"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['vertex2']['start'] = self._io.pos() - self.vertex2 = self._io.read_u2le() - self._debug['vertex2']['end'] = self._io.pos() - self._debug['vertex1']['start'] = self._io.pos() - self.vertex1 = self._io.read_u2le() - self._debug['vertex1']['end'] = self._io.pos() - self._debug['material_id']['start'] = self._io.pos() - self.material_id = self._io.read_u2le() - self._debug['material_id']['end'] = self._io.pos() - self._debug['vertex3']['start'] = self._io.pos() - self.vertex3 = self._io.read_u2le() - self._debug['vertex3']['end'] = self._io.pos() - - - class Frame(KaitaiStruct): - """ - .. seealso:: - Source - https://www.gtamodding.com/wiki/Frame_List_(RW_Section)#Structure - """ - SEQ_FIELDS = ["rotation_matrix", "position", "cur_frame_idx", "matrix_creation_flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['rotation_matrix']['start'] = self._io.pos() - self.rotation_matrix = self._root.Matrix(self._io, self, self._root) - self.rotation_matrix._read() - self._debug['rotation_matrix']['end'] = self._io.pos() - self._debug['position']['start'] = self._io.pos() - self.position = self._root.Vector3d(self._io, self, self._root) - self.position._read() - self._debug['position']['end'] = self._io.pos() - self._debug['cur_frame_idx']['start'] = self._io.pos() - self.cur_frame_idx = self._io.read_s4le() - self._debug['cur_frame_idx']['end'] = self._io.pos() - self._debug['matrix_creation_flags']['start'] = self._io.pos() - self.matrix_creation_flags = self._io.read_u4le() - self._debug['matrix_creation_flags']['end'] = self._io.pos() - - - class TexCoord(KaitaiStruct): - SEQ_FIELDS = ["u", "v"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['u']['start'] = self._io.pos() - self.u = self._io.read_f4le() - self._debug['u']['end'] = self._io.pos() - self._debug['v']['start'] = self._io.pos() - self.v = self._io.read_f4le() - self._debug['v']['end'] = self._io.pos() - - - class StructTextureDictionary(KaitaiStruct): - SEQ_FIELDS = ["num_textures"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_textures']['start'] = self._io.pos() - self.num_textures = self._io.read_u4le() - self._debug['num_textures']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/rtcp_payload.py b/python/examples/kaitai/rtcp_payload.py deleted file mode 100644 index c10066d1..00000000 --- a/python/examples/kaitai/rtcp_payload.py +++ /dev/null @@ -1,578 +0,0 @@ -# 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 -import collections - - -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 RtcpPayload(KaitaiStruct): - """RTCP is the Real-Time Control Protocol. - - .. seealso:: - Source - https://tools.ietf.org/html/rfc3550 - """ - - class PayloadType(Enum): - fir = 192 - nack = 193 - ij = 195 - sr = 200 - rr = 201 - sdes = 202 - bye = 203 - app = 204 - rtpfb = 205 - psfb = 206 - xr = 207 - avb = 208 - rsi = 209 - - class SdesSubtype(Enum): - pad = 0 - cname = 1 - name = 2 - email = 3 - phone = 4 - loc = 5 - tool = 6 - note = 7 - priv = 8 - - class PsfbSubtype(Enum): - pli = 1 - sli = 2 - rpsi = 3 - fir = 4 - tstr = 5 - tstn = 6 - vbcm = 7 - afb = 15 - - class RtpfbSubtype(Enum): - nack = 1 - tmmbr = 3 - tmmbn = 4 - rrr = 5 - transport_feedback = 15 - SEQ_FIELDS = ["rtcp_packets"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['rtcp_packets']['start'] = self._io.pos() - self.rtcp_packets = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['rtcp_packets']: - self._debug['rtcp_packets']['arr'] = [] - self._debug['rtcp_packets']['arr'].append({'start': self._io.pos()}) - _t_rtcp_packets = self._root.RtcpPacket(self._io, self, self._root) - _t_rtcp_packets._read() - self.rtcp_packets.append(_t_rtcp_packets) - self._debug['rtcp_packets']['arr'][len(self.rtcp_packets) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['rtcp_packets']['end'] = self._io.pos() - - class PsfbAfbRembPacket(KaitaiStruct): - SEQ_FIELDS = ["num_ssrc", "br_exp", "br_mantissa", "ssrc_list"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_ssrc']['start'] = self._io.pos() - self.num_ssrc = self._io.read_u1() - self._debug['num_ssrc']['end'] = self._io.pos() - self._debug['br_exp']['start'] = self._io.pos() - self.br_exp = self._io.read_bits_int(6) - self._debug['br_exp']['end'] = self._io.pos() - self._debug['br_mantissa']['start'] = self._io.pos() - self.br_mantissa = self._io.read_bits_int(18) - self._debug['br_mantissa']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['ssrc_list']['start'] = self._io.pos() - self.ssrc_list = [None] * (self.num_ssrc) - for i in range(self.num_ssrc): - if not 'arr' in self._debug['ssrc_list']: - self._debug['ssrc_list']['arr'] = [] - self._debug['ssrc_list']['arr'].append({'start': self._io.pos()}) - self.ssrc_list[i] = self._io.read_u4be() - self._debug['ssrc_list']['arr'][i]['end'] = self._io.pos() - - self._debug['ssrc_list']['end'] = self._io.pos() - - @property - def max_total_bitrate(self): - if hasattr(self, '_m_max_total_bitrate'): - return self._m_max_total_bitrate if hasattr(self, '_m_max_total_bitrate') else None - - self._m_max_total_bitrate = (self.br_mantissa * (1 << self.br_exp)) - return self._m_max_total_bitrate if hasattr(self, '_m_max_total_bitrate') else None - - - class SrPacket(KaitaiStruct): - SEQ_FIELDS = ["ssrc", "ntp_msw", "ntp_lsw", "rtp_timestamp", "sender_packet_count", "sender_octet_count", "report_block"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - self._debug['ntp_msw']['start'] = self._io.pos() - self.ntp_msw = self._io.read_u4be() - self._debug['ntp_msw']['end'] = self._io.pos() - self._debug['ntp_lsw']['start'] = self._io.pos() - self.ntp_lsw = self._io.read_u4be() - self._debug['ntp_lsw']['end'] = self._io.pos() - self._debug['rtp_timestamp']['start'] = self._io.pos() - self.rtp_timestamp = self._io.read_u4be() - self._debug['rtp_timestamp']['end'] = self._io.pos() - self._debug['sender_packet_count']['start'] = self._io.pos() - self.sender_packet_count = self._io.read_u4be() - self._debug['sender_packet_count']['end'] = self._io.pos() - self._debug['sender_octet_count']['start'] = self._io.pos() - self.sender_octet_count = self._io.read_u4be() - self._debug['sender_octet_count']['end'] = self._io.pos() - self._debug['report_block']['start'] = self._io.pos() - self.report_block = [None] * (self._parent.subtype) - for i in range(self._parent.subtype): - if not 'arr' in self._debug['report_block']: - self._debug['report_block']['arr'] = [] - self._debug['report_block']['arr'].append({'start': self._io.pos()}) - _t_report_block = self._root.ReportBlock(self._io, self, self._root) - _t_report_block._read() - self.report_block[i] = _t_report_block - self._debug['report_block']['arr'][i]['end'] = self._io.pos() - - self._debug['report_block']['end'] = self._io.pos() - - @property - def ntp(self): - if hasattr(self, '_m_ntp'): - return self._m_ntp if hasattr(self, '_m_ntp') else None - - self._m_ntp = ((self.ntp_msw << 32) & self.ntp_lsw) - return self._m_ntp if hasattr(self, '_m_ntp') else None - - - class RrPacket(KaitaiStruct): - SEQ_FIELDS = ["ssrc", "report_block"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - self._debug['report_block']['start'] = self._io.pos() - self.report_block = [None] * (self._parent.subtype) - for i in range(self._parent.subtype): - if not 'arr' in self._debug['report_block']: - self._debug['report_block']['arr'] = [] - self._debug['report_block']['arr'].append({'start': self._io.pos()}) - _t_report_block = self._root.ReportBlock(self._io, self, self._root) - _t_report_block._read() - self.report_block[i] = _t_report_block - self._debug['report_block']['arr'][i]['end'] = self._io.pos() - - self._debug['report_block']['end'] = self._io.pos() - - - class RtcpPacket(KaitaiStruct): - SEQ_FIELDS = ["version", "padding", "subtype", "payload_type", "length", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_bits_int(2) - self._debug['version']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bits_int(1) != 0 - self._debug['padding']['end'] = self._io.pos() - self._debug['subtype']['start'] = self._io.pos() - self.subtype = self._io.read_bits_int(5) - self._debug['subtype']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['payload_type']['start'] = self._io.pos() - self.payload_type = KaitaiStream.resolve_enum(self._root.PayloadType, self._io.read_u1()) - self._debug['payload_type']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.payload_type - if _on == self._root.PayloadType.sr: - self._raw_body = self._io.read_bytes((4 * self.length)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SrPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PayloadType.psfb: - self._raw_body = self._io.read_bytes((4 * self.length)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PsfbPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PayloadType.rr: - self._raw_body = self._io.read_bytes((4 * self.length)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RrPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PayloadType.rtpfb: - self._raw_body = self._io.read_bytes((4 * self.length)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RtpfbPacket(io, self, self._root) - self.body._read() - elif _on == self._root.PayloadType.sdes: - self._raw_body = self._io.read_bytes((4 * self.length)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SdesPacket(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes((4 * self.length)) - self._debug['body']['end'] = self._io.pos() - - - class SdesTlv(KaitaiStruct): - SEQ_FIELDS = ["type", "length", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.SdesSubtype, self._io.read_u1()) - self._debug['type']['end'] = self._io.pos() - if self.type != self._root.SdesSubtype.pad: - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u1() - self._debug['length']['end'] = self._io.pos() - - if self.type != self._root.SdesSubtype.pad: - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.length) - self._debug['value']['end'] = self._io.pos() - - - - class ReportBlock(KaitaiStruct): - SEQ_FIELDS = ["ssrc_source", "lost_val", "highest_seq_num_received", "interarrival_jitter", "lsr", "dlsr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc_source']['start'] = self._io.pos() - self.ssrc_source = self._io.read_u4be() - self._debug['ssrc_source']['end'] = self._io.pos() - self._debug['lost_val']['start'] = self._io.pos() - self.lost_val = self._io.read_u1() - self._debug['lost_val']['end'] = self._io.pos() - self._debug['highest_seq_num_received']['start'] = self._io.pos() - self.highest_seq_num_received = self._io.read_u4be() - self._debug['highest_seq_num_received']['end'] = self._io.pos() - self._debug['interarrival_jitter']['start'] = self._io.pos() - self.interarrival_jitter = self._io.read_u4be() - self._debug['interarrival_jitter']['end'] = self._io.pos() - self._debug['lsr']['start'] = self._io.pos() - self.lsr = self._io.read_u4be() - self._debug['lsr']['end'] = self._io.pos() - self._debug['dlsr']['start'] = self._io.pos() - self.dlsr = self._io.read_u4be() - self._debug['dlsr']['end'] = self._io.pos() - - @property - def fraction_lost(self): - if hasattr(self, '_m_fraction_lost'): - return self._m_fraction_lost if hasattr(self, '_m_fraction_lost') else None - - self._m_fraction_lost = (self.lost_val >> 24) - return self._m_fraction_lost if hasattr(self, '_m_fraction_lost') else None - - @property - def cumulative_packets_lost(self): - if hasattr(self, '_m_cumulative_packets_lost'): - return self._m_cumulative_packets_lost if hasattr(self, '_m_cumulative_packets_lost') else None - - self._m_cumulative_packets_lost = (self.lost_val & 16777215) - return self._m_cumulative_packets_lost if hasattr(self, '_m_cumulative_packets_lost') else None - - - class RtpfbTransportFeedbackPacket(KaitaiStruct): - SEQ_FIELDS = ["base_sequence_number", "packet_status_count", "b4", "remaining"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['base_sequence_number']['start'] = self._io.pos() - self.base_sequence_number = self._io.read_u2be() - self._debug['base_sequence_number']['end'] = self._io.pos() - self._debug['packet_status_count']['start'] = self._io.pos() - self.packet_status_count = self._io.read_u2be() - self._debug['packet_status_count']['end'] = self._io.pos() - self._debug['b4']['start'] = self._io.pos() - self.b4 = self._io.read_u4be() - self._debug['b4']['end'] = self._io.pos() - self._debug['remaining']['start'] = self._io.pos() - self.remaining = self._io.read_bytes_full() - self._debug['remaining']['end'] = self._io.pos() - - @property - def reference_time(self): - if hasattr(self, '_m_reference_time'): - return self._m_reference_time if hasattr(self, '_m_reference_time') else None - - self._m_reference_time = (self.b4 >> 8) - return self._m_reference_time if hasattr(self, '_m_reference_time') else None - - @property - def fb_pkt_count(self): - if hasattr(self, '_m_fb_pkt_count'): - return self._m_fb_pkt_count if hasattr(self, '_m_fb_pkt_count') else None - - self._m_fb_pkt_count = (self.b4 & 255) - return self._m_fb_pkt_count if hasattr(self, '_m_fb_pkt_count') else None - - @property - def packet_status(self): - if hasattr(self, '_m_packet_status'): - return self._m_packet_status if hasattr(self, '_m_packet_status') else None - - self._debug['_m_packet_status']['start'] = self._io.pos() - self._m_packet_status = self._io.read_bytes(0) - self._debug['_m_packet_status']['end'] = self._io.pos() - return self._m_packet_status if hasattr(self, '_m_packet_status') else None - - @property - def recv_delta(self): - if hasattr(self, '_m_recv_delta'): - return self._m_recv_delta if hasattr(self, '_m_recv_delta') else None - - self._debug['_m_recv_delta']['start'] = self._io.pos() - self._m_recv_delta = self._io.read_bytes(0) - self._debug['_m_recv_delta']['end'] = self._io.pos() - return self._m_recv_delta if hasattr(self, '_m_recv_delta') else None - - - class PsfbPacket(KaitaiStruct): - SEQ_FIELDS = ["ssrc", "ssrc_media_source", "fci_block"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - self._debug['ssrc_media_source']['start'] = self._io.pos() - self.ssrc_media_source = self._io.read_u4be() - self._debug['ssrc_media_source']['end'] = self._io.pos() - self._debug['fci_block']['start'] = self._io.pos() - _on = self.fmt - if _on == self._root.PsfbSubtype.afb: - self._raw_fci_block = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_fci_block)) - self.fci_block = self._root.PsfbAfbPacket(io, self, self._root) - self.fci_block._read() - else: - self.fci_block = self._io.read_bytes_full() - self._debug['fci_block']['end'] = self._io.pos() - - @property - def fmt(self): - if hasattr(self, '_m_fmt'): - return self._m_fmt if hasattr(self, '_m_fmt') else None - - self._m_fmt = KaitaiStream.resolve_enum(self._root.PsfbSubtype, self._parent.subtype) - return self._m_fmt if hasattr(self, '_m_fmt') else None - - - class SourceChunk(KaitaiStruct): - SEQ_FIELDS = ["ssrc", "sdes_tlv"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - self._debug['sdes_tlv']['start'] = self._io.pos() - self.sdes_tlv = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['sdes_tlv']: - self._debug['sdes_tlv']['arr'] = [] - self._debug['sdes_tlv']['arr'].append({'start': self._io.pos()}) - _t_sdes_tlv = self._root.SdesTlv(self._io, self, self._root) - _t_sdes_tlv._read() - self.sdes_tlv.append(_t_sdes_tlv) - self._debug['sdes_tlv']['arr'][len(self.sdes_tlv) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['sdes_tlv']['end'] = self._io.pos() - - - class SdesPacket(KaitaiStruct): - SEQ_FIELDS = ["source_chunk"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['source_chunk']['start'] = self._io.pos() - self.source_chunk = [None] * (self.source_count) - for i in range(self.source_count): - if not 'arr' in self._debug['source_chunk']: - self._debug['source_chunk']['arr'] = [] - self._debug['source_chunk']['arr'].append({'start': self._io.pos()}) - _t_source_chunk = self._root.SourceChunk(self._io, self, self._root) - _t_source_chunk._read() - self.source_chunk[i] = _t_source_chunk - self._debug['source_chunk']['arr'][i]['end'] = self._io.pos() - - self._debug['source_chunk']['end'] = self._io.pos() - - @property - def source_count(self): - if hasattr(self, '_m_source_count'): - return self._m_source_count if hasattr(self, '_m_source_count') else None - - self._m_source_count = self._parent.subtype - return self._m_source_count if hasattr(self, '_m_source_count') else None - - - class RtpfbPacket(KaitaiStruct): - SEQ_FIELDS = ["ssrc", "ssrc_media_source", "fci_block"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - self._debug['ssrc_media_source']['start'] = self._io.pos() - self.ssrc_media_source = self._io.read_u4be() - self._debug['ssrc_media_source']['end'] = self._io.pos() - self._debug['fci_block']['start'] = self._io.pos() - _on = self.fmt - if _on == self._root.RtpfbSubtype.transport_feedback: - self._raw_fci_block = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_fci_block)) - self.fci_block = self._root.RtpfbTransportFeedbackPacket(io, self, self._root) - self.fci_block._read() - else: - self.fci_block = self._io.read_bytes_full() - self._debug['fci_block']['end'] = self._io.pos() - - @property - def fmt(self): - if hasattr(self, '_m_fmt'): - return self._m_fmt if hasattr(self, '_m_fmt') else None - - self._m_fmt = KaitaiStream.resolve_enum(self._root.RtpfbSubtype, self._parent.subtype) - return self._m_fmt if hasattr(self, '_m_fmt') else None - - - class PacketStatusChunk(KaitaiStruct): - SEQ_FIELDS = ["t", "s2", "s1", "rle", "symbol_list"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['t']['start'] = self._io.pos() - self.t = self._io.read_bits_int(1) != 0 - self._debug['t']['end'] = self._io.pos() - if int(self.t) == 0: - self._debug['s2']['start'] = self._io.pos() - self.s2 = self._io.read_bits_int(2) - self._debug['s2']['end'] = self._io.pos() - - if int(self.t) == 1: - self._debug['s1']['start'] = self._io.pos() - self.s1 = self._io.read_bits_int(1) != 0 - self._debug['s1']['end'] = self._io.pos() - - if int(self.t) == 0: - self._debug['rle']['start'] = self._io.pos() - self.rle = self._io.read_bits_int(13) - self._debug['rle']['end'] = self._io.pos() - - if int(self.t) == 1: - self._debug['symbol_list']['start'] = self._io.pos() - self.symbol_list = self._io.read_bits_int(14) - self._debug['symbol_list']['end'] = self._io.pos() - - - @property - def s(self): - if hasattr(self, '_m_s'): - return self._m_s if hasattr(self, '_m_s') else None - - self._m_s = (self.s2 if int(self.t) == 0 else (1 if int(self.s1) == 0 else 0)) - return self._m_s if hasattr(self, '_m_s') else None - - - class PsfbAfbPacket(KaitaiStruct): - SEQ_FIELDS = ["uid", "contents"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['uid']['start'] = self._io.pos() - self.uid = self._io.read_u4be() - self._debug['uid']['end'] = self._io.pos() - self._debug['contents']['start'] = self._io.pos() - _on = self.uid - if _on == 1380273474: - self._raw_contents = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_contents)) - self.contents = self._root.PsfbAfbRembPacket(io, self, self._root) - self.contents._read() - else: - self.contents = self._io.read_bytes_full() - self._debug['contents']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/rtp_packet.py b/python/examples/kaitai/rtp_packet.py deleted file mode 100644 index cedcd0f9..00000000 --- a/python/examples/kaitai/rtp_packet.py +++ /dev/null @@ -1,149 +0,0 @@ -# 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 -import collections - - -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 RtpPacket(KaitaiStruct): - """The Real-time Transport Protocol (RTP) is a widely used network - protocol for transmitting audio or video. It usually works with the - RTP Control Protocol (RTCP). The transmission can be based on - Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). - """ - - class PayloadTypeEnum(Enum): - pcmu = 0 - reserved1 = 1 - reserved2 = 2 - gsm = 3 - g723 = 4 - dvi4_1 = 5 - dvi4_2 = 6 - lpc = 7 - pama = 8 - g722 = 9 - l16_1 = 10 - l16_2 = 11 - qcelp = 12 - cn = 13 - mpa = 14 - g728 = 15 - dvi4_3 = 16 - dvi4_4 = 17 - g729 = 18 - reserved3 = 19 - unassigned1 = 20 - unassigned2 = 21 - unassigned3 = 22 - unassigned4 = 23 - unassigned5 = 24 - celb = 25 - jpeg = 26 - unassigned6 = 27 - nv = 28 - unassigned7 = 29 - unassigned8 = 30 - h261 = 31 - mpv = 32 - mp2t = 33 - h263 = 34 - mpeg_ps = 96 - SEQ_FIELDS = ["version", "has_padding", "has_extension", "csrc_count", "marker", "payload_type", "sequence_number", "timestamp", "ssrc", "header_extension", "data", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_bits_int(2) - self._debug['version']['end'] = self._io.pos() - self._debug['has_padding']['start'] = self._io.pos() - self.has_padding = self._io.read_bits_int(1) != 0 - self._debug['has_padding']['end'] = self._io.pos() - self._debug['has_extension']['start'] = self._io.pos() - self.has_extension = self._io.read_bits_int(1) != 0 - self._debug['has_extension']['end'] = self._io.pos() - self._debug['csrc_count']['start'] = self._io.pos() - self.csrc_count = self._io.read_bits_int(4) - self._debug['csrc_count']['end'] = self._io.pos() - self._debug['marker']['start'] = self._io.pos() - self.marker = self._io.read_bits_int(1) != 0 - self._debug['marker']['end'] = self._io.pos() - self._debug['payload_type']['start'] = self._io.pos() - self.payload_type = KaitaiStream.resolve_enum(self._root.PayloadTypeEnum, self._io.read_bits_int(7)) - self._debug['payload_type']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['sequence_number']['start'] = self._io.pos() - self.sequence_number = self._io.read_u2be() - self._debug['sequence_number']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4be() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['ssrc']['start'] = self._io.pos() - self.ssrc = self._io.read_u4be() - self._debug['ssrc']['end'] = self._io.pos() - if self.has_extension: - self._debug['header_extension']['start'] = self._io.pos() - self.header_extension = self._root.HeaderExtention(self._io, self, self._root) - self.header_extension._read() - self._debug['header_extension']['end'] = self._io.pos() - - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(((self._io.size() - self._io.pos()) - self.len_padding)) - self._debug['data']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes(self.len_padding) - self._debug['padding']['end'] = self._io.pos() - - class HeaderExtention(KaitaiStruct): - SEQ_FIELDS = ["id", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = self._io.read_u2be() - self._debug['id']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - - - @property - def len_padding_if_exists(self): - """If padding bit is enabled, last byte of data contains number of - bytes appended to the payload as padding. - """ - if hasattr(self, '_m_len_padding_if_exists'): - return self._m_len_padding_if_exists if hasattr(self, '_m_len_padding_if_exists') else None - - if self.has_padding: - _pos = self._io.pos() - self._io.seek((self._io.size() - 1)) - self._debug['_m_len_padding_if_exists']['start'] = self._io.pos() - self._m_len_padding_if_exists = self._io.read_u1() - self._debug['_m_len_padding_if_exists']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_len_padding_if_exists if hasattr(self, '_m_len_padding_if_exists') else None - - @property - def len_padding(self): - """Always returns number of padding bytes to in the payload.""" - if hasattr(self, '_m_len_padding'): - return self._m_len_padding if hasattr(self, '_m_len_padding') else None - - self._m_len_padding = (self.len_padding_if_exists if self.has_padding else 0) - return self._m_len_padding if hasattr(self, '_m_len_padding') else None - - diff --git a/python/examples/kaitai/ruby_marshal.py b/python/examples/kaitai/ruby_marshal.py deleted file mode 100644 index 92deee38..00000000 --- a/python/examples/kaitai/ruby_marshal.py +++ /dev/null @@ -1,416 +0,0 @@ -# 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 -import collections - - -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 RubyMarshal(KaitaiStruct): - """Ruby's Marshal module allows serialization and deserialization of - many standard and arbitrary Ruby objects in a compact binary - format. It is relatively fast, available in stdlibs standard and - allows conservation of language-specific properties (such as symbols - or encoding-aware strings). - - Feature-wise, it is comparable to other language-specific - implementations, such as: - - * Java's - [Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html) - * .NET - [BinaryFormatter](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) - * Python's - [marshal](https://docs.python.org/3/library/marshal.html), - [pickle](https://docs.python.org/3/library/pickle.html) and - [shelve](https://docs.python.org/3/library/shelve.html) - - From internal perspective, serialized stream consists of a simple - magic header and a record. - - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Stream+Format - """ - - class Codes(Enum): - ruby_string = 34 - const_nil = 48 - ruby_symbol = 58 - ruby_symbol_link = 59 - const_false = 70 - instance_var = 73 - ruby_struct = 83 - const_true = 84 - ruby_array = 91 - packed_int = 105 - bignum = 108 - ruby_hash = 123 - SEQ_FIELDS = ["version", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.ensure_fixed_contents(b"\x04\x08") - self._debug['version']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = self._root.Record(self._io, self, self._root) - self.records._read() - self._debug['records']['end'] = self._io.pos() - - class RubyArray(KaitaiStruct): - SEQ_FIELDS = ["num_elements", "elements"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_elements']['start'] = self._io.pos() - self.num_elements = self._root.PackedInt(self._io, self, self._root) - self.num_elements._read() - self._debug['num_elements']['end'] = self._io.pos() - self._debug['elements']['start'] = self._io.pos() - self.elements = [None] * (self.num_elements.value) - for i in range(self.num_elements.value): - if not 'arr' in self._debug['elements']: - self._debug['elements']['arr'] = [] - self._debug['elements']['arr'].append({'start': self._io.pos()}) - _t_elements = self._root.Record(self._io, self, self._root) - _t_elements._read() - self.elements[i] = _t_elements - self._debug['elements']['arr'][i]['end'] = self._io.pos() - - self._debug['elements']['end'] = self._io.pos() - - - class Bignum(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Bignum - """ - SEQ_FIELDS = ["sign", "len_div_2", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sign']['start'] = self._io.pos() - self.sign = self._io.read_u1() - self._debug['sign']['end'] = self._io.pos() - self._debug['len_div_2']['start'] = self._io.pos() - self.len_div_2 = self._root.PackedInt(self._io, self, self._root) - self.len_div_2._read() - self._debug['len_div_2']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes((self.len_div_2.value * 2)) - self._debug['body']['end'] = self._io.pos() - - - class RubyStruct(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Struct - """ - SEQ_FIELDS = ["name", "num_members", "members"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._root.Record(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['num_members']['start'] = self._io.pos() - self.num_members = self._root.PackedInt(self._io, self, self._root) - self.num_members._read() - self._debug['num_members']['end'] = self._io.pos() - self._debug['members']['start'] = self._io.pos() - self.members = [None] * (self.num_members.value) - for i in range(self.num_members.value): - if not 'arr' in self._debug['members']: - self._debug['members']['arr'] = [] - self._debug['members']['arr'].append({'start': self._io.pos()}) - _t_members = self._root.Pair(self._io, self, self._root) - _t_members._read() - self.members[i] = _t_members - self._debug['members']['arr'][i]['end'] = self._io.pos() - - self._debug['members']['end'] = self._io.pos() - - - class RubySymbol(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Symbols+and+Byte+Sequence - """ - SEQ_FIELDS = ["len", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._root.PackedInt(self._io, self, self._root) - self.len._read() - self._debug['len']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes(self.len.value)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - - - class PackedInt(KaitaiStruct): - """Ruby uses sophisticated system to pack integers: first `code` - byte either determines packing scheme or carries encoded - immediate value (thus allowing smaller values from -123 to 122 - (inclusive) to take only one byte. There are 11 encoding schemes - in total: - - * 0 is encoded specially (as 0) - * 1..122 are encoded as immediate value with a shift - * 123..255 are encoded with code of 0x01 and 1 extra byte - * 0x100..0xffff are encoded with code of 0x02 and 2 extra bytes - * 0x10000..0xffffff are encoded with code of 0x03 and 3 extra - bytes - * 0x1000000..0xffffffff are encoded with code of 0x04 and 4 - extra bytes - * -123..-1 are encoded as immediate value with another shift - * -256..-124 are encoded with code of 0xff and 1 extra byte - * -0x10000..-257 are encoded with code of 0xfe and 2 extra bytes - * -0x1000000..0x10001 are encoded with code of 0xfd and 3 extra - bytes - * -0x40000000..-0x1000001 are encoded with code of 0xfc and 4 - extra bytes - - Values beyond that are serialized as bignum (even if they - technically might be not Bignum class in Ruby implementation, - i.e. if they fit into 64 bits on a 64-bit platform). - - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Fixnum+and+long - """ - SEQ_FIELDS = ["code", "encoded", "encoded2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = self._io.read_u1() - self._debug['code']['end'] = self._io.pos() - self._debug['encoded']['start'] = self._io.pos() - _on = self.code - if _on == 4: - self.encoded = self._io.read_u4le() - elif _on == 1: - self.encoded = self._io.read_u1() - elif _on == 252: - self.encoded = self._io.read_u4le() - elif _on == 253: - self.encoded = self._io.read_u2le() - elif _on == 3: - self.encoded = self._io.read_u2le() - elif _on == 2: - self.encoded = self._io.read_u2le() - elif _on == 255: - self.encoded = self._io.read_u1() - elif _on == 254: - self.encoded = self._io.read_u2le() - self._debug['encoded']['end'] = self._io.pos() - self._debug['encoded2']['start'] = self._io.pos() - _on = self.code - if _on == 3: - self.encoded2 = self._io.read_u1() - elif _on == 253: - self.encoded2 = self._io.read_u1() - self._debug['encoded2']['end'] = self._io.pos() - - @property - def is_immediate(self): - if hasattr(self, '_m_is_immediate'): - return self._m_is_immediate if hasattr(self, '_m_is_immediate') else None - - self._m_is_immediate = ((self.code > 4) and (self.code < 252)) - return self._m_is_immediate if hasattr(self, '_m_is_immediate') else None - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (((self.code - 5) if self.code < 128 else (4 - (~(self.code) & 127))) if self.is_immediate else (0 if self.code == 0 else ((self.encoded - 256) if self.code == 255 else ((self.encoded - 65536) if self.code == 254 else ((((self.encoded2 << 16) | self.encoded) - 16777216) if self.code == 253 else (((self.encoded2 << 16) | self.encoded) if self.code == 3 else self.encoded)))))) - return self._m_value if hasattr(self, '_m_value') else None - - - class Pair(KaitaiStruct): - SEQ_FIELDS = ["key", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key']['start'] = self._io.pos() - self.key = self._root.Record(self._io, self, self._root) - self.key._read() - self._debug['key']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._root.Record(self._io, self, self._root) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - - class InstanceVar(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Instance+Variables - """ - SEQ_FIELDS = ["obj", "num_vars", "vars"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['obj']['start'] = self._io.pos() - self.obj = self._root.Record(self._io, self, self._root) - self.obj._read() - self._debug['obj']['end'] = self._io.pos() - self._debug['num_vars']['start'] = self._io.pos() - self.num_vars = self._root.PackedInt(self._io, self, self._root) - self.num_vars._read() - self._debug['num_vars']['end'] = self._io.pos() - self._debug['vars']['start'] = self._io.pos() - self.vars = [None] * (self.num_vars.value) - for i in range(self.num_vars.value): - if not 'arr' in self._debug['vars']: - self._debug['vars']['arr'] = [] - self._debug['vars']['arr'].append({'start': self._io.pos()}) - _t_vars = self._root.Pair(self._io, self, self._root) - _t_vars._read() - self.vars[i] = _t_vars - self._debug['vars']['arr'][i]['end'] = self._io.pos() - - self._debug['vars']['end'] = self._io.pos() - - - class Record(KaitaiStruct): - """Each record starts with a single byte that determines its type - (`code`) and contents. If necessary, additional info as parsed - as `body`, to be determined by `code`. - """ - SEQ_FIELDS = ["code", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = KaitaiStream.resolve_enum(self._root.Codes, self._io.read_u1()) - self._debug['code']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.code - if _on == self._root.Codes.packed_int: - self.body = self._root.PackedInt(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.bignum: - self.body = self._root.Bignum(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_array: - self.body = self._root.RubyArray(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_symbol_link: - self.body = self._root.PackedInt(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_struct: - self.body = self._root.RubyStruct(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_string: - self.body = self._root.RubyString(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.instance_var: - self.body = self._root.InstanceVar(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_hash: - self.body = self._root.RubyHash(self._io, self, self._root) - self.body._read() - elif _on == self._root.Codes.ruby_symbol: - self.body = self._root.RubySymbol(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class RubyHash(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-Hash+and+Hash+with+Default+Value - """ - SEQ_FIELDS = ["num_pairs", "pairs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_pairs']['start'] = self._io.pos() - self.num_pairs = self._root.PackedInt(self._io, self, self._root) - self.num_pairs._read() - self._debug['num_pairs']['end'] = self._io.pos() - self._debug['pairs']['start'] = self._io.pos() - self.pairs = [None] * (self.num_pairs.value) - for i in range(self.num_pairs.value): - if not 'arr' in self._debug['pairs']: - self._debug['pairs']['arr'] = [] - self._debug['pairs']['arr'].append({'start': self._io.pos()}) - _t_pairs = self._root.Pair(self._io, self, self._root) - _t_pairs._read() - self.pairs[i] = _t_pairs - self._debug['pairs']['arr'][i]['end'] = self._io.pos() - - self._debug['pairs']['end'] = self._io.pos() - - - class RubyString(KaitaiStruct): - """ - .. seealso:: - Source - https://docs.ruby-lang.org/en/2.4.0/marshal_rdoc.html#label-String - """ - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._root.PackedInt(self._io, self, self._root) - self.len._read() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len.value) - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/s3m.py b/python/examples/kaitai/s3m.py deleted file mode 100644 index bc2dcb19..00000000 --- a/python/examples/kaitai/s3m.py +++ /dev/null @@ -1,484 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 S3m(KaitaiStruct): - """Scream Tracker 3 module is a tracker music file format that, as all - tracker music, bundles both sound samples and instructions on which - notes to play. It originates from a Scream Tracker 3 music editor - (1994) by Future Crew, derived from original Scream Tracker 2 (.stm) - module format. - - Instrument descriptions in S3M format allow to use either digital - samples or setup and control AdLib (OPL2) synth. - - Music is organized in so called `patterns`. "Pattern" is a generally - a 64-row long table, which instructs which notes to play on which - time measure. "Patterns" are played one-by-one in a sequence - determined by `orders`, which is essentially an array of pattern IDs - - this way it's possible to reuse certain patterns more than once - for repetitive musical phrases. - - .. seealso:: - Source - http://hackipedia.org/File%20formats/Music/Sample%20based/text/Scream%20Tracker%203.20%20file%20format.cp437.txt.utf-8.txt - """ - SEQ_FIELDS = ["song_name", "magic1", "file_type", "reserved1", "num_orders", "num_instruments", "num_patterns", "flags", "version", "samples_format", "magic2", "global_volume", "initial_speed", "initial_tempo", "is_stereo", "master_volume", "ultra_click_removal", "has_custom_pan", "reserved2", "ofs_special", "channels", "orders", "instruments", "patterns", "channel_pans"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['song_name']['start'] = self._io.pos() - self.song_name = KaitaiStream.bytes_terminate(self._io.read_bytes(28), 0, False) - self._debug['song_name']['end'] = self._io.pos() - self._debug['magic1']['start'] = self._io.pos() - self.magic1 = self._io.ensure_fixed_contents(b"\x1A") - self._debug['magic1']['end'] = self._io.pos() - self._debug['file_type']['start'] = self._io.pos() - self.file_type = self._io.read_u1() - self._debug['file_type']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bytes(2) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['num_orders']['start'] = self._io.pos() - self.num_orders = self._io.read_u2le() - self._debug['num_orders']['end'] = self._io.pos() - self._debug['num_instruments']['start'] = self._io.pos() - self.num_instruments = self._io.read_u2le() - self._debug['num_instruments']['end'] = self._io.pos() - self._debug['num_patterns']['start'] = self._io.pos() - self.num_patterns = self._io.read_u2le() - self._debug['num_patterns']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['samples_format']['start'] = self._io.pos() - self.samples_format = self._io.read_u2le() - self._debug['samples_format']['end'] = self._io.pos() - self._debug['magic2']['start'] = self._io.pos() - self.magic2 = self._io.ensure_fixed_contents(b"\x53\x43\x52\x4D") - self._debug['magic2']['end'] = self._io.pos() - self._debug['global_volume']['start'] = self._io.pos() - self.global_volume = self._io.read_u1() - self._debug['global_volume']['end'] = self._io.pos() - self._debug['initial_speed']['start'] = self._io.pos() - self.initial_speed = self._io.read_u1() - self._debug['initial_speed']['end'] = self._io.pos() - self._debug['initial_tempo']['start'] = self._io.pos() - self.initial_tempo = self._io.read_u1() - self._debug['initial_tempo']['end'] = self._io.pos() - self._debug['is_stereo']['start'] = self._io.pos() - self.is_stereo = self._io.read_bits_int(1) != 0 - self._debug['is_stereo']['end'] = self._io.pos() - self._debug['master_volume']['start'] = self._io.pos() - self.master_volume = self._io.read_bits_int(7) - self._debug['master_volume']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['ultra_click_removal']['start'] = self._io.pos() - self.ultra_click_removal = self._io.read_u1() - self._debug['ultra_click_removal']['end'] = self._io.pos() - self._debug['has_custom_pan']['start'] = self._io.pos() - self.has_custom_pan = self._io.read_u1() - self._debug['has_custom_pan']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(8) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['ofs_special']['start'] = self._io.pos() - self.ofs_special = self._io.read_u2le() - self._debug['ofs_special']['end'] = self._io.pos() - self._debug['channels']['start'] = self._io.pos() - self.channels = [None] * (32) - for i in range(32): - if not 'arr' in self._debug['channels']: - self._debug['channels']['arr'] = [] - self._debug['channels']['arr'].append({'start': self._io.pos()}) - _t_channels = self._root.Channel(self._io, self, self._root) - _t_channels._read() - self.channels[i] = _t_channels - self._debug['channels']['arr'][i]['end'] = self._io.pos() - - self._debug['channels']['end'] = self._io.pos() - self._debug['orders']['start'] = self._io.pos() - self.orders = self._io.read_bytes(self.num_orders) - self._debug['orders']['end'] = self._io.pos() - self._debug['instruments']['start'] = self._io.pos() - self.instruments = [None] * (self.num_instruments) - for i in range(self.num_instruments): - if not 'arr' in self._debug['instruments']: - self._debug['instruments']['arr'] = [] - self._debug['instruments']['arr'].append({'start': self._io.pos()}) - _t_instruments = self._root.InstrumentPtr(self._io, self, self._root) - _t_instruments._read() - self.instruments[i] = _t_instruments - self._debug['instruments']['arr'][i]['end'] = self._io.pos() - - self._debug['instruments']['end'] = self._io.pos() - self._debug['patterns']['start'] = self._io.pos() - self.patterns = [None] * (self.num_patterns) - for i in range(self.num_patterns): - if not 'arr' in self._debug['patterns']: - self._debug['patterns']['arr'] = [] - self._debug['patterns']['arr'].append({'start': self._io.pos()}) - _t_patterns = self._root.PatternPtr(self._io, self, self._root) - _t_patterns._read() - self.patterns[i] = _t_patterns - self._debug['patterns']['arr'][i]['end'] = self._io.pos() - - self._debug['patterns']['end'] = self._io.pos() - if self.has_custom_pan == 252: - self._debug['channel_pans']['start'] = self._io.pos() - self.channel_pans = [None] * (32) - for i in range(32): - if not 'arr' in self._debug['channel_pans']: - self._debug['channel_pans']['arr'] = [] - self._debug['channel_pans']['arr'].append({'start': self._io.pos()}) - _t_channel_pans = self._root.ChannelPan(self._io, self, self._root) - _t_channel_pans._read() - self.channel_pans[i] = _t_channel_pans - self._debug['channel_pans']['arr'][i]['end'] = self._io.pos() - - self._debug['channel_pans']['end'] = self._io.pos() - - - class ChannelPan(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "has_custom_pan", "reserved2", "pan"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(2) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['has_custom_pan']['start'] = self._io.pos() - self.has_custom_pan = self._io.read_bits_int(1) != 0 - self._debug['has_custom_pan']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(1) != 0 - self._debug['reserved2']['end'] = self._io.pos() - self._debug['pan']['start'] = self._io.pos() - self.pan = self._io.read_bits_int(4) - self._debug['pan']['end'] = self._io.pos() - - - class PatternCell(KaitaiStruct): - SEQ_FIELDS = ["has_fx", "has_volume", "has_note_and_instrument", "channel_num", "note", "instrument", "volume", "fx_type", "fx_value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['has_fx']['start'] = self._io.pos() - self.has_fx = self._io.read_bits_int(1) != 0 - self._debug['has_fx']['end'] = self._io.pos() - self._debug['has_volume']['start'] = self._io.pos() - self.has_volume = self._io.read_bits_int(1) != 0 - self._debug['has_volume']['end'] = self._io.pos() - self._debug['has_note_and_instrument']['start'] = self._io.pos() - self.has_note_and_instrument = self._io.read_bits_int(1) != 0 - self._debug['has_note_and_instrument']['end'] = self._io.pos() - self._debug['channel_num']['start'] = self._io.pos() - self.channel_num = self._io.read_bits_int(5) - self._debug['channel_num']['end'] = self._io.pos() - self._io.align_to_byte() - if self.has_note_and_instrument: - self._debug['note']['start'] = self._io.pos() - self.note = self._io.read_u1() - self._debug['note']['end'] = self._io.pos() - - if self.has_note_and_instrument: - self._debug['instrument']['start'] = self._io.pos() - self.instrument = self._io.read_u1() - self._debug['instrument']['end'] = self._io.pos() - - if self.has_volume: - self._debug['volume']['start'] = self._io.pos() - self.volume = self._io.read_u1() - self._debug['volume']['end'] = self._io.pos() - - if self.has_fx: - self._debug['fx_type']['start'] = self._io.pos() - self.fx_type = self._io.read_u1() - self._debug['fx_type']['end'] = self._io.pos() - - if self.has_fx: - self._debug['fx_value']['start'] = self._io.pos() - self.fx_value = self._io.read_u1() - self._debug['fx_value']['end'] = self._io.pos() - - - - class PatternCells(KaitaiStruct): - SEQ_FIELDS = ["cells"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cells']['start'] = self._io.pos() - self.cells = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['cells']: - self._debug['cells']['arr'] = [] - self._debug['cells']['arr'].append({'start': self._io.pos()}) - _t_cells = self._root.PatternCell(self._io, self, self._root) - _t_cells._read() - self.cells.append(_t_cells) - self._debug['cells']['arr'][len(self.cells) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['cells']['end'] = self._io.pos() - - - class Channel(KaitaiStruct): - SEQ_FIELDS = ["is_disabled", "ch_type"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['is_disabled']['start'] = self._io.pos() - self.is_disabled = self._io.read_bits_int(1) != 0 - self._debug['is_disabled']['end'] = self._io.pos() - self._debug['ch_type']['start'] = self._io.pos() - self.ch_type = self._io.read_bits_int(7) - self._debug['ch_type']['end'] = self._io.pos() - - - class SwappedU3(KaitaiStruct): - """Custom 3-byte integer, stored in mixed endian manner.""" - SEQ_FIELDS = ["hi", "lo"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hi']['start'] = self._io.pos() - self.hi = self._io.read_u1() - self._debug['hi']['end'] = self._io.pos() - self._debug['lo']['start'] = self._io.pos() - self.lo = self._io.read_u2le() - self._debug['lo']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (self.lo | (self.hi << 16)) - return self._m_value if hasattr(self, '_m_value') else None - - - class Pattern(KaitaiStruct): - SEQ_FIELDS = ["size", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u2le() - self._debug['size']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self._raw_body = self._io.read_bytes((self.size - 2)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.PatternCells(io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class PatternPtr(KaitaiStruct): - SEQ_FIELDS = ["paraptr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['paraptr']['start'] = self._io.pos() - self.paraptr = self._io.read_u2le() - self._debug['paraptr']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek((self.paraptr * 16)) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._root.Pattern(self._io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class InstrumentPtr(KaitaiStruct): - SEQ_FIELDS = ["paraptr"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['paraptr']['start'] = self._io.pos() - self.paraptr = self._io.read_u2le() - self._debug['paraptr']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek((self.paraptr * 16)) - self._debug['_m_body']['start'] = self._io.pos() - self._m_body = self._root.Instrument(self._io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - class Instrument(KaitaiStruct): - - class InstTypes(Enum): - sample = 1 - melodic = 2 - bass_drum = 3 - snare_drum = 4 - tom = 5 - cymbal = 6 - hihat = 7 - SEQ_FIELDS = ["type", "filename", "body", "tuning_hz", "reserved2", "sample_name", "magic"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = KaitaiStream.resolve_enum(self._root.Instrument.InstTypes, self._io.read_u1()) - self._debug['type']['end'] = self._io.pos() - self._debug['filename']['start'] = self._io.pos() - self.filename = KaitaiStream.bytes_terminate(self._io.read_bytes(12), 0, False) - self._debug['filename']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.type - if _on == self._root.Instrument.InstTypes.sample: - self.body = self._root.Instrument.Sampled(self._io, self, self._root) - self.body._read() - else: - self.body = self._root.Instrument.Adlib(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - self._debug['tuning_hz']['start'] = self._io.pos() - self.tuning_hz = self._io.read_u4le() - self._debug['tuning_hz']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bytes(12) - self._debug['reserved2']['end'] = self._io.pos() - self._debug['sample_name']['start'] = self._io.pos() - self.sample_name = KaitaiStream.bytes_terminate(self._io.read_bytes(28), 0, False) - self._debug['sample_name']['end'] = self._io.pos() - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x53\x43\x52\x53") - self._debug['magic']['end'] = self._io.pos() - - class Sampled(KaitaiStruct): - SEQ_FIELDS = ["paraptr_sample", "len_sample", "loop_begin", "loop_end", "default_volume", "reserved1", "is_packed", "flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['paraptr_sample']['start'] = self._io.pos() - self.paraptr_sample = self._root.SwappedU3(self._io, self, self._root) - self.paraptr_sample._read() - self._debug['paraptr_sample']['end'] = self._io.pos() - self._debug['len_sample']['start'] = self._io.pos() - self.len_sample = self._io.read_u4le() - self._debug['len_sample']['end'] = self._io.pos() - self._debug['loop_begin']['start'] = self._io.pos() - self.loop_begin = self._io.read_u4le() - self._debug['loop_begin']['end'] = self._io.pos() - self._debug['loop_end']['start'] = self._io.pos() - self.loop_end = self._io.read_u4le() - self._debug['loop_end']['end'] = self._io.pos() - self._debug['default_volume']['start'] = self._io.pos() - self.default_volume = self._io.read_u1() - self._debug['default_volume']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_u1() - self._debug['reserved1']['end'] = self._io.pos() - self._debug['is_packed']['start'] = self._io.pos() - self.is_packed = self._io.read_u1() - self._debug['is_packed']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - - @property - def sample(self): - if hasattr(self, '_m_sample'): - return self._m_sample if hasattr(self, '_m_sample') else None - - _pos = self._io.pos() - self._io.seek((self.paraptr_sample.value * 16)) - self._debug['_m_sample']['start'] = self._io.pos() - self._m_sample = self._io.read_bytes(self.len_sample) - self._debug['_m_sample']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_sample if hasattr(self, '_m_sample') else None - - - class Adlib(KaitaiStruct): - SEQ_FIELDS = ["reserved1", "_unnamed1"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.ensure_fixed_contents(b"\x00\x00\x00") - self._debug['reserved1']['end'] = self._io.pos() - self._debug['_unnamed1']['start'] = self._io.pos() - self._unnamed1 = self._io.read_bytes(16) - self._debug['_unnamed1']['end'] = self._io.pos() - - - - diff --git a/python/examples/kaitai/saints_row_2_vpp_pc.py b/python/examples/kaitai/saints_row_2_vpp_pc.py deleted file mode 100644 index 2c3dd1f8..00000000 --- a/python/examples/kaitai/saints_row_2_vpp_pc.py +++ /dev/null @@ -1,251 +0,0 @@ -# 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 -import collections - - -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 SaintsRow2VppPc(KaitaiStruct): - SEQ_FIELDS = ["magic", "pad1", "num_files", "container_size", "len_offsets", "len_filenames", "len_extensions", "smth5", "smth6", "smth7", "smth8", "smth9"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\xCE\x0A\x89\x51\x04") - self._debug['magic']['end'] = self._io.pos() - self._debug['pad1']['start'] = self._io.pos() - self.pad1 = self._io.read_bytes(335) - self._debug['pad1']['end'] = self._io.pos() - self._debug['num_files']['start'] = self._io.pos() - self.num_files = self._io.read_s4le() - self._debug['num_files']['end'] = self._io.pos() - self._debug['container_size']['start'] = self._io.pos() - self.container_size = self._io.read_s4le() - self._debug['container_size']['end'] = self._io.pos() - self._debug['len_offsets']['start'] = self._io.pos() - self.len_offsets = self._io.read_s4le() - self._debug['len_offsets']['end'] = self._io.pos() - self._debug['len_filenames']['start'] = self._io.pos() - self.len_filenames = self._io.read_s4le() - self._debug['len_filenames']['end'] = self._io.pos() - self._debug['len_extensions']['start'] = self._io.pos() - self.len_extensions = self._io.read_s4le() - self._debug['len_extensions']['end'] = self._io.pos() - self._debug['smth5']['start'] = self._io.pos() - self.smth5 = self._io.read_s4le() - self._debug['smth5']['end'] = self._io.pos() - self._debug['smth6']['start'] = self._io.pos() - self.smth6 = self._io.read_s4le() - self._debug['smth6']['end'] = self._io.pos() - self._debug['smth7']['start'] = self._io.pos() - self.smth7 = self._io.read_s4le() - self._debug['smth7']['end'] = self._io.pos() - self._debug['smth8']['start'] = self._io.pos() - self.smth8 = self._io.read_s4le() - self._debug['smth8']['end'] = self._io.pos() - self._debug['smth9']['start'] = self._io.pos() - self.smth9 = self._io.read_s4le() - self._debug['smth9']['end'] = self._io.pos() - - class Offsets(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.Offsets.Offset(self._io, self, self._root) - _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() - - class Offset(KaitaiStruct): - SEQ_FIELDS = ["name_ofs", "ext_ofs", "smth2", "ofs_body", "len_body", "always_minus_1", "always_zero"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_ofs']['start'] = self._io.pos() - self.name_ofs = self._io.read_u4le() - self._debug['name_ofs']['end'] = self._io.pos() - self._debug['ext_ofs']['start'] = self._io.pos() - self.ext_ofs = self._io.read_u4le() - self._debug['ext_ofs']['end'] = self._io.pos() - self._debug['smth2']['start'] = self._io.pos() - self.smth2 = self._io.read_s4le() - self._debug['smth2']['end'] = self._io.pos() - self._debug['ofs_body']['start'] = self._io.pos() - self.ofs_body = self._io.read_s4le() - self._debug['ofs_body']['end'] = self._io.pos() - self._debug['len_body']['start'] = self._io.pos() - self.len_body = self._io.read_s4le() - self._debug['len_body']['end'] = self._io.pos() - self._debug['always_minus_1']['start'] = self._io.pos() - self.always_minus_1 = self._io.read_s4le() - self._debug['always_minus_1']['end'] = self._io.pos() - self._debug['always_zero']['start'] = self._io.pos() - self.always_zero = self._io.read_s4le() - self._debug['always_zero']['end'] = self._io.pos() - - @property - def filename(self): - if hasattr(self, '_m_filename'): - return self._m_filename if hasattr(self, '_m_filename') else None - - io = self._root.filenames._io - _pos = io.pos() - io.seek(self.name_ofs) - self._debug['_m_filename']['start'] = io.pos() - self._m_filename = (io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['_m_filename']['end'] = io.pos() - io.seek(_pos) - return self._m_filename if hasattr(self, '_m_filename') else None - - @property - def ext(self): - if hasattr(self, '_m_ext'): - return self._m_ext if hasattr(self, '_m_ext') else None - - io = self._root.extensions._io - _pos = io.pos() - io.seek(self.ext_ofs) - self._debug['_m_ext']['start'] = io.pos() - self._m_ext = (io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['_m_ext']['end'] = io.pos() - io.seek(_pos) - return self._m_ext if hasattr(self, '_m_ext') else None - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - io = self._root._io - _pos = io.pos() - io.seek((self._root.data_start + self.ofs_body)) - self._debug['_m_body']['start'] = io.pos() - self._m_body = io.read_bytes(self.len_body) - self._debug['_m_body']['end'] = io.pos() - io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - - class Strings(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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()}) - self.entries.append((self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")) - self._debug['entries']['arr'][len(self.entries) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['entries']['end'] = self._io.pos() - - - @property - def filenames(self): - if hasattr(self, '_m_filenames'): - return self._m_filenames if hasattr(self, '_m_filenames') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_filenames) - self._debug['_m_filenames']['start'] = self._io.pos() - self._raw__m_filenames = self._io.read_bytes(self.len_filenames) - io = KaitaiStream(BytesIO(self._raw__m_filenames)) - self._m_filenames = self._root.Strings(io, self, self._root) - self._m_filenames._read() - self._debug['_m_filenames']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_filenames if hasattr(self, '_m_filenames') else None - - @property - def ofs_extensions(self): - if hasattr(self, '_m_ofs_extensions'): - return self._m_ofs_extensions if hasattr(self, '_m_ofs_extensions') else None - - self._m_ofs_extensions = (((self.ofs_filenames + self.len_filenames) & 4294965248) + 2048) - return self._m_ofs_extensions if hasattr(self, '_m_ofs_extensions') else None - - @property - def files(self): - if hasattr(self, '_m_files'): - return self._m_files if hasattr(self, '_m_files') else None - - _pos = self._io.pos() - self._io.seek(2048) - self._debug['_m_files']['start'] = self._io.pos() - self._raw__m_files = self._io.read_bytes(self.len_offsets) - io = KaitaiStream(BytesIO(self._raw__m_files)) - self._m_files = self._root.Offsets(io, self, self._root) - self._m_files._read() - self._debug['_m_files']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_files if hasattr(self, '_m_files') else None - - @property - def data_start(self): - if hasattr(self, '_m_data_start'): - return self._m_data_start if hasattr(self, '_m_data_start') else None - - self._m_data_start = (((self.ofs_extensions + self.len_extensions) & 4294965248) + 2048) - return self._m_data_start if hasattr(self, '_m_data_start') else None - - @property - def extensions(self): - if hasattr(self, '_m_extensions'): - return self._m_extensions if hasattr(self, '_m_extensions') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_extensions) - self._debug['_m_extensions']['start'] = self._io.pos() - self._raw__m_extensions = self._io.read_bytes(self.len_extensions) - io = KaitaiStream(BytesIO(self._raw__m_extensions)) - self._m_extensions = self._root.Strings(io, self, self._root) - self._m_extensions._read() - self._debug['_m_extensions']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_extensions if hasattr(self, '_m_extensions') else None - - @property - def ofs_filenames(self): - if hasattr(self, '_m_ofs_filenames'): - return self._m_ofs_filenames if hasattr(self, '_m_ofs_filenames') else None - - self._m_ofs_filenames = (((2048 + self.len_offsets) & 4294965248) + 2048) - return self._m_ofs_filenames if hasattr(self, '_m_ofs_filenames') else None - - diff --git a/python/examples/kaitai/shapefile_index.py b/python/examples/kaitai/shapefile_index.py deleted file mode 100644 index 4fbc7142..00000000 --- a/python/examples/kaitai/shapefile_index.py +++ /dev/null @@ -1,159 +0,0 @@ -# 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 -import collections - - -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 ShapefileIndex(KaitaiStruct): - - class ShapeType(Enum): - null_shape = 0 - point = 1 - poly_line = 3 - polygon = 5 - multi_point = 8 - point_z = 11 - poly_line_z = 13 - polygon_z = 15 - multi_point_z = 18 - point_m = 21 - poly_line_m = 23 - polygon_m = 25 - multi_point_m = 28 - multi_patch = 31 - SEQ_FIELDS = ["header", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.FileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.Record(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class FileHeader(KaitaiStruct): - SEQ_FIELDS = ["file_code", "unused_field_1", "unused_field_2", "unused_field_3", "unused_field_4", "unused_field_5", "file_length", "version", "shape_type", "bounding_box"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_code']['start'] = self._io.pos() - self.file_code = self._io.ensure_fixed_contents(b"\x00\x00\x27\x0A") - self._debug['file_code']['end'] = self._io.pos() - self._debug['unused_field_1']['start'] = self._io.pos() - self.unused_field_1 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_1']['end'] = self._io.pos() - self._debug['unused_field_2']['start'] = self._io.pos() - self.unused_field_2 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_2']['end'] = self._io.pos() - self._debug['unused_field_3']['start'] = self._io.pos() - self.unused_field_3 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_3']['end'] = self._io.pos() - self._debug['unused_field_4']['start'] = self._io.pos() - self.unused_field_4 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_4']['end'] = self._io.pos() - self._debug['unused_field_5']['start'] = self._io.pos() - self.unused_field_5 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_5']['end'] = self._io.pos() - self._debug['file_length']['start'] = self._io.pos() - self.file_length = self._io.read_s4be() - self._debug['file_length']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.ensure_fixed_contents(b"\xE8\x03\x00\x00") - self._debug['version']['end'] = self._io.pos() - self._debug['shape_type']['start'] = self._io.pos() - self.shape_type = KaitaiStream.resolve_enum(self._root.ShapeType, self._io.read_s4le()) - self._debug['shape_type']['end'] = self._io.pos() - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXYZM(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - - - class Record(KaitaiStruct): - SEQ_FIELDS = ["offset", "content_length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_s4be() - self._debug['offset']['end'] = self._io.pos() - self._debug['content_length']['start'] = self._io.pos() - self.content_length = self._io.read_s4be() - self._debug['content_length']['end'] = self._io.pos() - - - class BoundingBoxXYZM(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z", "m"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._root.BoundsMinMax(self._io, self, self._root) - self.x._read() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._root.BoundsMinMax(self._io, self, self._root) - self.y._read() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._root.BoundsMinMax(self._io, self, self._root) - self.z._read() - self._debug['z']['end'] = self._io.pos() - self._debug['m']['start'] = self._io.pos() - self.m = self._root.BoundsMinMax(self._io, self, self._root) - self.m._read() - self._debug['m']['end'] = self._io.pos() - - - class BoundsMinMax(KaitaiStruct): - SEQ_FIELDS = ["min", "max"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['min']['start'] = self._io.pos() - self.min = self._io.read_f8be() - self._debug['min']['end'] = self._io.pos() - self._debug['max']['start'] = self._io.pos() - self.max = self._io.read_f8be() - self._debug['max']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/shapefile_main.py b/python/examples/kaitai/shapefile_main.py deleted file mode 100644 index 7a64087e..00000000 --- a/python/examples/kaitai/shapefile_main.py +++ /dev/null @@ -1,878 +0,0 @@ -# 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 -import collections - - -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 ShapefileMain(KaitaiStruct): - - class ShapeType(Enum): - null_shape = 0 - point = 1 - poly_line = 3 - polygon = 5 - multi_point = 8 - point_z = 11 - poly_line_z = 13 - polygon_z = 15 - multi_point_z = 18 - point_m = 21 - poly_line_m = 23 - polygon_m = 25 - multi_point_m = 28 - multi_patch = 31 - - class PartType(Enum): - triangle_strip = 0 - triangle_fan = 1 - outer_ring = 2 - inner_ring = 3 - first_ring = 4 - ring = 5 - SEQ_FIELDS = ["header", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.FileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.Record(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class MultiPointM(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_points", "points", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class BoundingBoxXYZM(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z", "m"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._root.BoundsMinMax(self._io, self, self._root) - self.x._read() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._root.BoundsMinMax(self._io, self, self._root) - self.y._read() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._root.BoundsMinMax(self._io, self, self._root) - self.z._read() - self._debug['z']['end'] = self._io.pos() - self._debug['m']['start'] = self._io.pos() - self.m = self._root.BoundsMinMax(self._io, self, self._root) - self.m._read() - self._debug['m']['end'] = self._io.pos() - - - class Point(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f8le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f8le() - self._debug['y']['end'] = self._io.pos() - - - class Polygon(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - - - class BoundsMinMax(KaitaiStruct): - SEQ_FIELDS = ["min", "max"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['min']['start'] = self._io.pos() - self.min = self._io.read_f8le() - self._debug['min']['end'] = self._io.pos() - self._debug['max']['start'] = self._io.pos() - self.max = self._io.read_f8le() - self._debug['max']['end'] = self._io.pos() - - - class PolyLine(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - - - class MultiPointZ(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_points", "points", "z_range", "z_values", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['z_range']['start'] = self._io.pos() - self.z_range = self._root.BoundsMinMax(self._io, self, self._root) - self.z_range._read() - self._debug['z_range']['end'] = self._io.pos() - self._debug['z_values']['start'] = self._io.pos() - self.z_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['z_values']: - self._debug['z_values']['arr'] = [] - self._debug['z_values']['arr'].append({'start': self._io.pos()}) - self.z_values[i] = self._io.read_f8le() - self._debug['z_values']['arr'][i]['end'] = self._io.pos() - - self._debug['z_values']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class PolyLineZ(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points", "z_range", "z_values", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['z_range']['start'] = self._io.pos() - self.z_range = self._root.BoundsMinMax(self._io, self, self._root) - self.z_range._read() - self._debug['z_range']['end'] = self._io.pos() - self._debug['z_values']['start'] = self._io.pos() - self.z_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['z_values']: - self._debug['z_values']['arr'] = [] - self._debug['z_values']['arr'].append({'start': self._io.pos()}) - self.z_values[i] = self._io.read_f8le() - self._debug['z_values']['arr'][i]['end'] = self._io.pos() - - self._debug['z_values']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class PolygonZ(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points", "z_range", "z_values", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['z_range']['start'] = self._io.pos() - self.z_range = self._root.BoundsMinMax(self._io, self, self._root) - self.z_range._read() - self._debug['z_range']['end'] = self._io.pos() - self._debug['z_values']['start'] = self._io.pos() - self.z_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['z_values']: - self._debug['z_values']['arr'] = [] - self._debug['z_values']['arr'].append({'start': self._io.pos()}) - self.z_values[i] = self._io.read_f8le() - self._debug['z_values']['arr'][i]['end'] = self._io.pos() - - self._debug['z_values']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class BoundingBoxXY(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._root.BoundsMinMax(self._io, self, self._root) - self.x._read() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._root.BoundsMinMax(self._io, self, self._root) - self.y._read() - self._debug['y']['end'] = self._io.pos() - - - class PointM(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "m"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f8le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f8le() - self._debug['y']['end'] = self._io.pos() - self._debug['m']['start'] = self._io.pos() - self.m = self._io.read_f8le() - self._debug['m']['end'] = self._io.pos() - - - class PolygonM(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class RecordHeader(KaitaiStruct): - SEQ_FIELDS = ["record_number", "content_length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['record_number']['start'] = self._io.pos() - self.record_number = self._io.read_s4be() - self._debug['record_number']['end'] = self._io.pos() - self._debug['content_length']['start'] = self._io.pos() - self.content_length = self._io.read_s4be() - self._debug['content_length']['end'] = self._io.pos() - - - class MultiPoint(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_points", "points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - - - class FileHeader(KaitaiStruct): - SEQ_FIELDS = ["file_code", "unused_field_1", "unused_field_2", "unused_field_3", "unused_field_4", "unused_field_5", "file_length", "version", "shape_type", "bounding_box"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_code']['start'] = self._io.pos() - self.file_code = self._io.ensure_fixed_contents(b"\x00\x00\x27\x0A") - self._debug['file_code']['end'] = self._io.pos() - self._debug['unused_field_1']['start'] = self._io.pos() - self.unused_field_1 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_1']['end'] = self._io.pos() - self._debug['unused_field_2']['start'] = self._io.pos() - self.unused_field_2 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_2']['end'] = self._io.pos() - self._debug['unused_field_3']['start'] = self._io.pos() - self.unused_field_3 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_3']['end'] = self._io.pos() - self._debug['unused_field_4']['start'] = self._io.pos() - self.unused_field_4 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_4']['end'] = self._io.pos() - self._debug['unused_field_5']['start'] = self._io.pos() - self.unused_field_5 = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['unused_field_5']['end'] = self._io.pos() - self._debug['file_length']['start'] = self._io.pos() - self.file_length = self._io.read_s4be() - self._debug['file_length']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.ensure_fixed_contents(b"\xE8\x03\x00\x00") - self._debug['version']['end'] = self._io.pos() - self._debug['shape_type']['start'] = self._io.pos() - self.shape_type = KaitaiStream.resolve_enum(self._root.ShapeType, self._io.read_s4le()) - self._debug['shape_type']['end'] = self._io.pos() - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXYZM(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - - - class PointZ(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z", "m"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f8le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f8le() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_f8le() - self._debug['z']['end'] = self._io.pos() - self._debug['m']['start'] = self._io.pos() - self.m = self._io.read_f8le() - self._debug['m']['end'] = self._io.pos() - - - class Record(KaitaiStruct): - SEQ_FIELDS = ["header", "contents"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.RecordHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['contents']['start'] = self._io.pos() - self.contents = self._root.RecordContents(self._io, self, self._root) - self.contents._read() - self._debug['contents']['end'] = self._io.pos() - - - class RecordContents(KaitaiStruct): - SEQ_FIELDS = ["shape_type", "shape_parameters"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['shape_type']['start'] = self._io.pos() - self.shape_type = KaitaiStream.resolve_enum(self._root.ShapeType, self._io.read_s4le()) - self._debug['shape_type']['end'] = self._io.pos() - if self.shape_type != self._root.ShapeType.null_shape: - self._debug['shape_parameters']['start'] = self._io.pos() - _on = self.shape_type - if _on == self._root.ShapeType.poly_line_z: - self.shape_parameters = self._root.PolyLineZ(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.multi_patch: - self.shape_parameters = self._root.MultiPatch(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.poly_line_m: - self.shape_parameters = self._root.PolyLineM(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.polygon: - self.shape_parameters = self._root.Polygon(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.polygon_z: - self.shape_parameters = self._root.PolygonZ(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.point_z: - self.shape_parameters = self._root.PointZ(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.poly_line: - self.shape_parameters = self._root.PolyLine(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.point_m: - self.shape_parameters = self._root.PointM(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.polygon_m: - self.shape_parameters = self._root.PolygonM(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.multi_point: - self.shape_parameters = self._root.MultiPoint(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.point: - self.shape_parameters = self._root.Point(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.multi_point_m: - self.shape_parameters = self._root.MultiPointM(self._io, self, self._root) - self.shape_parameters._read() - elif _on == self._root.ShapeType.multi_point_z: - self.shape_parameters = self._root.MultiPointZ(self._io, self, self._root) - self.shape_parameters._read() - self._debug['shape_parameters']['end'] = self._io.pos() - - - - class MultiPatch(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "part_types", "points", "z_range", "z_values", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['part_types']['start'] = self._io.pos() - self.part_types = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['part_types']: - self._debug['part_types']['arr'] = [] - self._debug['part_types']['arr'].append({'start': self._io.pos()}) - self.part_types[i] = KaitaiStream.resolve_enum(self._root.PartType, self._io.read_s4le()) - self._debug['part_types']['arr'][i]['end'] = self._io.pos() - - self._debug['part_types']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['z_range']['start'] = self._io.pos() - self.z_range = self._root.BoundsMinMax(self._io, self, self._root) - self.z_range._read() - self._debug['z_range']['end'] = self._io.pos() - self._debug['z_values']['start'] = self._io.pos() - self.z_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['z_values']: - self._debug['z_values']['arr'] = [] - self._debug['z_values']['arr'].append({'start': self._io.pos()}) - self.z_values[i] = self._io.read_f8le() - self._debug['z_values']['arr'][i]['end'] = self._io.pos() - - self._debug['z_values']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - class PolyLineM(KaitaiStruct): - SEQ_FIELDS = ["bounding_box", "number_of_parts", "number_of_points", "parts", "points", "m_range", "m_values"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bounding_box']['start'] = self._io.pos() - self.bounding_box = self._root.BoundingBoxXY(self._io, self, self._root) - self.bounding_box._read() - self._debug['bounding_box']['end'] = self._io.pos() - self._debug['number_of_parts']['start'] = self._io.pos() - self.number_of_parts = self._io.read_s4le() - self._debug['number_of_parts']['end'] = self._io.pos() - self._debug['number_of_points']['start'] = self._io.pos() - self.number_of_points = self._io.read_s4le() - self._debug['number_of_points']['end'] = self._io.pos() - self._debug['parts']['start'] = self._io.pos() - self.parts = [None] * (self.number_of_parts) - for i in range(self.number_of_parts): - if not 'arr' in self._debug['parts']: - self._debug['parts']['arr'] = [] - self._debug['parts']['arr'].append({'start': self._io.pos()}) - self.parts[i] = self._io.read_s4le() - self._debug['parts']['arr'][i]['end'] = self._io.pos() - - self._debug['parts']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.Point(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - self._debug['m_range']['start'] = self._io.pos() - self.m_range = self._root.BoundsMinMax(self._io, self, self._root) - self.m_range._read() - self._debug['m_range']['end'] = self._io.pos() - self._debug['m_values']['start'] = self._io.pos() - self.m_values = [None] * (self.number_of_points) - for i in range(self.number_of_points): - if not 'arr' in self._debug['m_values']: - self._debug['m_values']['arr'] = [] - self._debug['m_values']['arr'].append({'start': self._io.pos()}) - self.m_values[i] = self._io.read_f8le() - self._debug['m_values']['arr'][i]['end'] = self._io.pos() - - self._debug['m_values']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/specpr.py b/python/examples/kaitai/specpr.py deleted file mode 100644 index 4f23d4ca..00000000 --- a/python/examples/kaitai/specpr.py +++ /dev/null @@ -1,403 +0,0 @@ -# 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 -import collections - - -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 Specpr(KaitaiStruct): - """Specpr records are fixed format, 1536 bytes/record. Record number - counting starts at 0. Binary data are in IEEE format real numbers - and non-byte swapped integers (compatiible with all Sun - Microsystems, and Hewlett Packard workstations (Intel and some DEC - machines are byte swapped relative to Suns and HPs). Each record may - contain different information according to the following scheme. - - You can get some library of spectra from - ftp://ftpext.cr.usgs.gov/pub/cr/co/denver/speclab/pub/spectral.library/splib06.library/ - """ - - class RecordType(Enum): - data_initial = 0 - text_initial = 1 - data_continuation = 2 - text_continuation = 3 - SEQ_FIELDS = ["records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.Record(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class DataInitial(KaitaiStruct): - SEQ_FIELDS = ["ids", "iscta", "isctb", "jdatea", "jdateb", "istb", "isra", "isdec", "itchan", "irmas", "revs", "iband", "irwav", "irespt", "irecno", "itpntr", "ihist", "mhist", "nruns", "siangl", "seangl", "sphase", "iwtrns", "itimch", "xnrm", "scatim", "timint", "tempd", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ids']['start'] = self._io.pos() - self.ids = self._root.Identifiers(self._io, self, self._root) - self.ids._read() - self._debug['ids']['end'] = self._io.pos() - self._debug['iscta']['start'] = self._io.pos() - self.iscta = self._root.CoarseTimestamp(self._io, self, self._root) - self.iscta._read() - self._debug['iscta']['end'] = self._io.pos() - self._debug['isctb']['start'] = self._io.pos() - self.isctb = self._root.CoarseTimestamp(self._io, self, self._root) - self.isctb._read() - self._debug['isctb']['end'] = self._io.pos() - self._debug['jdatea']['start'] = self._io.pos() - self.jdatea = self._io.read_s4be() - self._debug['jdatea']['end'] = self._io.pos() - self._debug['jdateb']['start'] = self._io.pos() - self.jdateb = self._io.read_s4be() - self._debug['jdateb']['end'] = self._io.pos() - self._debug['istb']['start'] = self._io.pos() - self.istb = self._root.CoarseTimestamp(self._io, self, self._root) - self.istb._read() - self._debug['istb']['end'] = self._io.pos() - self._debug['isra']['start'] = self._io.pos() - self.isra = self._io.read_s4be() - self._debug['isra']['end'] = self._io.pos() - self._debug['isdec']['start'] = self._io.pos() - self.isdec = self._io.read_s4be() - self._debug['isdec']['end'] = self._io.pos() - self._debug['itchan']['start'] = self._io.pos() - self.itchan = self._io.read_s4be() - self._debug['itchan']['end'] = self._io.pos() - self._debug['irmas']['start'] = self._io.pos() - self.irmas = self._io.read_s4be() - self._debug['irmas']['end'] = self._io.pos() - self._debug['revs']['start'] = self._io.pos() - self.revs = self._io.read_s4be() - self._debug['revs']['end'] = self._io.pos() - self._debug['iband']['start'] = self._io.pos() - self.iband = [None] * (2) - for i in range(2): - if not 'arr' in self._debug['iband']: - self._debug['iband']['arr'] = [] - self._debug['iband']['arr'].append({'start': self._io.pos()}) - self.iband[i] = self._io.read_s4be() - self._debug['iband']['arr'][i]['end'] = self._io.pos() - - self._debug['iband']['end'] = self._io.pos() - self._debug['irwav']['start'] = self._io.pos() - self.irwav = self._io.read_s4be() - self._debug['irwav']['end'] = self._io.pos() - self._debug['irespt']['start'] = self._io.pos() - self.irespt = self._io.read_s4be() - self._debug['irespt']['end'] = self._io.pos() - self._debug['irecno']['start'] = self._io.pos() - self.irecno = self._io.read_s4be() - self._debug['irecno']['end'] = self._io.pos() - self._debug['itpntr']['start'] = self._io.pos() - self.itpntr = self._io.read_s4be() - self._debug['itpntr']['end'] = self._io.pos() - self._debug['ihist']['start'] = self._io.pos() - self.ihist = (KaitaiStream.bytes_strip_right(self._io.read_bytes(60), 32)).decode(u"ascii") - self._debug['ihist']['end'] = self._io.pos() - self._debug['mhist']['start'] = self._io.pos() - self.mhist = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['mhist']: - self._debug['mhist']['arr'] = [] - self._debug['mhist']['arr'].append({'start': self._io.pos()}) - self.mhist[i] = (self._io.read_bytes(74)).decode(u"ascii") - self._debug['mhist']['arr'][i]['end'] = self._io.pos() - - self._debug['mhist']['end'] = self._io.pos() - self._debug['nruns']['start'] = self._io.pos() - self.nruns = self._io.read_s4be() - self._debug['nruns']['end'] = self._io.pos() - self._debug['siangl']['start'] = self._io.pos() - self.siangl = self._root.IllumAngle(self._io, self, self._root) - self.siangl._read() - self._debug['siangl']['end'] = self._io.pos() - self._debug['seangl']['start'] = self._io.pos() - self.seangl = self._root.IllumAngle(self._io, self, self._root) - self.seangl._read() - self._debug['seangl']['end'] = self._io.pos() - self._debug['sphase']['start'] = self._io.pos() - self.sphase = self._io.read_s4be() - self._debug['sphase']['end'] = self._io.pos() - self._debug['iwtrns']['start'] = self._io.pos() - self.iwtrns = self._io.read_s4be() - self._debug['iwtrns']['end'] = self._io.pos() - self._debug['itimch']['start'] = self._io.pos() - self.itimch = self._io.read_s4be() - self._debug['itimch']['end'] = self._io.pos() - self._debug['xnrm']['start'] = self._io.pos() - self.xnrm = self._io.read_f4be() - self._debug['xnrm']['end'] = self._io.pos() - self._debug['scatim']['start'] = self._io.pos() - self.scatim = self._io.read_f4be() - self._debug['scatim']['end'] = self._io.pos() - self._debug['timint']['start'] = self._io.pos() - self.timint = self._io.read_f4be() - self._debug['timint']['end'] = self._io.pos() - self._debug['tempd']['start'] = self._io.pos() - self.tempd = self._io.read_f4be() - self._debug['tempd']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = [None] * (256) - for i in range(256): - if not 'arr' in self._debug['data']: - self._debug['data']['arr'] = [] - self._debug['data']['arr'].append({'start': self._io.pos()}) - self.data[i] = self._io.read_f4be() - self._debug['data']['arr'][i]['end'] = self._io.pos() - - self._debug['data']['end'] = self._io.pos() - - @property - def phase_angle_arcsec(self): - """The phase angle between iangl and eangl in seconds.""" - if hasattr(self, '_m_phase_angle_arcsec'): - return self._m_phase_angle_arcsec if hasattr(self, '_m_phase_angle_arcsec') else None - - self._m_phase_angle_arcsec = (self.sphase / 1500) - return self._m_phase_angle_arcsec if hasattr(self, '_m_phase_angle_arcsec') else None - - - class CoarseTimestamp(KaitaiStruct): - SEQ_FIELDS = ["scaled_seconds"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['scaled_seconds']['start'] = self._io.pos() - self.scaled_seconds = self._io.read_s4be() - self._debug['scaled_seconds']['end'] = self._io.pos() - - @property - def seconds(self): - if hasattr(self, '_m_seconds'): - return self._m_seconds if hasattr(self, '_m_seconds') else None - - self._m_seconds = (self.scaled_seconds * 24000) - return self._m_seconds if hasattr(self, '_m_seconds') else None - - - class Icflag(KaitaiStruct): - """it is big endian.""" - SEQ_FIELDS = ["reserved", "isctb_type", "iscta_type", "coordinate_mode", "errors", "text", "continuation"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(26) - self._debug['reserved']['end'] = self._io.pos() - self._debug['isctb_type']['start'] = self._io.pos() - self.isctb_type = self._io.read_bits_int(1) != 0 - self._debug['isctb_type']['end'] = self._io.pos() - self._debug['iscta_type']['start'] = self._io.pos() - self.iscta_type = self._io.read_bits_int(1) != 0 - self._debug['iscta_type']['end'] = self._io.pos() - self._debug['coordinate_mode']['start'] = self._io.pos() - self.coordinate_mode = self._io.read_bits_int(1) != 0 - self._debug['coordinate_mode']['end'] = self._io.pos() - self._debug['errors']['start'] = self._io.pos() - self.errors = self._io.read_bits_int(1) != 0 - self._debug['errors']['end'] = self._io.pos() - self._debug['text']['start'] = self._io.pos() - self.text = self._io.read_bits_int(1) != 0 - self._debug['text']['end'] = self._io.pos() - self._debug['continuation']['start'] = self._io.pos() - self.continuation = self._io.read_bits_int(1) != 0 - self._debug['continuation']['end'] = self._io.pos() - - @property - def type(self): - if hasattr(self, '_m_type'): - return self._m_type if hasattr(self, '_m_type') else None - - self._m_type = KaitaiStream.resolve_enum(self._root.RecordType, ((int(self.text) * 1) + (int(self.continuation) * 2))) - return self._m_type if hasattr(self, '_m_type') else None - - - class DataContinuation(KaitaiStruct): - SEQ_FIELDS = ["cdata"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cdata']['start'] = self._io.pos() - self.cdata = [None] * (383) - for i in range(383): - if not 'arr' in self._debug['cdata']: - self._debug['cdata']['arr'] = [] - self._debug['cdata']['arr'].append({'start': self._io.pos()}) - self.cdata[i] = self._io.read_f4be() - self._debug['cdata']['arr'][i]['end'] = self._io.pos() - - self._debug['cdata']['end'] = self._io.pos() - - - class Identifiers(KaitaiStruct): - SEQ_FIELDS = ["ititle", "usernm"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ititle']['start'] = self._io.pos() - self.ititle = (KaitaiStream.bytes_strip_right(self._io.read_bytes(40), 32)).decode(u"ascii") - self._debug['ititle']['end'] = self._io.pos() - self._debug['usernm']['start'] = self._io.pos() - self.usernm = (self._io.read_bytes(8)).decode(u"ascii") - self._debug['usernm']['end'] = self._io.pos() - - - class IllumAngle(KaitaiStruct): - SEQ_FIELDS = ["angl"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['angl']['start'] = self._io.pos() - self.angl = self._io.read_s4be() - self._debug['angl']['end'] = self._io.pos() - - @property - def seconds_total(self): - if hasattr(self, '_m_seconds_total'): - return self._m_seconds_total if hasattr(self, '_m_seconds_total') else None - - self._m_seconds_total = self.angl // 6000 - return self._m_seconds_total if hasattr(self, '_m_seconds_total') else None - - @property - def minutes_total(self): - if hasattr(self, '_m_minutes_total'): - return self._m_minutes_total if hasattr(self, '_m_minutes_total') else None - - self._m_minutes_total = self.seconds_total // 60 - return self._m_minutes_total if hasattr(self, '_m_minutes_total') else None - - @property - def degrees_total(self): - if hasattr(self, '_m_degrees_total'): - return self._m_degrees_total if hasattr(self, '_m_degrees_total') else None - - self._m_degrees_total = self.minutes_total // 60 - return self._m_degrees_total if hasattr(self, '_m_degrees_total') else None - - - class TextInitial(KaitaiStruct): - SEQ_FIELDS = ["ids", "itxtpt", "itxtch", "itext"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ids']['start'] = self._io.pos() - self.ids = self._root.Identifiers(self._io, self, self._root) - self.ids._read() - self._debug['ids']['end'] = self._io.pos() - self._debug['itxtpt']['start'] = self._io.pos() - self.itxtpt = self._io.read_u4be() - self._debug['itxtpt']['end'] = self._io.pos() - self._debug['itxtch']['start'] = self._io.pos() - self.itxtch = self._io.read_s4be() - self._debug['itxtch']['end'] = self._io.pos() - self._debug['itext']['start'] = self._io.pos() - self.itext = (self._io.read_bytes(1476)).decode(u"ascii") - self._debug['itext']['end'] = self._io.pos() - - - class Record(KaitaiStruct): - SEQ_FIELDS = ["icflag", "content"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['icflag']['start'] = self._io.pos() - self.icflag = self._root.Icflag(self._io, self, self._root) - self.icflag._read() - self._debug['icflag']['end'] = self._io.pos() - self._debug['content']['start'] = self._io.pos() - _on = self.icflag.type - if _on == self._root.RecordType.data_initial: - self._raw_content = self._io.read_bytes((1536 - 4)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.DataInitial(io, self, self._root) - self.content._read() - elif _on == self._root.RecordType.data_continuation: - self._raw_content = self._io.read_bytes((1536 - 4)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.DataContinuation(io, self, self._root) - self.content._read() - elif _on == self._root.RecordType.text_continuation: - self._raw_content = self._io.read_bytes((1536 - 4)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.TextContinuation(io, self, self._root) - self.content._read() - elif _on == self._root.RecordType.text_initial: - self._raw_content = self._io.read_bytes((1536 - 4)) - io = KaitaiStream(BytesIO(self._raw_content)) - self.content = self._root.TextInitial(io, self, self._root) - self.content._read() - else: - self.content = self._io.read_bytes((1536 - 4)) - self._debug['content']['end'] = self._io.pos() - - - class TextContinuation(KaitaiStruct): - SEQ_FIELDS = ["tdata"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tdata']['start'] = self._io.pos() - self.tdata = (self._io.read_bytes(1532)).decode(u"ascii") - self._debug['tdata']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/sqlite3.py b/python/examples/kaitai/sqlite3.py deleted file mode 100644 index 1db1a375..00000000 --- a/python/examples/kaitai/sqlite3.py +++ /dev/null @@ -1,469 +0,0 @@ -# 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 -import collections - - -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)) - -from .vlq_base128_be import VlqBase128Be -class Sqlite3(KaitaiStruct): - """SQLite3 is a popular serverless SQL engine, implemented as a library - to be used within other applications. It keeps its databases as - regular disk files. - - Every database file is segmented into pages. First page (starting at - the very beginning) is special: it contains a file-global header - which specifies some data relevant to proper parsing (i.e. format - versions, size of page, etc). After the header, normal contents of - the first page follow. - - Each page would be of some type, and generally, they would be - reached via the links starting from the first page. First page type - (`root_page`) is always "btree_page". - - .. seealso:: - Source - https://www.sqlite.org/fileformat.html - """ - - class Versions(Enum): - legacy = 1 - wal = 2 - - class Encodings(Enum): - utf_8 = 1 - utf_16le = 2 - utf_16be = 3 - SEQ_FIELDS = ["magic", "len_page_mod", "write_version", "read_version", "reserved_space", "max_payload_frac", "min_payload_frac", "leaf_payload_frac", "file_change_counter", "num_pages", "first_freelist_trunk_page", "num_freelist_pages", "schema_cookie", "schema_format", "def_page_cache_size", "largest_root_page", "text_encoding", "user_version", "is_incremental_vacuum", "application_id", "reserved", "version_valid_for", "sqlite_version_number", "root_page"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x53\x51\x4C\x69\x74\x65\x20\x66\x6F\x72\x6D\x61\x74\x20\x33\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['len_page_mod']['start'] = self._io.pos() - self.len_page_mod = self._io.read_u2be() - self._debug['len_page_mod']['end'] = self._io.pos() - self._debug['write_version']['start'] = self._io.pos() - self.write_version = KaitaiStream.resolve_enum(self._root.Versions, self._io.read_u1()) - self._debug['write_version']['end'] = self._io.pos() - self._debug['read_version']['start'] = self._io.pos() - self.read_version = KaitaiStream.resolve_enum(self._root.Versions, self._io.read_u1()) - self._debug['read_version']['end'] = self._io.pos() - self._debug['reserved_space']['start'] = self._io.pos() - self.reserved_space = self._io.read_u1() - self._debug['reserved_space']['end'] = self._io.pos() - self._debug['max_payload_frac']['start'] = self._io.pos() - self.max_payload_frac = self._io.read_u1() - self._debug['max_payload_frac']['end'] = self._io.pos() - self._debug['min_payload_frac']['start'] = self._io.pos() - self.min_payload_frac = self._io.read_u1() - self._debug['min_payload_frac']['end'] = self._io.pos() - self._debug['leaf_payload_frac']['start'] = self._io.pos() - self.leaf_payload_frac = self._io.read_u1() - self._debug['leaf_payload_frac']['end'] = self._io.pos() - self._debug['file_change_counter']['start'] = self._io.pos() - self.file_change_counter = self._io.read_u4be() - self._debug['file_change_counter']['end'] = self._io.pos() - self._debug['num_pages']['start'] = self._io.pos() - self.num_pages = self._io.read_u4be() - self._debug['num_pages']['end'] = self._io.pos() - self._debug['first_freelist_trunk_page']['start'] = self._io.pos() - self.first_freelist_trunk_page = self._io.read_u4be() - self._debug['first_freelist_trunk_page']['end'] = self._io.pos() - self._debug['num_freelist_pages']['start'] = self._io.pos() - self.num_freelist_pages = self._io.read_u4be() - self._debug['num_freelist_pages']['end'] = self._io.pos() - self._debug['schema_cookie']['start'] = self._io.pos() - self.schema_cookie = self._io.read_u4be() - self._debug['schema_cookie']['end'] = self._io.pos() - self._debug['schema_format']['start'] = self._io.pos() - self.schema_format = self._io.read_u4be() - self._debug['schema_format']['end'] = self._io.pos() - self._debug['def_page_cache_size']['start'] = self._io.pos() - self.def_page_cache_size = self._io.read_u4be() - self._debug['def_page_cache_size']['end'] = self._io.pos() - self._debug['largest_root_page']['start'] = self._io.pos() - self.largest_root_page = self._io.read_u4be() - self._debug['largest_root_page']['end'] = self._io.pos() - self._debug['text_encoding']['start'] = self._io.pos() - self.text_encoding = KaitaiStream.resolve_enum(self._root.Encodings, self._io.read_u4be()) - self._debug['text_encoding']['end'] = self._io.pos() - self._debug['user_version']['start'] = self._io.pos() - self.user_version = self._io.read_u4be() - self._debug['user_version']['end'] = self._io.pos() - self._debug['is_incremental_vacuum']['start'] = self._io.pos() - self.is_incremental_vacuum = self._io.read_u4be() - self._debug['is_incremental_vacuum']['end'] = self._io.pos() - self._debug['application_id']['start'] = self._io.pos() - self.application_id = self._io.read_u4be() - self._debug['application_id']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(20) - self._debug['reserved']['end'] = self._io.pos() - self._debug['version_valid_for']['start'] = self._io.pos() - self.version_valid_for = self._io.read_u4be() - self._debug['version_valid_for']['end'] = self._io.pos() - self._debug['sqlite_version_number']['start'] = self._io.pos() - self.sqlite_version_number = self._io.read_u4be() - self._debug['sqlite_version_number']['end'] = self._io.pos() - self._debug['root_page']['start'] = self._io.pos() - self.root_page = self._root.BtreePage(self._io, self, self._root) - self.root_page._read() - self._debug['root_page']['end'] = self._io.pos() - - class Serial(KaitaiStruct): - SEQ_FIELDS = ["code"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = VlqBase128Be(self._io) - self.code._read() - self._debug['code']['end'] = self._io.pos() - - @property - def is_blob(self): - if hasattr(self, '_m_is_blob'): - return self._m_is_blob if hasattr(self, '_m_is_blob') else None - - self._m_is_blob = ((self.code.value >= 12) and ((self.code.value % 2) == 0)) - return self._m_is_blob if hasattr(self, '_m_is_blob') else None - - @property - def is_string(self): - if hasattr(self, '_m_is_string'): - return self._m_is_string if hasattr(self, '_m_is_string') else None - - self._m_is_string = ((self.code.value >= 13) and ((self.code.value % 2) == 1)) - return self._m_is_string if hasattr(self, '_m_is_string') else None - - @property - def len_content(self): - if hasattr(self, '_m_len_content'): - return self._m_len_content if hasattr(self, '_m_len_content') else None - - if self.code.value >= 12: - self._m_len_content = (self.code.value - 12) // 2 - - return self._m_len_content if hasattr(self, '_m_len_content') else None - - - class BtreePage(KaitaiStruct): - SEQ_FIELDS = ["page_type", "first_freeblock", "num_cells", "ofs_cells", "num_frag_free_bytes", "right_ptr", "cells"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['page_type']['start'] = self._io.pos() - self.page_type = self._io.read_u1() - self._debug['page_type']['end'] = self._io.pos() - self._debug['first_freeblock']['start'] = self._io.pos() - self.first_freeblock = self._io.read_u2be() - self._debug['first_freeblock']['end'] = self._io.pos() - self._debug['num_cells']['start'] = self._io.pos() - self.num_cells = self._io.read_u2be() - self._debug['num_cells']['end'] = self._io.pos() - self._debug['ofs_cells']['start'] = self._io.pos() - self.ofs_cells = self._io.read_u2be() - self._debug['ofs_cells']['end'] = self._io.pos() - self._debug['num_frag_free_bytes']['start'] = self._io.pos() - self.num_frag_free_bytes = self._io.read_u1() - self._debug['num_frag_free_bytes']['end'] = self._io.pos() - if ((self.page_type == 2) or (self.page_type == 5)) : - self._debug['right_ptr']['start'] = self._io.pos() - self.right_ptr = self._io.read_u4be() - self._debug['right_ptr']['end'] = self._io.pos() - - self._debug['cells']['start'] = self._io.pos() - self.cells = [None] * (self.num_cells) - for i in range(self.num_cells): - if not 'arr' in self._debug['cells']: - self._debug['cells']['arr'] = [] - self._debug['cells']['arr'].append({'start': self._io.pos()}) - _t_cells = self._root.RefCell(self._io, self, self._root) - _t_cells._read() - self.cells[i] = _t_cells - self._debug['cells']['arr'][i]['end'] = self._io.pos() - - self._debug['cells']['end'] = self._io.pos() - - - class CellIndexLeaf(KaitaiStruct): - """ - .. seealso:: - Source - https://www.sqlite.org/fileformat.html#b_tree_pages - """ - SEQ_FIELDS = ["len_payload", "payload"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_payload']['start'] = self._io.pos() - self.len_payload = VlqBase128Be(self._io) - self.len_payload._read() - self._debug['len_payload']['end'] = self._io.pos() - self._debug['payload']['start'] = self._io.pos() - self._raw_payload = self._io.read_bytes(self.len_payload.value) - io = KaitaiStream(BytesIO(self._raw_payload)) - self.payload = self._root.CellPayload(io, self, self._root) - self.payload._read() - self._debug['payload']['end'] = self._io.pos() - - - class Serials(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = VlqBase128Be(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() - - - class CellTableLeaf(KaitaiStruct): - """ - .. seealso:: - Source - https://www.sqlite.org/fileformat.html#b_tree_pages - """ - SEQ_FIELDS = ["len_payload", "row_id", "payload"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_payload']['start'] = self._io.pos() - self.len_payload = VlqBase128Be(self._io) - self.len_payload._read() - self._debug['len_payload']['end'] = self._io.pos() - self._debug['row_id']['start'] = self._io.pos() - self.row_id = VlqBase128Be(self._io) - self.row_id._read() - self._debug['row_id']['end'] = self._io.pos() - self._debug['payload']['start'] = self._io.pos() - self._raw_payload = self._io.read_bytes(self.len_payload.value) - io = KaitaiStream(BytesIO(self._raw_payload)) - self.payload = self._root.CellPayload(io, self, self._root) - self.payload._read() - self._debug['payload']['end'] = self._io.pos() - - - class CellPayload(KaitaiStruct): - """ - .. seealso:: - Source - https://sqlite.org/fileformat2.html#record_format - """ - SEQ_FIELDS = ["len_header_and_len", "column_serials", "column_contents"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_header_and_len']['start'] = self._io.pos() - self.len_header_and_len = VlqBase128Be(self._io) - self.len_header_and_len._read() - self._debug['len_header_and_len']['end'] = self._io.pos() - self._debug['column_serials']['start'] = self._io.pos() - self._raw_column_serials = self._io.read_bytes((self.len_header_and_len.value - 1)) - io = KaitaiStream(BytesIO(self._raw_column_serials)) - self.column_serials = self._root.Serials(io, self, self._root) - self.column_serials._read() - self._debug['column_serials']['end'] = self._io.pos() - self._debug['column_contents']['start'] = self._io.pos() - self.column_contents = [None] * (len(self.column_serials.entries)) - for i in range(len(self.column_serials.entries)): - if not 'arr' in self._debug['column_contents']: - self._debug['column_contents']['arr'] = [] - self._debug['column_contents']['arr'].append({'start': self._io.pos()}) - _t_column_contents = self._root.ColumnContent(self.column_serials.entries[i], self._io, self, self._root) - _t_column_contents._read() - self.column_contents[i] = _t_column_contents - self._debug['column_contents']['arr'][i]['end'] = self._io.pos() - - self._debug['column_contents']['end'] = self._io.pos() - - - class CellTableInterior(KaitaiStruct): - """ - .. seealso:: - Source - https://www.sqlite.org/fileformat.html#b_tree_pages - """ - SEQ_FIELDS = ["left_child_page", "row_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left_child_page']['start'] = self._io.pos() - self.left_child_page = self._io.read_u4be() - self._debug['left_child_page']['end'] = self._io.pos() - self._debug['row_id']['start'] = self._io.pos() - self.row_id = VlqBase128Be(self._io) - self.row_id._read() - self._debug['row_id']['end'] = self._io.pos() - - - class CellIndexInterior(KaitaiStruct): - """ - .. seealso:: - Source - https://www.sqlite.org/fileformat.html#b_tree_pages - """ - SEQ_FIELDS = ["left_child_page", "len_payload", "payload"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left_child_page']['start'] = self._io.pos() - self.left_child_page = self._io.read_u4be() - self._debug['left_child_page']['end'] = self._io.pos() - self._debug['len_payload']['start'] = self._io.pos() - self.len_payload = VlqBase128Be(self._io) - self.len_payload._read() - self._debug['len_payload']['end'] = self._io.pos() - self._debug['payload']['start'] = self._io.pos() - self._raw_payload = self._io.read_bytes(self.len_payload.value) - io = KaitaiStream(BytesIO(self._raw_payload)) - self.payload = self._root.CellPayload(io, self, self._root) - self.payload._read() - self._debug['payload']['end'] = self._io.pos() - - - class ColumnContent(KaitaiStruct): - SEQ_FIELDS = ["as_int", "as_float", "as_blob", "as_str"] - def __init__(self, ser, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self.ser = ser - self._debug = collections.defaultdict(dict) - - def _read(self): - if ((self.serial_type.code.value >= 1) and (self.serial_type.code.value <= 6)) : - self._debug['as_int']['start'] = self._io.pos() - _on = self.serial_type.code.value - if _on == 4: - self.as_int = self._io.read_u4be() - elif _on == 6: - self.as_int = self._io.read_u8be() - elif _on == 1: - self.as_int = self._io.read_u1() - elif _on == 3: - self.as_int = self._io.read_bits_int(24) - elif _on == 5: - self.as_int = self._io.read_bits_int(48) - elif _on == 2: - self.as_int = self._io.read_u2be() - self._debug['as_int']['end'] = self._io.pos() - - if self.serial_type.code.value == 7: - self._debug['as_float']['start'] = self._io.pos() - self.as_float = self._io.read_f8be() - self._debug['as_float']['end'] = self._io.pos() - - if self.serial_type.is_blob: - self._debug['as_blob']['start'] = self._io.pos() - self.as_blob = self._io.read_bytes(self.serial_type.len_content) - self._debug['as_blob']['end'] = self._io.pos() - - self._debug['as_str']['start'] = self._io.pos() - self.as_str = (self._io.read_bytes(self.serial_type.len_content)).decode(u"UTF-8") - self._debug['as_str']['end'] = self._io.pos() - - @property - def serial_type(self): - if hasattr(self, '_m_serial_type'): - return self._m_serial_type if hasattr(self, '_m_serial_type') else None - - self._m_serial_type = self.ser - return self._m_serial_type if hasattr(self, '_m_serial_type') else None - - - class RefCell(KaitaiStruct): - SEQ_FIELDS = ["ofs_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ofs_body']['start'] = self._io.pos() - self.ofs_body = self._io.read_u2be() - self._debug['ofs_body']['end'] = self._io.pos() - - @property - def body(self): - if hasattr(self, '_m_body'): - return self._m_body if hasattr(self, '_m_body') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_body) - self._debug['_m_body']['start'] = self._io.pos() - _on = self._parent.page_type - if _on == 13: - self._m_body = self._root.CellTableLeaf(self._io, self, self._root) - self._m_body._read() - elif _on == 5: - self._m_body = self._root.CellTableInterior(self._io, self, self._root) - self._m_body._read() - elif _on == 10: - self._m_body = self._root.CellIndexLeaf(self._io, self, self._root) - self._m_body._read() - elif _on == 2: - self._m_body = self._root.CellIndexInterior(self._io, self, self._root) - self._m_body._read() - self._debug['_m_body']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_body if hasattr(self, '_m_body') else None - - - @property - def len_page(self): - if hasattr(self, '_m_len_page'): - return self._m_len_page if hasattr(self, '_m_len_page') else None - - self._m_len_page = (65536 if self.len_page_mod == 1 else self.len_page_mod) - return self._m_len_page if hasattr(self, '_m_len_page') else None - - diff --git a/python/examples/kaitai/ssh_public_key.py b/python/examples/kaitai/ssh_public_key.py deleted file mode 100644 index bf1375d6..00000000 --- a/python/examples/kaitai/ssh_public_key.py +++ /dev/null @@ -1,251 +0,0 @@ -# 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 -import collections - - -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 SshPublicKey(KaitaiStruct): - """SSH public keys are encoded in a special binary format, typically represented - to end users as either one-liner OpenSSH format or multi-line PEM format - (commerical SSH). Text wrapper carries extra information about user who - created the key, comment, etc, but the inner binary is always base64-encoded - and follows the same internal format. - - This format spec deals with this internal binary format (called "blob" in - openssh sources) only. Buffer is expected to be raw binary and not base64-d. - Implementation closely follows code in OpenSSH. - - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L1970 - """ - SEQ_FIELDS = ["key_name", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key_name']['start'] = self._io.pos() - self.key_name = self._root.Cstring(self._io, self, self._root) - self.key_name._read() - self._debug['key_name']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.key_name.value - if _on == u"ssh-rsa": - self.body = self._root.KeyRsa(self._io, self, self._root) - self.body._read() - elif _on == u"ecdsa-sha2-nistp256": - self.body = self._root.KeyEcdsa(self._io, self, self._root) - self.body._read() - elif _on == u"ssh-ed25519": - self.body = self._root.KeyEd25519(self._io, self, self._root) - self.body._read() - elif _on == u"ssh-dss": - self.body = self._root.KeyDsa(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - class KeyRsa(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L2011-L2028 - """ - SEQ_FIELDS = ["rsa_e", "rsa_n"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['rsa_e']['start'] = self._io.pos() - self.rsa_e = self._root.Bignum2(self._io, self, self._root) - self.rsa_e._read() - self._debug['rsa_e']['end'] = self._io.pos() - self._debug['rsa_n']['start'] = self._io.pos() - self.rsa_n = self._root.Bignum2(self._io, self, self._root) - self.rsa_n._read() - self._debug['rsa_n']['end'] = self._io.pos() - - @property - def key_length(self): - """Key length in bits.""" - if hasattr(self, '_m_key_length'): - return self._m_key_length if hasattr(self, '_m_key_length') else None - - self._m_key_length = self.rsa_n.length_in_bits - return self._m_key_length if hasattr(self, '_m_key_length') else None - - - class KeyEd25519(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L2111-L2124 - """ - SEQ_FIELDS = ["len_pk", "pk"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_pk']['start'] = self._io.pos() - self.len_pk = self._io.read_u4be() - self._debug['len_pk']['end'] = self._io.pos() - self._debug['pk']['start'] = self._io.pos() - self.pk = self._io.read_bytes(self.len_pk) - self._debug['pk']['end'] = self._io.pos() - - - class KeyEcdsa(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L2060-L2103 - """ - SEQ_FIELDS = ["curve_name", "ec"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['curve_name']['start'] = self._io.pos() - self.curve_name = self._root.Cstring(self._io, self, self._root) - self.curve_name._read() - self._debug['curve_name']['end'] = self._io.pos() - self._debug['ec']['start'] = self._io.pos() - self.ec = self._root.EllipticCurve(self._io, self, self._root) - self.ec._read() - self._debug['ec']['end'] = self._io.pos() - - - class Cstring(KaitaiStruct): - """A integer-prefixed string designed to be read using `sshbuf_get_cstring` - and written by `sshbuf_put_cstring` routines in ssh sources. Name is an - obscure misnomer, as typically "C string" means a null-terminated string. - - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshbuf-getput-basic.c#L181 - """ - SEQ_FIELDS = ["len", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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['value']['start'] = self._io.pos() - self.value = (self._io.read_bytes(self.len)).decode(u"ASCII") - self._debug['value']['end'] = self._io.pos() - - - class KeyDsa(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L2036-L2051 - """ - SEQ_FIELDS = ["dsa_p", "dsa_q", "dsa_g", "dsa_pub_key"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dsa_p']['start'] = self._io.pos() - self.dsa_p = self._root.Bignum2(self._io, self, self._root) - self.dsa_p._read() - self._debug['dsa_p']['end'] = self._io.pos() - self._debug['dsa_q']['start'] = self._io.pos() - self.dsa_q = self._root.Bignum2(self._io, self, self._root) - self.dsa_q._read() - self._debug['dsa_q']['end'] = self._io.pos() - self._debug['dsa_g']['start'] = self._io.pos() - self.dsa_g = self._root.Bignum2(self._io, self, self._root) - self.dsa_g._read() - self._debug['dsa_g']['end'] = self._io.pos() - self._debug['dsa_pub_key']['start'] = self._io.pos() - self.dsa_pub_key = self._root.Bignum2(self._io, self, self._root) - self.dsa_pub_key._read() - self._debug['dsa_pub_key']['end'] = self._io.pos() - - - class EllipticCurve(KaitaiStruct): - """Elliptic curve dump format used by ssh. In OpenSSH code, the following - routines are used to read/write it: - - * sshbuf_get_ec - * get_ec - - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshbuf-getput-crypto.c#L90 - https://github.com/openssh/openssh-portable/blob/master/sshbuf-getput-crypto.c#L76 - """ - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len) - self._debug['body']['end'] = self._io.pos() - - - class Bignum2(KaitaiStruct): - """Big integers serialization format used by ssh, v2. In the code, the following - routines are used to read/write it: - - * sshbuf_get_bignum2 - * sshbuf_get_bignum2_bytes_direct - * sshbuf_put_bignum2 - * sshbuf_get_bignum2_bytes_direct - - .. seealso:: - Source - https://github.com/openssh/openssh-portable/blob/master/sshbuf-getput-crypto.c#L35 - https://github.com/openssh/openssh-portable/blob/master/sshbuf-getput-basic.c#L431 - """ - SEQ_FIELDS = ["len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len) - self._debug['body']['end'] = self._io.pos() - - @property - def length_in_bits(self): - """Length of big integer in bits. In OpenSSH sources, this corresponds to - `BN_num_bits` function. - """ - if hasattr(self, '_m_length_in_bits'): - return self._m_length_in_bits if hasattr(self, '_m_length_in_bits') else None - - self._m_length_in_bits = ((self.len - 1) * 8) - return self._m_length_in_bits if hasattr(self, '_m_length_in_bits') else None - - - diff --git a/python/examples/kaitai/standard_midi_file.py b/python/examples/kaitai/standard_midi_file.py deleted file mode 100644 index f4723352..00000000 --- a/python/examples/kaitai/standard_midi_file.py +++ /dev/null @@ -1,385 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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)) - -from .vlq_base128_be import VlqBase128Be -class StandardMidiFile(KaitaiStruct): - """Standard MIDI file, typically knows just as "MID", is a standard way - to serialize series of MIDI events, which is a protocol used in many - music synthesizers to transfer music data: notes being played, - effects being applied, etc. - - Internally, file consists of a header and series of tracks, every - track listing MIDI events with certain header designating time these - events are happening. - - NOTE: Rarely, MIDI files employ certain stateful compression scheme - to avoid storing certain elements of further elements, instead - reusing them from events which happened earlier in the - stream. Kaitai Struct (as of v0.9) is currently unable to parse - these, but files employing this mechanism are relatively rare. - """ - SEQ_FIELDS = ["hdr", "tracks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hdr']['start'] = self._io.pos() - self.hdr = self._root.Header(self._io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - self._debug['tracks']['start'] = self._io.pos() - self.tracks = [None] * (self.hdr.num_tracks) - for i in range(self.hdr.num_tracks): - if not 'arr' in self._debug['tracks']: - self._debug['tracks']['arr'] = [] - self._debug['tracks']['arr'].append({'start': self._io.pos()}) - _t_tracks = self._root.Track(self._io, self, self._root) - _t_tracks._read() - self.tracks[i] = _t_tracks - self._debug['tracks']['arr'][i]['end'] = self._io.pos() - - self._debug['tracks']['end'] = self._io.pos() - - class TrackEvents(KaitaiStruct): - SEQ_FIELDS = ["event"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['event']['start'] = self._io.pos() - self.event = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['event']: - self._debug['event']['arr'] = [] - self._debug['event']['arr'].append({'start': self._io.pos()}) - _t_event = self._root.TrackEvent(self._io, self, self._root) - _t_event._read() - self.event.append(_t_event) - self._debug['event']['arr'][len(self.event) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['event']['end'] = self._io.pos() - - - class TrackEvent(KaitaiStruct): - SEQ_FIELDS = ["v_time", "event_header", "meta_event_body", "sysex_body", "event_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['v_time']['start'] = self._io.pos() - self.v_time = VlqBase128Be(self._io) - self.v_time._read() - self._debug['v_time']['end'] = self._io.pos() - self._debug['event_header']['start'] = self._io.pos() - self.event_header = self._io.read_u1() - self._debug['event_header']['end'] = self._io.pos() - if self.event_header == 255: - self._debug['meta_event_body']['start'] = self._io.pos() - self.meta_event_body = self._root.MetaEventBody(self._io, self, self._root) - self.meta_event_body._read() - self._debug['meta_event_body']['end'] = self._io.pos() - - if self.event_header == 240: - self._debug['sysex_body']['start'] = self._io.pos() - self.sysex_body = self._root.SysexEventBody(self._io, self, self._root) - self.sysex_body._read() - self._debug['sysex_body']['end'] = self._io.pos() - - self._debug['event_body']['start'] = self._io.pos() - _on = self.event_type - if _on == 224: - self.event_body = self._root.PitchBendEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 144: - self.event_body = self._root.NoteOnEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 208: - self.event_body = self._root.ChannelPressureEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 192: - self.event_body = self._root.ProgramChangeEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 160: - self.event_body = self._root.PolyphonicPressureEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 176: - self.event_body = self._root.ControllerEvent(self._io, self, self._root) - self.event_body._read() - elif _on == 128: - self.event_body = self._root.NoteOffEvent(self._io, self, self._root) - self.event_body._read() - self._debug['event_body']['end'] = self._io.pos() - - @property - def event_type(self): - if hasattr(self, '_m_event_type'): - return self._m_event_type if hasattr(self, '_m_event_type') else None - - self._m_event_type = (self.event_header & 240) - return self._m_event_type if hasattr(self, '_m_event_type') else None - - @property - def channel(self): - if hasattr(self, '_m_channel'): - return self._m_channel if hasattr(self, '_m_channel') else None - - if self.event_type != 240: - self._m_channel = (self.event_header & 15) - - return self._m_channel if hasattr(self, '_m_channel') else None - - - class PitchBendEvent(KaitaiStruct): - SEQ_FIELDS = ["b1", "b2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - self._debug['b2']['start'] = self._io.pos() - self.b2 = self._io.read_u1() - self._debug['b2']['end'] = self._io.pos() - - @property - def bend_value(self): - if hasattr(self, '_m_bend_value'): - return self._m_bend_value if hasattr(self, '_m_bend_value') else None - - self._m_bend_value = (((self.b2 << 7) + self.b1) - 16384) - return self._m_bend_value if hasattr(self, '_m_bend_value') else None - - @property - def adj_bend_value(self): - if hasattr(self, '_m_adj_bend_value'): - return self._m_adj_bend_value if hasattr(self, '_m_adj_bend_value') else None - - self._m_adj_bend_value = (self.bend_value - 16384) - return self._m_adj_bend_value if hasattr(self, '_m_adj_bend_value') else None - - - class ProgramChangeEvent(KaitaiStruct): - SEQ_FIELDS = ["program"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['program']['start'] = self._io.pos() - self.program = self._io.read_u1() - self._debug['program']['end'] = self._io.pos() - - - class NoteOnEvent(KaitaiStruct): - SEQ_FIELDS = ["note", "velocity"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['note']['start'] = self._io.pos() - self.note = self._io.read_u1() - self._debug['note']['end'] = self._io.pos() - self._debug['velocity']['start'] = self._io.pos() - self.velocity = self._io.read_u1() - self._debug['velocity']['end'] = self._io.pos() - - - class PolyphonicPressureEvent(KaitaiStruct): - SEQ_FIELDS = ["note", "pressure"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['note']['start'] = self._io.pos() - self.note = self._io.read_u1() - self._debug['note']['end'] = self._io.pos() - self._debug['pressure']['start'] = self._io.pos() - self.pressure = self._io.read_u1() - self._debug['pressure']['end'] = self._io.pos() - - - class Track(KaitaiStruct): - SEQ_FIELDS = ["magic", "len_events", "events"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4D\x54\x72\x6B") - self._debug['magic']['end'] = self._io.pos() - self._debug['len_events']['start'] = self._io.pos() - self.len_events = self._io.read_u4be() - self._debug['len_events']['end'] = self._io.pos() - self._debug['events']['start'] = self._io.pos() - self._raw_events = self._io.read_bytes(self.len_events) - io = KaitaiStream(BytesIO(self._raw_events)) - self.events = self._root.TrackEvents(io, self, self._root) - self.events._read() - self._debug['events']['end'] = self._io.pos() - - - class MetaEventBody(KaitaiStruct): - - class MetaTypeEnum(Enum): - sequence_number = 0 - text_event = 1 - copyright = 2 - sequence_track_name = 3 - instrument_name = 4 - lyric_text = 5 - marker_text = 6 - cue_point = 7 - midi_channel_prefix_assignment = 32 - end_of_track = 47 - tempo = 81 - smpte_offset = 84 - time_signature = 88 - key_signature = 89 - sequencer_specific_event = 127 - SEQ_FIELDS = ["meta_type", "len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['meta_type']['start'] = self._io.pos() - self.meta_type = KaitaiStream.resolve_enum(self._root.MetaEventBody.MetaTypeEnum, self._io.read_u1()) - self._debug['meta_type']['end'] = self._io.pos() - self._debug['len']['start'] = self._io.pos() - self.len = VlqBase128Be(self._io) - self.len._read() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.len.value) - self._debug['body']['end'] = self._io.pos() - - - class ControllerEvent(KaitaiStruct): - SEQ_FIELDS = ["controller", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['controller']['start'] = self._io.pos() - self.controller = self._io.read_u1() - self._debug['controller']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_u1() - self._debug['value']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - SEQ_FIELDS = ["magic", "len_header", "format", "num_tracks", "division"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4D\x54\x68\x64") - self._debug['magic']['end'] = self._io.pos() - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u4be() - self._debug['len_header']['end'] = self._io.pos() - self._debug['format']['start'] = self._io.pos() - self.format = self._io.read_u2be() - self._debug['format']['end'] = self._io.pos() - self._debug['num_tracks']['start'] = self._io.pos() - self.num_tracks = self._io.read_u2be() - self._debug['num_tracks']['end'] = self._io.pos() - self._debug['division']['start'] = self._io.pos() - self.division = self._io.read_s2be() - self._debug['division']['end'] = self._io.pos() - - - class SysexEventBody(KaitaiStruct): - SEQ_FIELDS = ["len", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = VlqBase128Be(self._io) - self.len._read() - self._debug['len']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.len.value) - self._debug['data']['end'] = self._io.pos() - - - class NoteOffEvent(KaitaiStruct): - SEQ_FIELDS = ["note", "velocity"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['note']['start'] = self._io.pos() - self.note = self._io.read_u1() - self._debug['note']['end'] = self._io.pos() - self._debug['velocity']['start'] = self._io.pos() - self.velocity = self._io.read_u1() - self._debug['velocity']['end'] = self._io.pos() - - - class ChannelPressureEvent(KaitaiStruct): - SEQ_FIELDS = ["pressure"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pressure']['start'] = self._io.pos() - self.pressure = self._io.read_u1() - self._debug['pressure']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/stl.py b/python/examples/kaitai/stl.py deleted file mode 100644 index 18971107..00000000 --- a/python/examples/kaitai/stl.py +++ /dev/null @@ -1,107 +0,0 @@ -# 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 -import collections - - -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 Stl(KaitaiStruct): - """STL files are used to represent simple 3D models, defined using - triangular 3D faces. - - Initially it was introduced as native format for 3D Systems - Stereolithography CAD system, but due to its extreme simplicity, it - was adopted by a wide range of 3D modelling, CAD, rapid prototyping - and 3D printing applications as the simplest 3D model exchange - format. - - STL is extremely bare-bones format: there are no complex headers, no - texture / color support, no units specifications, no distinct vertex - arrays. Whole model is specified as a collection of triangular - faces. - - There are two versions of the format (text and binary), this spec - describes binary version. - """ - SEQ_FIELDS = ["header", "num_triangles", "triangles"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._io.read_bytes(80) - self._debug['header']['end'] = self._io.pos() - self._debug['num_triangles']['start'] = self._io.pos() - self.num_triangles = self._io.read_u4le() - self._debug['num_triangles']['end'] = self._io.pos() - self._debug['triangles']['start'] = self._io.pos() - self.triangles = [None] * (self.num_triangles) - for i in range(self.num_triangles): - if not 'arr' in self._debug['triangles']: - self._debug['triangles']['arr'] = [] - self._debug['triangles']['arr'].append({'start': self._io.pos()}) - _t_triangles = self._root.Triangle(self._io, self, self._root) - _t_triangles._read() - self.triangles[i] = _t_triangles - self._debug['triangles']['arr'][i]['end'] = self._io.pos() - - self._debug['triangles']['end'] = self._io.pos() - - class Triangle(KaitaiStruct): - """Each STL triangle is defined by its 3 points in 3D space and a - normal vector, which is generally used to determine where is - "inside" and "outside" of the model. - """ - SEQ_FIELDS = ["normal", "vertices"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['normal']['start'] = self._io.pos() - self.normal = self._root.Vec3d(self._io, self, self._root) - self.normal._read() - self._debug['normal']['end'] = self._io.pos() - self._debug['vertices']['start'] = self._io.pos() - self.vertices = [None] * (3) - for i in range(3): - if not 'arr' in self._debug['vertices']: - self._debug['vertices']['arr'] = [] - self._debug['vertices']['arr'].append({'start': self._io.pos()}) - _t_vertices = self._root.Vec3d(self._io, self, self._root) - _t_vertices._read() - self.vertices[i] = _t_vertices - self._debug['vertices']['arr'][i]['end'] = self._io.pos() - - self._debug['vertices']['end'] = self._io.pos() - - - class Vec3d(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "z"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_f4le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_f4le() - self._debug['y']['end'] = self._io.pos() - self._debug['z']['start'] = self._io.pos() - self.z = self._io.read_f4le() - self._debug['z']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/swf.py b/python/examples/kaitai/swf.py deleted file mode 100644 index dc39fd00..00000000 --- a/python/examples/kaitai/swf.py +++ /dev/null @@ -1,403 +0,0 @@ -# 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 -import collections -import zlib - - -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 Swf(KaitaiStruct): - """SWF files are used by Adobe Flash (AKA Shockwave Flash, Macromedia - Flash) to encode rich interactive multimedia content and are, - essentially, a container for special bytecode instructions to play - back that content. In early 2000s, it was dominant rich multimedia - web format (.swf files were integrated into web pages and played - back with a browser plugin), but its usage largely declined in - 2010s, as HTML5 and performant browser-native solutions - (i.e. JavaScript engines and graphical approaches, such as WebGL) - emerged. - - There are a lot of versions of SWF (~36), format is somewhat - documented by Adobe. - - .. seealso:: - Source - https://www.adobe.com/content/dam/acom/en/devnet/pdf/swf-file-format-spec.pdf - """ - - class Compressions(Enum): - zlib = 67 - none = 70 - lzma = 90 - - class TagType(Enum): - end_of_file = 0 - place_object = 4 - remove_object = 5 - set_background_color = 9 - define_sound = 14 - place_object2 = 26 - remove_object2 = 28 - frame_label = 43 - export_assets = 56 - script_limits = 65 - file_attributes = 69 - place_object3 = 70 - symbol_class = 76 - metadata = 77 - define_scaling_grid = 78 - do_abc = 82 - define_scene_and_frame_label_data = 86 - SEQ_FIELDS = ["compression", "signature", "version", "len_file", "plain_body", "zlib_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['compression']['start'] = self._io.pos() - self.compression = KaitaiStream.resolve_enum(self._root.Compressions, self._io.read_u1()) - self._debug['compression']['end'] = self._io.pos() - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x57\x53") - self._debug['signature']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['len_file']['start'] = self._io.pos() - self.len_file = self._io.read_u4le() - self._debug['len_file']['end'] = self._io.pos() - if self.compression == self._root.Compressions.none: - self._debug['plain_body']['start'] = self._io.pos() - self._raw_plain_body = self._io.read_bytes_full() - io = KaitaiStream(BytesIO(self._raw_plain_body)) - self.plain_body = self._root.SwfBody(io, self, self._root) - self.plain_body._read() - self._debug['plain_body']['end'] = self._io.pos() - - if self.compression == self._root.Compressions.zlib: - self._debug['zlib_body']['start'] = self._io.pos() - self._raw__raw_zlib_body = self._io.read_bytes_full() - self._raw_zlib_body = zlib.decompress(self._raw__raw_zlib_body) - io = KaitaiStream(BytesIO(self._raw_zlib_body)) - self.zlib_body = self._root.SwfBody(io, self, self._root) - self.zlib_body._read() - self._debug['zlib_body']['end'] = self._io.pos() - - - class Rgb(KaitaiStruct): - SEQ_FIELDS = ["r", "g", "b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['r']['start'] = self._io.pos() - self.r = self._io.read_u1() - self._debug['r']['end'] = self._io.pos() - self._debug['g']['start'] = self._io.pos() - self.g = self._io.read_u1() - self._debug['g']['end'] = self._io.pos() - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - - - class DoAbcBody(KaitaiStruct): - SEQ_FIELDS = ["flags", "name", "abcdata"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - self._debug['abcdata']['start'] = self._io.pos() - self.abcdata = self._io.read_bytes_full() - self._debug['abcdata']['end'] = self._io.pos() - - - class SwfBody(KaitaiStruct): - SEQ_FIELDS = ["rect", "frame_rate", "frame_count", "file_attributes_tag", "tags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['rect']['start'] = self._io.pos() - self.rect = self._root.Rect(self._io, self, self._root) - self.rect._read() - self._debug['rect']['end'] = self._io.pos() - self._debug['frame_rate']['start'] = self._io.pos() - self.frame_rate = self._io.read_u2le() - self._debug['frame_rate']['end'] = self._io.pos() - self._debug['frame_count']['start'] = self._io.pos() - self.frame_count = self._io.read_u2le() - self._debug['frame_count']['end'] = self._io.pos() - if self._root.version >= 8: - self._debug['file_attributes_tag']['start'] = self._io.pos() - self.file_attributes_tag = self._root.Tag(self._io, self, self._root) - self.file_attributes_tag._read() - self._debug['file_attributes_tag']['end'] = self._io.pos() - - self._debug['tags']['start'] = self._io.pos() - self.tags = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['tags']: - self._debug['tags']['arr'] = [] - self._debug['tags']['arr'].append({'start': self._io.pos()}) - _t_tags = self._root.Tag(self._io, self, self._root) - _t_tags._read() - self.tags.append(_t_tags) - self._debug['tags']['arr'][len(self.tags) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['tags']['end'] = self._io.pos() - - - class Rect(KaitaiStruct): - SEQ_FIELDS = ["b1", "skip"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b1']['start'] = self._io.pos() - self.b1 = self._io.read_u1() - self._debug['b1']['end'] = self._io.pos() - self._debug['skip']['start'] = self._io.pos() - self.skip = self._io.read_bytes(self.num_bytes) - self._debug['skip']['end'] = self._io.pos() - - @property - def num_bits(self): - if hasattr(self, '_m_num_bits'): - return self._m_num_bits if hasattr(self, '_m_num_bits') else None - - self._m_num_bits = (self.b1 >> 3) - return self._m_num_bits if hasattr(self, '_m_num_bits') else None - - @property - def num_bytes(self): - if hasattr(self, '_m_num_bytes'): - return self._m_num_bytes if hasattr(self, '_m_num_bytes') else None - - self._m_num_bytes = (((self.num_bits * 4) - 3) + 7) // 8 - return self._m_num_bytes if hasattr(self, '_m_num_bytes') else None - - - class Tag(KaitaiStruct): - SEQ_FIELDS = ["record_header", "tag_body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['record_header']['start'] = self._io.pos() - self.record_header = self._root.RecordHeader(self._io, self, self._root) - self.record_header._read() - self._debug['record_header']['end'] = self._io.pos() - self._debug['tag_body']['start'] = self._io.pos() - _on = self.record_header.tag_type - if _on == self._root.TagType.define_sound: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.DefineSoundBody(io, self, self._root) - self.tag_body._read() - elif _on == self._root.TagType.set_background_color: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.Rgb(io, self, self._root) - self.tag_body._read() - elif _on == self._root.TagType.script_limits: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.ScriptLimitsBody(io, self, self._root) - self.tag_body._read() - elif _on == self._root.TagType.do_abc: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.DoAbcBody(io, self, self._root) - self.tag_body._read() - elif _on == self._root.TagType.export_assets: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.SymbolClassBody(io, self, self._root) - self.tag_body._read() - elif _on == self._root.TagType.symbol_class: - self._raw_tag_body = self._io.read_bytes(self.record_header.len) - io = KaitaiStream(BytesIO(self._raw_tag_body)) - self.tag_body = self._root.SymbolClassBody(io, self, self._root) - self.tag_body._read() - else: - self.tag_body = self._io.read_bytes(self.record_header.len) - self._debug['tag_body']['end'] = self._io.pos() - - - class SymbolClassBody(KaitaiStruct): - SEQ_FIELDS = ["num_symbols", "symbols"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_symbols']['start'] = self._io.pos() - self.num_symbols = self._io.read_u2le() - self._debug['num_symbols']['end'] = self._io.pos() - self._debug['symbols']['start'] = self._io.pos() - self.symbols = [None] * (self.num_symbols) - for i in range(self.num_symbols): - if not 'arr' in self._debug['symbols']: - self._debug['symbols']['arr'] = [] - self._debug['symbols']['arr'].append({'start': self._io.pos()}) - _t_symbols = self._root.SymbolClassBody.Symbol(self._io, self, self._root) - _t_symbols._read() - self.symbols[i] = _t_symbols - self._debug['symbols']['arr'][i]['end'] = self._io.pos() - - self._debug['symbols']['end'] = self._io.pos() - - class Symbol(KaitaiStruct): - SEQ_FIELDS = ["tag", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = self._io.read_u2le() - self._debug['tag']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ASCII") - self._debug['name']['end'] = self._io.pos() - - - - class DefineSoundBody(KaitaiStruct): - - class SamplingRates(Enum): - rate_5_5_khz = 0 - rate_11_khz = 1 - rate_22_khz = 2 - rate_44_khz = 3 - - class Bps(Enum): - sound_8_bit = 0 - sound_16_bit = 1 - - class Channels(Enum): - mono = 0 - stereo = 1 - SEQ_FIELDS = ["id", "format", "sampling_rate", "bits_per_sample", "num_channels", "num_samples"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['id']['start'] = self._io.pos() - self.id = self._io.read_u2le() - self._debug['id']['end'] = self._io.pos() - self._debug['format']['start'] = self._io.pos() - self.format = self._io.read_bits_int(4) - self._debug['format']['end'] = self._io.pos() - self._debug['sampling_rate']['start'] = self._io.pos() - self.sampling_rate = KaitaiStream.resolve_enum(self._root.DefineSoundBody.SamplingRates, self._io.read_bits_int(2)) - self._debug['sampling_rate']['end'] = self._io.pos() - self._debug['bits_per_sample']['start'] = self._io.pos() - self.bits_per_sample = KaitaiStream.resolve_enum(self._root.DefineSoundBody.Bps, self._io.read_bits_int(1)) - self._debug['bits_per_sample']['end'] = self._io.pos() - self._debug['num_channels']['start'] = self._io.pos() - self.num_channels = KaitaiStream.resolve_enum(self._root.DefineSoundBody.Channels, self._io.read_bits_int(1)) - self._debug['num_channels']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['num_samples']['start'] = self._io.pos() - self.num_samples = self._io.read_u4le() - self._debug['num_samples']['end'] = self._io.pos() - - - class RecordHeader(KaitaiStruct): - SEQ_FIELDS = ["tag_code_and_length", "big_len"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag_code_and_length']['start'] = self._io.pos() - self.tag_code_and_length = self._io.read_u2le() - self._debug['tag_code_and_length']['end'] = self._io.pos() - if self.small_len == 63: - self._debug['big_len']['start'] = self._io.pos() - self.big_len = self._io.read_s4le() - self._debug['big_len']['end'] = self._io.pos() - - - @property - def tag_type(self): - if hasattr(self, '_m_tag_type'): - return self._m_tag_type if hasattr(self, '_m_tag_type') else None - - self._m_tag_type = KaitaiStream.resolve_enum(self._root.TagType, (self.tag_code_and_length >> 6)) - return self._m_tag_type if hasattr(self, '_m_tag_type') else None - - @property - def small_len(self): - if hasattr(self, '_m_small_len'): - return self._m_small_len if hasattr(self, '_m_small_len') else None - - self._m_small_len = (self.tag_code_and_length & 63) - return self._m_small_len if hasattr(self, '_m_small_len') else None - - @property - def len(self): - if hasattr(self, '_m_len'): - return self._m_len if hasattr(self, '_m_len') else None - - self._m_len = (self.big_len if self.small_len == 63 else self.small_len) - return self._m_len if hasattr(self, '_m_len') else None - - - class ScriptLimitsBody(KaitaiStruct): - SEQ_FIELDS = ["max_recursion_depth", "script_timeout_seconds"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['max_recursion_depth']['start'] = self._io.pos() - self.max_recursion_depth = self._io.read_u2le() - self._debug['max_recursion_depth']['end'] = self._io.pos() - self._debug['script_timeout_seconds']['start'] = self._io.pos() - self.script_timeout_seconds = self._io.read_u2le() - self._debug['script_timeout_seconds']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/systemd_journal.py b/python/examples/kaitai/systemd_journal.py deleted file mode 100644 index 214757d9..00000000 --- a/python/examples/kaitai/systemd_journal.py +++ /dev/null @@ -1,358 +0,0 @@ -# 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 -import collections - - -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 SystemdJournal(KaitaiStruct): - """systemd, a popular user-space system/service management suite on Linux, - offers logging functionality, storing incoming logs in a binary journal - format. - - On live Linux system running systemd, these journals are typically located at: - - * /run/log/journal/machine-id/*.journal (volatile, lost after reboot) - * /var/log/journal/machine-id/*.journal (persistent, but disabled by default on Debian / Ubuntu) - - .. seealso:: - Source - https://www.freedesktop.org/wiki/Software/systemd/journal-files/ - """ - - class State(Enum): - offline = 0 - online = 1 - archived = 2 - SEQ_FIELDS = ["header", "objects"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes(self.len_header) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['objects']['start'] = self._io.pos() - self.objects = [None] * (self.header.num_objects) - for i in range(self.header.num_objects): - if not 'arr' in self._debug['objects']: - self._debug['objects']['arr'] = [] - self._debug['objects']['arr'].append({'start': self._io.pos()}) - _t_objects = self._root.JournalObject(self._io, self, self._root) - _t_objects._read() - self.objects[i] = _t_objects - self._debug['objects']['arr'][i]['end'] = self._io.pos() - - self._debug['objects']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["signature", "compatible_flags", "incompatible_flags", "state", "reserved", "file_id", "machine_id", "boot_id", "seqnum_id", "len_header", "len_arena", "ofs_data_hash_table", "len_data_hash_table", "ofs_field_hash_table", "len_field_hash_table", "ofs_tail_object", "num_objects", "num_entries", "tail_entry_seqnum", "head_entry_seqnum", "ofs_entry_array", "head_entry_realtime", "tail_entry_realtime", "tail_entry_monotonic", "num_data", "num_fields", "num_tags", "num_entry_arrays"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x4C\x50\x4B\x53\x48\x48\x52\x48") - self._debug['signature']['end'] = self._io.pos() - self._debug['compatible_flags']['start'] = self._io.pos() - self.compatible_flags = self._io.read_u4le() - self._debug['compatible_flags']['end'] = self._io.pos() - self._debug['incompatible_flags']['start'] = self._io.pos() - self.incompatible_flags = self._io.read_u4le() - self._debug['incompatible_flags']['end'] = self._io.pos() - self._debug['state']['start'] = self._io.pos() - self.state = KaitaiStream.resolve_enum(self._root.State, self._io.read_u1()) - self._debug['state']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(7) - self._debug['reserved']['end'] = self._io.pos() - self._debug['file_id']['start'] = self._io.pos() - self.file_id = self._io.read_bytes(16) - self._debug['file_id']['end'] = self._io.pos() - self._debug['machine_id']['start'] = self._io.pos() - self.machine_id = self._io.read_bytes(16) - self._debug['machine_id']['end'] = self._io.pos() - self._debug['boot_id']['start'] = self._io.pos() - self.boot_id = self._io.read_bytes(16) - self._debug['boot_id']['end'] = self._io.pos() - self._debug['seqnum_id']['start'] = self._io.pos() - self.seqnum_id = self._io.read_bytes(16) - self._debug['seqnum_id']['end'] = self._io.pos() - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u8le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['len_arena']['start'] = self._io.pos() - self.len_arena = self._io.read_u8le() - self._debug['len_arena']['end'] = self._io.pos() - self._debug['ofs_data_hash_table']['start'] = self._io.pos() - self.ofs_data_hash_table = self._io.read_u8le() - self._debug['ofs_data_hash_table']['end'] = self._io.pos() - self._debug['len_data_hash_table']['start'] = self._io.pos() - self.len_data_hash_table = self._io.read_u8le() - self._debug['len_data_hash_table']['end'] = self._io.pos() - self._debug['ofs_field_hash_table']['start'] = self._io.pos() - self.ofs_field_hash_table = self._io.read_u8le() - self._debug['ofs_field_hash_table']['end'] = self._io.pos() - self._debug['len_field_hash_table']['start'] = self._io.pos() - self.len_field_hash_table = self._io.read_u8le() - self._debug['len_field_hash_table']['end'] = self._io.pos() - self._debug['ofs_tail_object']['start'] = self._io.pos() - self.ofs_tail_object = self._io.read_u8le() - self._debug['ofs_tail_object']['end'] = self._io.pos() - self._debug['num_objects']['start'] = self._io.pos() - self.num_objects = self._io.read_u8le() - self._debug['num_objects']['end'] = self._io.pos() - self._debug['num_entries']['start'] = self._io.pos() - self.num_entries = self._io.read_u8le() - self._debug['num_entries']['end'] = self._io.pos() - self._debug['tail_entry_seqnum']['start'] = self._io.pos() - self.tail_entry_seqnum = self._io.read_u8le() - self._debug['tail_entry_seqnum']['end'] = self._io.pos() - self._debug['head_entry_seqnum']['start'] = self._io.pos() - self.head_entry_seqnum = self._io.read_u8le() - self._debug['head_entry_seqnum']['end'] = self._io.pos() - self._debug['ofs_entry_array']['start'] = self._io.pos() - self.ofs_entry_array = self._io.read_u8le() - self._debug['ofs_entry_array']['end'] = self._io.pos() - self._debug['head_entry_realtime']['start'] = self._io.pos() - self.head_entry_realtime = self._io.read_u8le() - self._debug['head_entry_realtime']['end'] = self._io.pos() - self._debug['tail_entry_realtime']['start'] = self._io.pos() - self.tail_entry_realtime = self._io.read_u8le() - self._debug['tail_entry_realtime']['end'] = self._io.pos() - self._debug['tail_entry_monotonic']['start'] = self._io.pos() - self.tail_entry_monotonic = self._io.read_u8le() - self._debug['tail_entry_monotonic']['end'] = self._io.pos() - if not (self._io.is_eof()): - self._debug['num_data']['start'] = self._io.pos() - self.num_data = self._io.read_u8le() - self._debug['num_data']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['num_fields']['start'] = self._io.pos() - self.num_fields = self._io.read_u8le() - self._debug['num_fields']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['num_tags']['start'] = self._io.pos() - self.num_tags = self._io.read_u8le() - self._debug['num_tags']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['num_entry_arrays']['start'] = self._io.pos() - self.num_entry_arrays = self._io.read_u8le() - self._debug['num_entry_arrays']['end'] = self._io.pos() - - - - class JournalObject(KaitaiStruct): - """ - .. seealso:: - Source - https://www.freedesktop.org/wiki/Software/systemd/journal-files/#objects - """ - - class ObjectTypes(Enum): - unused = 0 - data = 1 - field = 2 - entry = 3 - data_hash_table = 4 - field_hash_table = 5 - entry_array = 6 - tag = 7 - SEQ_FIELDS = ["padding", "object_type", "flags", "reserved", "len_object", "payload"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_bytes(((8 - self._io.pos()) % 8)) - self._debug['padding']['end'] = self._io.pos() - self._debug['object_type']['start'] = self._io.pos() - self.object_type = KaitaiStream.resolve_enum(self._root.JournalObject.ObjectTypes, self._io.read_u1()) - self._debug['object_type']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(6) - self._debug['reserved']['end'] = self._io.pos() - self._debug['len_object']['start'] = self._io.pos() - self.len_object = self._io.read_u8le() - self._debug['len_object']['end'] = self._io.pos() - self._debug['payload']['start'] = self._io.pos() - _on = self.object_type - if _on == self._root.JournalObject.ObjectTypes.data: - self._raw_payload = self._io.read_bytes((self.len_object - 16)) - io = KaitaiStream(BytesIO(self._raw_payload)) - self.payload = self._root.DataObject(io, self, self._root) - self.payload._read() - else: - self.payload = self._io.read_bytes((self.len_object - 16)) - self._debug['payload']['end'] = self._io.pos() - - - class DataObject(KaitaiStruct): - """Data objects are designed to carry log payload, typically in - form of a "key=value" string in `payload` attribute. - - .. seealso:: - Source - https://www.freedesktop.org/wiki/Software/systemd/journal-files/#dataobjects - """ - SEQ_FIELDS = ["hash", "ofs_next_hash", "ofs_head_field", "ofs_entry", "ofs_entry_array", "num_entries", "payload"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['hash']['start'] = self._io.pos() - self.hash = self._io.read_u8le() - self._debug['hash']['end'] = self._io.pos() - self._debug['ofs_next_hash']['start'] = self._io.pos() - self.ofs_next_hash = self._io.read_u8le() - self._debug['ofs_next_hash']['end'] = self._io.pos() - self._debug['ofs_head_field']['start'] = self._io.pos() - self.ofs_head_field = self._io.read_u8le() - self._debug['ofs_head_field']['end'] = self._io.pos() - self._debug['ofs_entry']['start'] = self._io.pos() - self.ofs_entry = self._io.read_u8le() - self._debug['ofs_entry']['end'] = self._io.pos() - self._debug['ofs_entry_array']['start'] = self._io.pos() - self.ofs_entry_array = self._io.read_u8le() - self._debug['ofs_entry_array']['end'] = self._io.pos() - self._debug['num_entries']['start'] = self._io.pos() - self.num_entries = self._io.read_u8le() - self._debug['num_entries']['end'] = self._io.pos() - self._debug['payload']['start'] = self._io.pos() - self.payload = self._io.read_bytes_full() - self._debug['payload']['end'] = self._io.pos() - - @property - def next_hash(self): - if hasattr(self, '_m_next_hash'): - return self._m_next_hash if hasattr(self, '_m_next_hash') else None - - if self.ofs_next_hash != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_next_hash) - self._debug['_m_next_hash']['start'] = io.pos() - self._m_next_hash = self._root.JournalObject(io, self, self._root) - self._m_next_hash._read() - self._debug['_m_next_hash']['end'] = io.pos() - io.seek(_pos) - - return self._m_next_hash if hasattr(self, '_m_next_hash') else None - - @property - def head_field(self): - if hasattr(self, '_m_head_field'): - return self._m_head_field if hasattr(self, '_m_head_field') else None - - if self.ofs_head_field != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_head_field) - self._debug['_m_head_field']['start'] = io.pos() - self._m_head_field = self._root.JournalObject(io, self, self._root) - self._m_head_field._read() - self._debug['_m_head_field']['end'] = io.pos() - io.seek(_pos) - - return self._m_head_field if hasattr(self, '_m_head_field') else None - - @property - def entry(self): - if hasattr(self, '_m_entry'): - return self._m_entry if hasattr(self, '_m_entry') else None - - if self.ofs_entry != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_entry) - self._debug['_m_entry']['start'] = io.pos() - self._m_entry = self._root.JournalObject(io, self, self._root) - self._m_entry._read() - self._debug['_m_entry']['end'] = io.pos() - io.seek(_pos) - - return self._m_entry if hasattr(self, '_m_entry') else None - - @property - def entry_array(self): - if hasattr(self, '_m_entry_array'): - return self._m_entry_array if hasattr(self, '_m_entry_array') else None - - if self.ofs_entry_array != 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_entry_array) - self._debug['_m_entry_array']['start'] = io.pos() - self._m_entry_array = self._root.JournalObject(io, self, self._root) - self._m_entry_array._read() - self._debug['_m_entry_array']['end'] = io.pos() - io.seek(_pos) - - return self._m_entry_array if hasattr(self, '_m_entry_array') else None - - - @property - def len_header(self): - """Header length is used to set substream size, as it thus required - prior to declaration of header. - """ - if hasattr(self, '_m_len_header'): - return self._m_len_header if hasattr(self, '_m_len_header') else None - - _pos = self._io.pos() - self._io.seek(88) - self._debug['_m_len_header']['start'] = self._io.pos() - self._m_len_header = self._io.read_u8le() - self._debug['_m_len_header']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_len_header if hasattr(self, '_m_len_header') else None - - @property - def data_hash_table(self): - if hasattr(self, '_m_data_hash_table'): - return self._m_data_hash_table if hasattr(self, '_m_data_hash_table') else None - - _pos = self._io.pos() - self._io.seek(self.header.ofs_data_hash_table) - self._debug['_m_data_hash_table']['start'] = self._io.pos() - self._m_data_hash_table = self._io.read_bytes(self.header.len_data_hash_table) - self._debug['_m_data_hash_table']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data_hash_table if hasattr(self, '_m_data_hash_table') else None - - @property - def field_hash_table(self): - if hasattr(self, '_m_field_hash_table'): - return self._m_field_hash_table if hasattr(self, '_m_field_hash_table') else None - - _pos = self._io.pos() - self._io.seek(self.header.ofs_field_hash_table) - self._debug['_m_field_hash_table']['start'] = self._io.pos() - self._m_field_hash_table = self._io.read_bytes(self.header.len_field_hash_table) - self._debug['_m_field_hash_table']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_field_hash_table if hasattr(self, '_m_field_hash_table') else None - - diff --git a/python/examples/kaitai/tcp_segment.py b/python/examples/kaitai/tcp_segment.py deleted file mode 100644 index e329d84c..00000000 --- a/python/examples/kaitai/tcp_segment.py +++ /dev/null @@ -1,56 +0,0 @@ -# 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 -import collections - - -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 TcpSegment(KaitaiStruct): - """TCP is one of the core Internet protocols on transport layer (AKA - OSI layer 4), providing stateful connections with error checking, - guarantees of delivery, order of segments and avoidance of duplicate - delivery. - """ - SEQ_FIELDS = ["src_port", "dst_port", "seq_num", "ack_num", "b12", "b13", "window_size", "checksum", "urgent_pointer", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['src_port']['start'] = self._io.pos() - self.src_port = self._io.read_u2be() - self._debug['src_port']['end'] = self._io.pos() - self._debug['dst_port']['start'] = self._io.pos() - self.dst_port = self._io.read_u2be() - self._debug['dst_port']['end'] = self._io.pos() - self._debug['seq_num']['start'] = self._io.pos() - self.seq_num = self._io.read_u4be() - self._debug['seq_num']['end'] = self._io.pos() - self._debug['ack_num']['start'] = self._io.pos() - self.ack_num = self._io.read_u4be() - self._debug['ack_num']['end'] = self._io.pos() - self._debug['b12']['start'] = self._io.pos() - self.b12 = self._io.read_u1() - self._debug['b12']['end'] = self._io.pos() - self._debug['b13']['start'] = self._io.pos() - self.b13 = self._io.read_u1() - self._debug['b13']['end'] = self._io.pos() - self._debug['window_size']['start'] = self._io.pos() - self.window_size = self._io.read_u2be() - self._debug['window_size']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2be() - self._debug['checksum']['end'] = self._io.pos() - self._debug['urgent_pointer']['start'] = self._io.pos() - self.urgent_pointer = self._io.read_u2be() - self._debug['urgent_pointer']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes_full() - self._debug['body']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/tga.py b/python/examples/kaitai/tga.py deleted file mode 100644 index 5ba11862..00000000 --- a/python/examples/kaitai/tga.py +++ /dev/null @@ -1,212 +0,0 @@ -# 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 -import collections - - -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 Tga(KaitaiStruct): - """TGA (AKA Truevision TGA, AKA TARGA), is a raster image file format created by Truevision. It supports up to 32 bits per pixel (three 8-bit RGB channels + 8-bit alpha channel), color mapping and optional lossless RLE compression. - - .. seealso:: - Source - http://www.dca.fee.unicamp.br/~martino/disciplinas/ea978/tgaffs.pdf - """ - - class ColorMapEnum(Enum): - no_color_map = 0 - has_color_map = 1 - - class ImageTypeEnum(Enum): - no_image_data = 0 - uncomp_color_mapped = 1 - uncomp_true_color = 2 - uncomp_bw = 3 - rle_color_mapped = 9 - rle_true_color = 10 - rle_bw = 11 - SEQ_FIELDS = ["image_id_len", "color_map_type", "image_type", "color_map_ofs", "num_color_map", "color_map_depth", "x_offset", "y_offset", "width", "height", "image_depth", "img_descriptor", "image_id", "color_map"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['image_id_len']['start'] = self._io.pos() - self.image_id_len = self._io.read_u1() - self._debug['image_id_len']['end'] = self._io.pos() - self._debug['color_map_type']['start'] = self._io.pos() - self.color_map_type = KaitaiStream.resolve_enum(self._root.ColorMapEnum, self._io.read_u1()) - self._debug['color_map_type']['end'] = self._io.pos() - self._debug['image_type']['start'] = self._io.pos() - self.image_type = KaitaiStream.resolve_enum(self._root.ImageTypeEnum, self._io.read_u1()) - self._debug['image_type']['end'] = self._io.pos() - self._debug['color_map_ofs']['start'] = self._io.pos() - self.color_map_ofs = self._io.read_u2le() - self._debug['color_map_ofs']['end'] = self._io.pos() - self._debug['num_color_map']['start'] = self._io.pos() - self.num_color_map = self._io.read_u2le() - self._debug['num_color_map']['end'] = self._io.pos() - self._debug['color_map_depth']['start'] = self._io.pos() - self.color_map_depth = self._io.read_u1() - self._debug['color_map_depth']['end'] = self._io.pos() - self._debug['x_offset']['start'] = self._io.pos() - self.x_offset = self._io.read_u2le() - self._debug['x_offset']['end'] = self._io.pos() - self._debug['y_offset']['start'] = self._io.pos() - self.y_offset = self._io.read_u2le() - self._debug['y_offset']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['image_depth']['start'] = self._io.pos() - self.image_depth = self._io.read_u1() - self._debug['image_depth']['end'] = self._io.pos() - self._debug['img_descriptor']['start'] = self._io.pos() - self.img_descriptor = self._io.read_u1() - self._debug['img_descriptor']['end'] = self._io.pos() - self._debug['image_id']['start'] = self._io.pos() - self.image_id = self._io.read_bytes(self.image_id_len) - self._debug['image_id']['end'] = self._io.pos() - if self.color_map_type == self._root.ColorMapEnum.has_color_map: - self._debug['color_map']['start'] = self._io.pos() - self.color_map = [None] * (self.num_color_map) - for i in range(self.num_color_map): - if not 'arr' in self._debug['color_map']: - self._debug['color_map']['arr'] = [] - self._debug['color_map']['arr'].append({'start': self._io.pos()}) - self.color_map[i] = self._io.read_bytes((self.color_map_depth + 7) // 8) - self._debug['color_map']['arr'][i]['end'] = self._io.pos() - - self._debug['color_map']['end'] = self._io.pos() - - - class TgaFooter(KaitaiStruct): - SEQ_FIELDS = ["ext_area_ofs", "dev_dir_ofs", "version_magic"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ext_area_ofs']['start'] = self._io.pos() - self.ext_area_ofs = self._io.read_u4le() - self._debug['ext_area_ofs']['end'] = self._io.pos() - self._debug['dev_dir_ofs']['start'] = self._io.pos() - self.dev_dir_ofs = self._io.read_u4le() - self._debug['dev_dir_ofs']['end'] = self._io.pos() - self._debug['version_magic']['start'] = self._io.pos() - self.version_magic = self._io.read_bytes(18) - self._debug['version_magic']['end'] = self._io.pos() - - @property - def is_valid(self): - if hasattr(self, '_m_is_valid'): - return self._m_is_valid if hasattr(self, '_m_is_valid') else None - - self._m_is_valid = self.version_magic == b"\x54\x52\x55\x45\x56\x49\x53\x49\x4F\x4E\x2D\x58\x46\x49\x4C\x45\x2E\x00" - return self._m_is_valid if hasattr(self, '_m_is_valid') else None - - @property - def ext_area(self): - if hasattr(self, '_m_ext_area'): - return self._m_ext_area if hasattr(self, '_m_ext_area') else None - - if self.is_valid: - _pos = self._io.pos() - self._io.seek(self.ext_area_ofs) - self._debug['_m_ext_area']['start'] = self._io.pos() - self._m_ext_area = self._root.TgaExtArea(self._io, self, self._root) - self._m_ext_area._read() - self._debug['_m_ext_area']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_ext_area if hasattr(self, '_m_ext_area') else None - - - class TgaExtArea(KaitaiStruct): - SEQ_FIELDS = ["ext_area_size", "author_name", "comments", "timestamp", "job_id", "job_time", "software_id", "software_version", "key_color", "pixel_aspect_ratio", "gamma_value", "color_corr_ofs", "postage_stamp_ofs", "scan_line_ofs", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ext_area_size']['start'] = self._io.pos() - self.ext_area_size = self._io.read_u2le() - self._debug['ext_area_size']['end'] = self._io.pos() - self._debug['author_name']['start'] = self._io.pos() - self.author_name = (self._io.read_bytes(41)).decode(u"ASCII") - self._debug['author_name']['end'] = self._io.pos() - self._debug['comments']['start'] = self._io.pos() - self.comments = [None] * (4) - for i in range(4): - if not 'arr' in self._debug['comments']: - self._debug['comments']['arr'] = [] - self._debug['comments']['arr'].append({'start': self._io.pos()}) - self.comments[i] = (self._io.read_bytes(81)).decode(u"ASCII") - self._debug['comments']['arr'][i]['end'] = self._io.pos() - - self._debug['comments']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_bytes(12) - self._debug['timestamp']['end'] = self._io.pos() - self._debug['job_id']['start'] = self._io.pos() - self.job_id = (self._io.read_bytes(41)).decode(u"ASCII") - self._debug['job_id']['end'] = self._io.pos() - self._debug['job_time']['start'] = self._io.pos() - self.job_time = (self._io.read_bytes(6)).decode(u"ASCII") - self._debug['job_time']['end'] = self._io.pos() - self._debug['software_id']['start'] = self._io.pos() - self.software_id = (self._io.read_bytes(41)).decode(u"ASCII") - self._debug['software_id']['end'] = self._io.pos() - self._debug['software_version']['start'] = self._io.pos() - self.software_version = self._io.read_bytes(3) - self._debug['software_version']['end'] = self._io.pos() - self._debug['key_color']['start'] = self._io.pos() - self.key_color = self._io.read_u4le() - self._debug['key_color']['end'] = self._io.pos() - self._debug['pixel_aspect_ratio']['start'] = self._io.pos() - self.pixel_aspect_ratio = self._io.read_u4le() - self._debug['pixel_aspect_ratio']['end'] = self._io.pos() - self._debug['gamma_value']['start'] = self._io.pos() - self.gamma_value = self._io.read_u4le() - self._debug['gamma_value']['end'] = self._io.pos() - self._debug['color_corr_ofs']['start'] = self._io.pos() - self.color_corr_ofs = self._io.read_u4le() - self._debug['color_corr_ofs']['end'] = self._io.pos() - self._debug['postage_stamp_ofs']['start'] = self._io.pos() - self.postage_stamp_ofs = self._io.read_u4le() - self._debug['postage_stamp_ofs']['end'] = self._io.pos() - self._debug['scan_line_ofs']['start'] = self._io.pos() - self.scan_line_ofs = self._io.read_u4le() - self._debug['scan_line_ofs']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = self._io.read_u1() - self._debug['attributes']['end'] = self._io.pos() - - - @property - def footer(self): - if hasattr(self, '_m_footer'): - return self._m_footer if hasattr(self, '_m_footer') else None - - _pos = self._io.pos() - self._io.seek((self._io.size() - 26)) - self._debug['_m_footer']['start'] = self._io.pos() - self._m_footer = self._root.TgaFooter(self._io, self, self._root) - self._m_footer._read() - self._debug['_m_footer']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_footer if hasattr(self, '_m_footer') else None - - diff --git a/python/examples/kaitai/tls_client_hello.py b/python/examples/kaitai/tls_client_hello.py deleted file mode 100644 index b5c6cba8..00000000 --- a/python/examples/kaitai/tls_client_hello.py +++ /dev/null @@ -1,292 +0,0 @@ -# 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 -import collections - - -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 TlsClientHello(KaitaiStruct): - SEQ_FIELDS = ["version", "random", "session_id", "cipher_suites", "compression_methods", "extensions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Version(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['random']['start'] = self._io.pos() - self.random = self._root.Random(self._io, self, self._root) - self.random._read() - self._debug['random']['end'] = self._io.pos() - self._debug['session_id']['start'] = self._io.pos() - self.session_id = self._root.SessionId(self._io, self, self._root) - self.session_id._read() - self._debug['session_id']['end'] = self._io.pos() - self._debug['cipher_suites']['start'] = self._io.pos() - self.cipher_suites = self._root.CipherSuites(self._io, self, self._root) - self.cipher_suites._read() - self._debug['cipher_suites']['end'] = self._io.pos() - self._debug['compression_methods']['start'] = self._io.pos() - self.compression_methods = self._root.CompressionMethods(self._io, self, self._root) - self.compression_methods._read() - self._debug['compression_methods']['end'] = self._io.pos() - if self._io.is_eof() == False: - self._debug['extensions']['start'] = self._io.pos() - self.extensions = self._root.Extensions(self._io, self, self._root) - self.extensions._read() - self._debug['extensions']['end'] = self._io.pos() - - - class ServerName(KaitaiStruct): - SEQ_FIELDS = ["name_type", "length", "host_name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name_type']['start'] = self._io.pos() - self.name_type = self._io.read_u1() - self._debug['name_type']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - self._debug['host_name']['start'] = self._io.pos() - self.host_name = self._io.read_bytes(self.length) - self._debug['host_name']['end'] = self._io.pos() - - - class Random(KaitaiStruct): - SEQ_FIELDS = ["gmt_unix_time", "random"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['gmt_unix_time']['start'] = self._io.pos() - self.gmt_unix_time = self._io.read_u4be() - self._debug['gmt_unix_time']['end'] = self._io.pos() - self._debug['random']['start'] = self._io.pos() - self.random = self._io.read_bytes(28) - self._debug['random']['end'] = self._io.pos() - - - class SessionId(KaitaiStruct): - SEQ_FIELDS = ["len", "sid"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u1() - self._debug['len']['end'] = self._io.pos() - self._debug['sid']['start'] = self._io.pos() - self.sid = self._io.read_bytes(self.len) - self._debug['sid']['end'] = self._io.pos() - - - class Sni(KaitaiStruct): - SEQ_FIELDS = ["list_length", "server_names"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['list_length']['start'] = self._io.pos() - self.list_length = self._io.read_u2be() - self._debug['list_length']['end'] = self._io.pos() - self._debug['server_names']['start'] = self._io.pos() - self.server_names = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['server_names']: - self._debug['server_names']['arr'] = [] - self._debug['server_names']['arr'].append({'start': self._io.pos()}) - _t_server_names = self._root.ServerName(self._io, self, self._root) - _t_server_names._read() - self.server_names.append(_t_server_names) - self._debug['server_names']['arr'][len(self.server_names) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['server_names']['end'] = self._io.pos() - - - class CipherSuites(KaitaiStruct): - SEQ_FIELDS = ["len", "cipher_suites"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u2be() - self._debug['len']['end'] = self._io.pos() - self._debug['cipher_suites']['start'] = self._io.pos() - self.cipher_suites = [None] * (self.len // 2) - for i in range(self.len // 2): - if not 'arr' in self._debug['cipher_suites']: - self._debug['cipher_suites']['arr'] = [] - self._debug['cipher_suites']['arr'].append({'start': self._io.pos()}) - self.cipher_suites[i] = self._io.read_u2be() - self._debug['cipher_suites']['arr'][i]['end'] = self._io.pos() - - self._debug['cipher_suites']['end'] = self._io.pos() - - - class CompressionMethods(KaitaiStruct): - SEQ_FIELDS = ["len", "compression_methods"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u1() - self._debug['len']['end'] = self._io.pos() - self._debug['compression_methods']['start'] = self._io.pos() - self.compression_methods = self._io.read_bytes(self.len) - self._debug['compression_methods']['end'] = self._io.pos() - - - class Alpn(KaitaiStruct): - SEQ_FIELDS = ["ext_len", "alpn_protocols"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ext_len']['start'] = self._io.pos() - self.ext_len = self._io.read_u2be() - self._debug['ext_len']['end'] = self._io.pos() - self._debug['alpn_protocols']['start'] = self._io.pos() - self.alpn_protocols = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['alpn_protocols']: - self._debug['alpn_protocols']['arr'] = [] - self._debug['alpn_protocols']['arr'].append({'start': self._io.pos()}) - _t_alpn_protocols = self._root.Protocol(self._io, self, self._root) - _t_alpn_protocols._read() - self.alpn_protocols.append(_t_alpn_protocols) - self._debug['alpn_protocols']['arr'][len(self.alpn_protocols) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['alpn_protocols']['end'] = self._io.pos() - - - class Extensions(KaitaiStruct): - SEQ_FIELDS = ["len", "extensions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u2be() - self._debug['len']['end'] = self._io.pos() - self._debug['extensions']['start'] = self._io.pos() - self.extensions = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['extensions']: - self._debug['extensions']['arr'] = [] - self._debug['extensions']['arr'].append({'start': self._io.pos()}) - _t_extensions = self._root.Extension(self._io, self, self._root) - _t_extensions._read() - self.extensions.append(_t_extensions) - self._debug['extensions']['arr'][len(self.extensions) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['extensions']['end'] = self._io.pos() - - - class Version(KaitaiStruct): - SEQ_FIELDS = ["major", "minor"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u1() - self._debug['major']['end'] = self._io.pos() - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u1() - self._debug['minor']['end'] = self._io.pos() - - - class Protocol(KaitaiStruct): - SEQ_FIELDS = ["strlen", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['strlen']['start'] = self._io.pos() - self.strlen = self._io.read_u1() - self._debug['strlen']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = self._io.read_bytes(self.strlen) - self._debug['name']['end'] = self._io.pos() - - - class Extension(KaitaiStruct): - SEQ_FIELDS = ["type", "len", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u2be() - self._debug['type']['end'] = self._io.pos() - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u2be() - self._debug['len']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.type - if _on == 0: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.Sni(io, self, self._root) - self.body._read() - elif _on == 16: - self._raw_body = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.Alpn(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.len) - self._debug['body']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/tr_dos_image.py b/python/examples/kaitai/tr_dos_image.py deleted file mode 100644 index 70298f7a..00000000 --- a/python/examples/kaitai/tr_dos_image.py +++ /dev/null @@ -1,317 +0,0 @@ -# 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 -import collections - - -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 TrDosImage(KaitaiStruct): - """.trd file is a raw dump of TR-DOS (ZX-Spectrum) floppy. .trd files are - headerless and contain consequent "logical tracks", each logical track - consists of 16 256-byte sectors. - - Logical tracks are defined the same way as used by TR-DOS: for single-side - floppies it's just a physical track number, for two-side floppies sides are - interleaved, i.e. logical_track_num = (physical_track_num << 1) | side - - So, this format definition is more for TR-DOS filesystem than for .trd files, - which are formatless. - - Strings (file names, disk label, disk password) are padded with spaces and use - ZX Spectrum character set, including UDGs, block drawing chars and Basic - tokens. ASCII range is mostly standard ASCII, with few characters (^, `, DEL) - replaced with (up arrow, pound, copyright symbol). - - .trd file can be smaller than actual floppy disk, if last logical tracks are - empty (contain no file data) they can be omitted. - """ - - class DiskType(Enum): - type_80_tracks_double_side = 22 - type_40_tracks_double_side = 23 - type_80_tracks_single_side = 24 - type_40_tracks_single_side = 25 - SEQ_FIELDS = ["files"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['files']['start'] = self._io.pos() - self.files = [] - i = 0 - while True: - if not 'arr' in self._debug['files']: - self._debug['files']['arr'] = [] - self._debug['files']['arr'].append({'start': self._io.pos()}) - _t_files = self._root.File(self._io, self, self._root) - _t_files._read() - _ = _t_files - self.files.append(_) - self._debug['files']['arr'][len(self.files) - 1]['end'] = self._io.pos() - if _.is_terminator: - break - i += 1 - self._debug['files']['end'] = self._io.pos() - - class VolumeInfo(KaitaiStruct): - SEQ_FIELDS = ["catalog_end", "unused", "first_free_sector_sector", "first_free_sector_track", "disk_type", "num_files", "num_free_sectors", "tr_dos_id", "unused_2", "password", "unused_3", "num_deleted_files", "label", "unused_4"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['catalog_end']['start'] = self._io.pos() - self.catalog_end = self._io.ensure_fixed_contents(b"\x00") - self._debug['catalog_end']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_bytes(224) - self._debug['unused']['end'] = self._io.pos() - self._debug['first_free_sector_sector']['start'] = self._io.pos() - self.first_free_sector_sector = self._io.read_u1() - self._debug['first_free_sector_sector']['end'] = self._io.pos() - self._debug['first_free_sector_track']['start'] = self._io.pos() - self.first_free_sector_track = self._io.read_u1() - self._debug['first_free_sector_track']['end'] = self._io.pos() - self._debug['disk_type']['start'] = self._io.pos() - self.disk_type = KaitaiStream.resolve_enum(self._root.DiskType, self._io.read_u1()) - self._debug['disk_type']['end'] = self._io.pos() - self._debug['num_files']['start'] = self._io.pos() - self.num_files = self._io.read_u1() - self._debug['num_files']['end'] = self._io.pos() - self._debug['num_free_sectors']['start'] = self._io.pos() - self.num_free_sectors = self._io.read_u2le() - self._debug['num_free_sectors']['end'] = self._io.pos() - self._debug['tr_dos_id']['start'] = self._io.pos() - self.tr_dos_id = self._io.ensure_fixed_contents(b"\x10") - self._debug['tr_dos_id']['end'] = self._io.pos() - self._debug['unused_2']['start'] = self._io.pos() - self.unused_2 = self._io.read_bytes(2) - self._debug['unused_2']['end'] = self._io.pos() - self._debug['password']['start'] = self._io.pos() - self.password = self._io.read_bytes(9) - self._debug['password']['end'] = self._io.pos() - self._debug['unused_3']['start'] = self._io.pos() - self.unused_3 = self._io.read_bytes(1) - self._debug['unused_3']['end'] = self._io.pos() - self._debug['num_deleted_files']['start'] = self._io.pos() - self.num_deleted_files = self._io.read_u1() - self._debug['num_deleted_files']['end'] = self._io.pos() - self._debug['label']['start'] = self._io.pos() - self.label = self._io.read_bytes(8) - self._debug['label']['end'] = self._io.pos() - self._debug['unused_4']['start'] = self._io.pos() - self.unused_4 = self._io.read_bytes(3) - self._debug['unused_4']['end'] = self._io.pos() - - @property - def num_tracks(self): - if hasattr(self, '_m_num_tracks'): - return self._m_num_tracks if hasattr(self, '_m_num_tracks') else None - - self._m_num_tracks = (40 if (self.disk_type.value & 1) != 0 else 80) - return self._m_num_tracks if hasattr(self, '_m_num_tracks') else None - - @property - def num_sides(self): - if hasattr(self, '_m_num_sides'): - return self._m_num_sides if hasattr(self, '_m_num_sides') else None - - self._m_num_sides = (1 if (self.disk_type.value & 8) != 0 else 2) - return self._m_num_sides if hasattr(self, '_m_num_sides') else None - - - class PositionAndLengthCode(KaitaiStruct): - SEQ_FIELDS = ["start_address", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['start_address']['start'] = self._io.pos() - self.start_address = self._io.read_u2le() - self._debug['start_address']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2le() - self._debug['length']['end'] = self._io.pos() - - - class Filename(KaitaiStruct): - SEQ_FIELDS = ["name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self.name = self._io.read_bytes(8) - self._debug['name']['end'] = self._io.pos() - - @property - def first_byte(self): - if hasattr(self, '_m_first_byte'): - return self._m_first_byte if hasattr(self, '_m_first_byte') else None - - _pos = self._io.pos() - self._io.seek(0) - self._debug['_m_first_byte']['start'] = self._io.pos() - self._m_first_byte = self._io.read_u1() - self._debug['_m_first_byte']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_first_byte if hasattr(self, '_m_first_byte') else None - - - class PositionAndLengthPrint(KaitaiStruct): - SEQ_FIELDS = ["extent_no", "reserved", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['extent_no']['start'] = self._io.pos() - self.extent_no = self._io.read_u1() - self._debug['extent_no']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u1() - self._debug['reserved']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2le() - self._debug['length']['end'] = self._io.pos() - - - class PositionAndLengthGeneric(KaitaiStruct): - SEQ_FIELDS = ["reserved", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u2le() - self._debug['reserved']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2le() - self._debug['length']['end'] = self._io.pos() - - - class PositionAndLengthBasic(KaitaiStruct): - SEQ_FIELDS = ["program_and_data_length", "program_length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['program_and_data_length']['start'] = self._io.pos() - self.program_and_data_length = self._io.read_u2le() - self._debug['program_and_data_length']['end'] = self._io.pos() - self._debug['program_length']['start'] = self._io.pos() - self.program_length = self._io.read_u2le() - self._debug['program_length']['end'] = self._io.pos() - - - class File(KaitaiStruct): - SEQ_FIELDS = ["name", "extension", "position_and_length", "length_sectors", "starting_sector", "starting_track"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['name']['start'] = self._io.pos() - self._raw_name = self._io.read_bytes(8) - io = KaitaiStream(BytesIO(self._raw_name)) - self.name = self._root.Filename(io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['extension']['start'] = self._io.pos() - self.extension = self._io.read_u1() - self._debug['extension']['end'] = self._io.pos() - self._debug['position_and_length']['start'] = self._io.pos() - _on = self.extension - if _on == 66: - self.position_and_length = self._root.PositionAndLengthBasic(self._io, self, self._root) - self.position_and_length._read() - elif _on == 67: - self.position_and_length = self._root.PositionAndLengthCode(self._io, self, self._root) - self.position_and_length._read() - elif _on == 35: - self.position_and_length = self._root.PositionAndLengthPrint(self._io, self, self._root) - self.position_and_length._read() - else: - self.position_and_length = self._root.PositionAndLengthGeneric(self._io, self, self._root) - self.position_and_length._read() - self._debug['position_and_length']['end'] = self._io.pos() - self._debug['length_sectors']['start'] = self._io.pos() - self.length_sectors = self._io.read_u1() - self._debug['length_sectors']['end'] = self._io.pos() - self._debug['starting_sector']['start'] = self._io.pos() - self.starting_sector = self._io.read_u1() - self._debug['starting_sector']['end'] = self._io.pos() - self._debug['starting_track']['start'] = self._io.pos() - self.starting_track = self._io.read_u1() - self._debug['starting_track']['end'] = self._io.pos() - - @property - def is_deleted(self): - if hasattr(self, '_m_is_deleted'): - return self._m_is_deleted if hasattr(self, '_m_is_deleted') else None - - self._m_is_deleted = self.name.first_byte == 1 - return self._m_is_deleted if hasattr(self, '_m_is_deleted') else None - - @property - def is_terminator(self): - if hasattr(self, '_m_is_terminator'): - return self._m_is_terminator if hasattr(self, '_m_is_terminator') else None - - self._m_is_terminator = self.name.first_byte == 0 - return self._m_is_terminator if hasattr(self, '_m_is_terminator') else None - - @property - def contents(self): - if hasattr(self, '_m_contents'): - return self._m_contents if hasattr(self, '_m_contents') else None - - _pos = self._io.pos() - self._io.seek((((self.starting_track * 256) * 16) + (self.starting_sector * 256))) - self._debug['_m_contents']['start'] = self._io.pos() - self._m_contents = self._io.read_bytes((self.length_sectors * 256)) - self._debug['_m_contents']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_contents if hasattr(self, '_m_contents') else None - - - @property - def volume_info(self): - if hasattr(self, '_m_volume_info'): - return self._m_volume_info if hasattr(self, '_m_volume_info') else None - - _pos = self._io.pos() - self._io.seek(2048) - self._debug['_m_volume_info']['start'] = self._io.pos() - self._m_volume_info = self._root.VolumeInfo(self._io, self, self._root) - self._m_volume_info._read() - self._debug['_m_volume_info']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_volume_info if hasattr(self, '_m_volume_info') else None - - diff --git a/python/examples/kaitai/tsm.py b/python/examples/kaitai/tsm.py deleted file mode 100644 index 45c99191..00000000 --- a/python/examples/kaitai/tsm.py +++ /dev/null @@ -1,195 +0,0 @@ -# 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 -import collections - - -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 Tsm(KaitaiStruct): - """InfluxDB is a scalable database optimized for storage of time - series, real-time application metrics, operations monitoring events, - etc, written in Go. - - Data is stored in .tsm files, which are kept pretty simple - conceptually. Each .tsm file contains a header and footer, which - stores offset to an index. Index is used to find a data block for a - requested time boundary. - """ - SEQ_FIELDS = ["header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["magic", "version"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x16\xD1\x16\xD1") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - - - class Index(KaitaiStruct): - SEQ_FIELDS = ["offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u8be() - self._debug['offset']['end'] = self._io.pos() - - class IndexHeader(KaitaiStruct): - SEQ_FIELDS = ["key_len", "key", "type", "entry_count", "index_entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['key_len']['start'] = self._io.pos() - self.key_len = self._io.read_u2be() - self._debug['key_len']['end'] = self._io.pos() - self._debug['key']['start'] = self._io.pos() - self.key = (self._io.read_bytes(self.key_len)).decode(u"UTF-8") - self._debug['key']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u1() - self._debug['type']['end'] = self._io.pos() - self._debug['entry_count']['start'] = self._io.pos() - self.entry_count = self._io.read_u2be() - self._debug['entry_count']['end'] = self._io.pos() - self._debug['index_entries']['start'] = self._io.pos() - self.index_entries = [None] * (self.entry_count) - for i in range(self.entry_count): - if not 'arr' in self._debug['index_entries']: - self._debug['index_entries']['arr'] = [] - self._debug['index_entries']['arr'].append({'start': self._io.pos()}) - _t_index_entries = self._root.Index.IndexHeader.IndexEntry(self._io, self, self._root) - _t_index_entries._read() - self.index_entries[i] = _t_index_entries - self._debug['index_entries']['arr'][i]['end'] = self._io.pos() - - self._debug['index_entries']['end'] = self._io.pos() - - class IndexEntry(KaitaiStruct): - SEQ_FIELDS = ["min_time", "max_time", "block_offset", "block_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['min_time']['start'] = self._io.pos() - self.min_time = self._io.read_u8be() - self._debug['min_time']['end'] = self._io.pos() - self._debug['max_time']['start'] = self._io.pos() - self.max_time = self._io.read_u8be() - self._debug['max_time']['end'] = self._io.pos() - self._debug['block_offset']['start'] = self._io.pos() - self.block_offset = self._io.read_u8be() - self._debug['block_offset']['end'] = self._io.pos() - self._debug['block_size']['start'] = self._io.pos() - self.block_size = self._io.read_u4be() - self._debug['block_size']['end'] = self._io.pos() - - class BlockEntry(KaitaiStruct): - SEQ_FIELDS = ["crc32", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['crc32']['start'] = self._io.pos() - self.crc32 = self._io.read_u4be() - self._debug['crc32']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes((self._parent.block_size - 4)) - self._debug['data']['end'] = self._io.pos() - - - @property - def block(self): - if hasattr(self, '_m_block'): - return self._m_block if hasattr(self, '_m_block') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.block_offset) - self._debug['_m_block']['start'] = io.pos() - self._m_block = self._root.Index.IndexHeader.IndexEntry.BlockEntry(io, self, self._root) - self._m_block._read() - self._debug['_m_block']['end'] = io.pos() - io.seek(_pos) - return self._m_block if hasattr(self, '_m_block') else None - - - - @property - def entries(self): - if hasattr(self, '_m_entries'): - return self._m_entries if hasattr(self, '_m_entries') else None - - _pos = self._io.pos() - self._io.seek(self.offset) - self._debug['_m_entries']['start'] = self._io.pos() - self._m_entries = [] - i = 0 - while True: - if not 'arr' in self._debug['_m_entries']: - self._debug['_m_entries']['arr'] = [] - self._debug['_m_entries']['arr'].append({'start': self._io.pos()}) - _t__m_entries = self._root.Index.IndexHeader(self._io, self, self._root) - _t__m_entries._read() - _ = _t__m_entries - self._m_entries.append(_) - self._debug['_m_entries']['arr'][len(self._m_entries) - 1]['end'] = self._io.pos() - if self._io.pos() == (self._io.size() - 8): - break - i += 1 - self._debug['_m_entries']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_entries if hasattr(self, '_m_entries') else None - - - @property - def index(self): - if hasattr(self, '_m_index'): - return self._m_index if hasattr(self, '_m_index') else None - - _pos = self._io.pos() - self._io.seek((self._io.size() - 8)) - self._debug['_m_index']['start'] = self._io.pos() - self._m_index = self._root.Index(self._io, self, self._root) - self._m_index._read() - self._debug['_m_index']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_index if hasattr(self, '_m_index') else None - - diff --git a/python/examples/kaitai/ttf.py b/python/examples/kaitai/ttf.py deleted file mode 100644 index 1d493208..00000000 --- a/python/examples/kaitai/ttf.py +++ /dev/null @@ -1,1817 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 Ttf(KaitaiStruct): - """A TrueType font file contains data, in table format, that comprises - an outline font. - - .. seealso:: - Source - https://www.microsoft.com/typography/tt/ttf_spec/ttch02.doc - """ - SEQ_FIELDS = ["offset_table", "directory_table"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['offset_table']['start'] = self._io.pos() - self.offset_table = self._root.OffsetTable(self._io, self, self._root) - self.offset_table._read() - self._debug['offset_table']['end'] = self._io.pos() - self._debug['directory_table']['start'] = self._io.pos() - self.directory_table = [None] * (self.offset_table.num_tables) - for i in range(self.offset_table.num_tables): - if not 'arr' in self._debug['directory_table']: - self._debug['directory_table']['arr'] = [] - self._debug['directory_table']['arr'].append({'start': self._io.pos()}) - _t_directory_table = self._root.DirTableEntry(self._io, self, self._root) - _t_directory_table._read() - self.directory_table[i] = _t_directory_table - self._debug['directory_table']['arr'][i]['end'] = self._io.pos() - - self._debug['directory_table']['end'] = self._io.pos() - - class Post(KaitaiStruct): - SEQ_FIELDS = ["format", "italic_angle", "underline_position", "underline_thichness", "is_fixed_pitch", "min_mem_type42", "max_mem_type42", "min_mem_type1", "max_mem_type1", "format20"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['format']['start'] = self._io.pos() - self.format = self._root.Fixed(self._io, self, self._root) - self.format._read() - self._debug['format']['end'] = self._io.pos() - self._debug['italic_angle']['start'] = self._io.pos() - self.italic_angle = self._root.Fixed(self._io, self, self._root) - self.italic_angle._read() - self._debug['italic_angle']['end'] = self._io.pos() - self._debug['underline_position']['start'] = self._io.pos() - self.underline_position = self._io.read_s2be() - self._debug['underline_position']['end'] = self._io.pos() - self._debug['underline_thichness']['start'] = self._io.pos() - self.underline_thichness = self._io.read_s2be() - self._debug['underline_thichness']['end'] = self._io.pos() - self._debug['is_fixed_pitch']['start'] = self._io.pos() - self.is_fixed_pitch = self._io.read_u4be() - self._debug['is_fixed_pitch']['end'] = self._io.pos() - self._debug['min_mem_type42']['start'] = self._io.pos() - self.min_mem_type42 = self._io.read_u4be() - self._debug['min_mem_type42']['end'] = self._io.pos() - self._debug['max_mem_type42']['start'] = self._io.pos() - self.max_mem_type42 = self._io.read_u4be() - self._debug['max_mem_type42']['end'] = self._io.pos() - self._debug['min_mem_type1']['start'] = self._io.pos() - self.min_mem_type1 = self._io.read_u4be() - self._debug['min_mem_type1']['end'] = self._io.pos() - self._debug['max_mem_type1']['start'] = self._io.pos() - self.max_mem_type1 = self._io.read_u4be() - self._debug['max_mem_type1']['end'] = self._io.pos() - if ((self.format.major == 2) and (self.format.minor == 0)) : - self._debug['format20']['start'] = self._io.pos() - self.format20 = self._root.Post.Format20(self._io, self, self._root) - self.format20._read() - self._debug['format20']['end'] = self._io.pos() - - - class Format20(KaitaiStruct): - SEQ_FIELDS = ["number_of_glyphs", "glyph_name_index", "glyph_names"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number_of_glyphs']['start'] = self._io.pos() - self.number_of_glyphs = self._io.read_u2be() - self._debug['number_of_glyphs']['end'] = self._io.pos() - self._debug['glyph_name_index']['start'] = self._io.pos() - self.glyph_name_index = [None] * (self.number_of_glyphs) - for i in range(self.number_of_glyphs): - if not 'arr' in self._debug['glyph_name_index']: - self._debug['glyph_name_index']['arr'] = [] - self._debug['glyph_name_index']['arr'].append({'start': self._io.pos()}) - self.glyph_name_index[i] = self._io.read_u2be() - self._debug['glyph_name_index']['arr'][i]['end'] = self._io.pos() - - self._debug['glyph_name_index']['end'] = self._io.pos() - self._debug['glyph_names']['start'] = self._io.pos() - self.glyph_names = [] - i = 0 - while True: - if not 'arr' in self._debug['glyph_names']: - self._debug['glyph_names']['arr'] = [] - self._debug['glyph_names']['arr'].append({'start': self._io.pos()}) - _t_glyph_names = self._root.Post.Format20.PascalString(self._io, self, self._root) - _t_glyph_names._read() - _ = _t_glyph_names - self.glyph_names.append(_) - self._debug['glyph_names']['arr'][len(self.glyph_names) - 1]['end'] = self._io.pos() - if _.length == 0: - break - i += 1 - self._debug['glyph_names']['end'] = self._io.pos() - - class PascalString(KaitaiStruct): - SEQ_FIELDS = ["length", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u1() - self._debug['length']['end'] = self._io.pos() - if self.length != 0: - self._debug['value']['start'] = self._io.pos() - self.value = (self._io.read_bytes(self.length)).decode(u"ascii") - self._debug['value']['end'] = self._io.pos() - - - - - - class Name(KaitaiStruct): - """Name table is meant to include human-readable string metadata - that describes font: name of the font, its styles, copyright & - trademark notices, vendor and designer info, etc. - - The table includes a list of "name records", each of which - corresponds to a single metadata entry. - - .. seealso:: - Source - https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html - """ - - class Platforms(Enum): - unicode = 0 - macintosh = 1 - reserved_2 = 2 - microsoft = 3 - - class Names(Enum): - copyright = 0 - font_family = 1 - font_subfamily = 2 - unique_subfamily_id = 3 - full_font_name = 4 - name_table_version = 5 - postscript_font_name = 6 - trademark = 7 - manufacturer = 8 - designer = 9 - description = 10 - url_vendor = 11 - url_designer = 12 - license = 13 - url_license = 14 - reserved_15 = 15 - preferred_family = 16 - preferred_subfamily = 17 - compatible_full_name = 18 - sample_text = 19 - SEQ_FIELDS = ["format_selector", "num_name_records", "ofs_strings", "name_records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['format_selector']['start'] = self._io.pos() - self.format_selector = self._io.read_u2be() - self._debug['format_selector']['end'] = self._io.pos() - self._debug['num_name_records']['start'] = self._io.pos() - self.num_name_records = self._io.read_u2be() - self._debug['num_name_records']['end'] = self._io.pos() - self._debug['ofs_strings']['start'] = self._io.pos() - self.ofs_strings = self._io.read_u2be() - self._debug['ofs_strings']['end'] = self._io.pos() - self._debug['name_records']['start'] = self._io.pos() - self.name_records = [None] * (self.num_name_records) - for i in range(self.num_name_records): - if not 'arr' in self._debug['name_records']: - self._debug['name_records']['arr'] = [] - self._debug['name_records']['arr'].append({'start': self._io.pos()}) - _t_name_records = self._root.Name.NameRecord(self._io, self, self._root) - _t_name_records._read() - self.name_records[i] = _t_name_records - self._debug['name_records']['arr'][i]['end'] = self._io.pos() - - self._debug['name_records']['end'] = self._io.pos() - - class NameRecord(KaitaiStruct): - SEQ_FIELDS = ["platform_id", "encoding_id", "language_id", "name_id", "len_str", "ofs_str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['platform_id']['start'] = self._io.pos() - self.platform_id = KaitaiStream.resolve_enum(self._root.Name.Platforms, self._io.read_u2be()) - self._debug['platform_id']['end'] = self._io.pos() - self._debug['encoding_id']['start'] = self._io.pos() - self.encoding_id = self._io.read_u2be() - self._debug['encoding_id']['end'] = self._io.pos() - self._debug['language_id']['start'] = self._io.pos() - self.language_id = self._io.read_u2be() - self._debug['language_id']['end'] = self._io.pos() - self._debug['name_id']['start'] = self._io.pos() - self.name_id = KaitaiStream.resolve_enum(self._root.Name.Names, self._io.read_u2be()) - self._debug['name_id']['end'] = self._io.pos() - self._debug['len_str']['start'] = self._io.pos() - self.len_str = self._io.read_u2be() - self._debug['len_str']['end'] = self._io.pos() - self._debug['ofs_str']['start'] = self._io.pos() - self.ofs_str = self._io.read_u2be() - self._debug['ofs_str']['end'] = self._io.pos() - - @property - def ascii_value(self): - if hasattr(self, '_m_ascii_value'): - return self._m_ascii_value if hasattr(self, '_m_ascii_value') else None - - io = self._parent._io - _pos = io.pos() - io.seek((self._parent.ofs_strings + self.ofs_str)) - self._debug['_m_ascii_value']['start'] = io.pos() - self._m_ascii_value = (io.read_bytes(self.len_str)).decode(u"ascii") - self._debug['_m_ascii_value']['end'] = io.pos() - io.seek(_pos) - return self._m_ascii_value if hasattr(self, '_m_ascii_value') else None - - @property - def unicode_value(self): - if hasattr(self, '_m_unicode_value'): - return self._m_unicode_value if hasattr(self, '_m_unicode_value') else None - - io = self._parent._io - _pos = io.pos() - io.seek((self._parent.ofs_strings + self.ofs_str)) - self._debug['_m_unicode_value']['start'] = io.pos() - self._m_unicode_value = (io.read_bytes(self.len_str)).decode(u"utf-16be") - self._debug['_m_unicode_value']['end'] = io.pos() - io.seek(_pos) - return self._m_unicode_value if hasattr(self, '_m_unicode_value') else None - - - - class Head(KaitaiStruct): - - class Flags(Enum): - baseline_at_y0 = 1 - left_sidebearing_at_x0 = 2 - flag_depend_on_point_size = 4 - flag_force_ppem = 8 - flag_may_advance_width = 16 - - class FontDirectionHint(Enum): - fully_mixed_directional_glyphs = 0 - only_strongly_left_to_right = 1 - strongly_left_to_right_and_neutrals = 2 - SEQ_FIELDS = ["version", "font_revision", "checksum_adjustment", "magic_number", "flags", "units_per_em", "created", "modified", "x_min", "y_min", "x_max", "y_max", "mac_style", "lowest_rec_ppem", "font_direction_hint", "index_to_loc_format", "glyph_data_format"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Fixed(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['font_revision']['start'] = self._io.pos() - self.font_revision = self._root.Fixed(self._io, self, self._root) - self.font_revision._read() - self._debug['font_revision']['end'] = self._io.pos() - self._debug['checksum_adjustment']['start'] = self._io.pos() - self.checksum_adjustment = self._io.read_u4be() - self._debug['checksum_adjustment']['end'] = self._io.pos() - self._debug['magic_number']['start'] = self._io.pos() - self.magic_number = self._io.ensure_fixed_contents(b"\x5F\x0F\x3C\xF5") - self._debug['magic_number']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = KaitaiStream.resolve_enum(self._root.Head.Flags, self._io.read_u2be()) - self._debug['flags']['end'] = self._io.pos() - self._debug['units_per_em']['start'] = self._io.pos() - self.units_per_em = self._io.read_u2be() - self._debug['units_per_em']['end'] = self._io.pos() - self._debug['created']['start'] = self._io.pos() - self.created = self._io.read_u8be() - self._debug['created']['end'] = self._io.pos() - self._debug['modified']['start'] = self._io.pos() - self.modified = self._io.read_u8be() - self._debug['modified']['end'] = self._io.pos() - self._debug['x_min']['start'] = self._io.pos() - self.x_min = self._io.read_s2be() - self._debug['x_min']['end'] = self._io.pos() - self._debug['y_min']['start'] = self._io.pos() - self.y_min = self._io.read_s2be() - self._debug['y_min']['end'] = self._io.pos() - self._debug['x_max']['start'] = self._io.pos() - self.x_max = self._io.read_s2be() - self._debug['x_max']['end'] = self._io.pos() - self._debug['y_max']['start'] = self._io.pos() - self.y_max = self._io.read_s2be() - self._debug['y_max']['end'] = self._io.pos() - self._debug['mac_style']['start'] = self._io.pos() - self.mac_style = self._io.read_u2be() - self._debug['mac_style']['end'] = self._io.pos() - self._debug['lowest_rec_ppem']['start'] = self._io.pos() - self.lowest_rec_ppem = self._io.read_u2be() - self._debug['lowest_rec_ppem']['end'] = self._io.pos() - self._debug['font_direction_hint']['start'] = self._io.pos() - self.font_direction_hint = KaitaiStream.resolve_enum(self._root.Head.FontDirectionHint, self._io.read_s2be()) - self._debug['font_direction_hint']['end'] = self._io.pos() - self._debug['index_to_loc_format']['start'] = self._io.pos() - self.index_to_loc_format = self._io.read_s2be() - self._debug['index_to_loc_format']['end'] = self._io.pos() - self._debug['glyph_data_format']['start'] = self._io.pos() - self.glyph_data_format = self._io.read_s2be() - self._debug['glyph_data_format']['end'] = self._io.pos() - - - class Prep(KaitaiStruct): - SEQ_FIELDS = ["instructions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['instructions']['start'] = self._io.pos() - self.instructions = self._io.read_bytes_full() - self._debug['instructions']['end'] = self._io.pos() - - - class Hhea(KaitaiStruct): - SEQ_FIELDS = ["version", "ascender", "descender", "line_gap", "advance_width_max", "min_left_side_bearing", "min_right_side_bearing", "x_max_extend", "caret_slope_rise", "caret_slope_run", "reserved", "metric_data_format", "number_of_hmetrics"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Fixed(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - self._debug['ascender']['start'] = self._io.pos() - self.ascender = self._io.read_s2be() - self._debug['ascender']['end'] = self._io.pos() - self._debug['descender']['start'] = self._io.pos() - self.descender = self._io.read_s2be() - self._debug['descender']['end'] = self._io.pos() - self._debug['line_gap']['start'] = self._io.pos() - self.line_gap = self._io.read_s2be() - self._debug['line_gap']['end'] = self._io.pos() - self._debug['advance_width_max']['start'] = self._io.pos() - self.advance_width_max = self._io.read_u2be() - self._debug['advance_width_max']['end'] = self._io.pos() - self._debug['min_left_side_bearing']['start'] = self._io.pos() - self.min_left_side_bearing = self._io.read_s2be() - self._debug['min_left_side_bearing']['end'] = self._io.pos() - self._debug['min_right_side_bearing']['start'] = self._io.pos() - self.min_right_side_bearing = self._io.read_s2be() - self._debug['min_right_side_bearing']['end'] = self._io.pos() - self._debug['x_max_extend']['start'] = self._io.pos() - self.x_max_extend = self._io.read_s2be() - self._debug['x_max_extend']['end'] = self._io.pos() - self._debug['caret_slope_rise']['start'] = self._io.pos() - self.caret_slope_rise = self._io.read_s2be() - self._debug['caret_slope_rise']['end'] = self._io.pos() - self._debug['caret_slope_run']['start'] = self._io.pos() - self.caret_slope_run = self._io.read_s2be() - self._debug['caret_slope_run']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['metric_data_format']['start'] = self._io.pos() - self.metric_data_format = self._io.read_s2be() - self._debug['metric_data_format']['end'] = self._io.pos() - self._debug['number_of_hmetrics']['start'] = self._io.pos() - self.number_of_hmetrics = self._io.read_u2be() - self._debug['number_of_hmetrics']['end'] = self._io.pos() - - - class Fpgm(KaitaiStruct): - SEQ_FIELDS = ["instructions"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['instructions']['start'] = self._io.pos() - self.instructions = self._io.read_bytes_full() - self._debug['instructions']['end'] = self._io.pos() - - - class Kern(KaitaiStruct): - SEQ_FIELDS = ["version", "subtable_count", "subtables"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2be() - self._debug['version']['end'] = self._io.pos() - self._debug['subtable_count']['start'] = self._io.pos() - self.subtable_count = self._io.read_u2be() - self._debug['subtable_count']['end'] = self._io.pos() - self._debug['subtables']['start'] = self._io.pos() - self.subtables = [None] * (self.subtable_count) - for i in range(self.subtable_count): - if not 'arr' in self._debug['subtables']: - self._debug['subtables']['arr'] = [] - self._debug['subtables']['arr'].append({'start': self._io.pos()}) - _t_subtables = self._root.Kern.Subtable(self._io, self, self._root) - _t_subtables._read() - self.subtables[i] = _t_subtables - self._debug['subtables']['arr'][i]['end'] = self._io.pos() - - self._debug['subtables']['end'] = self._io.pos() - - class Subtable(KaitaiStruct): - SEQ_FIELDS = ["version", "length", "format", "reserved", "is_override", "is_cross_stream", "is_minimum", "is_horizontal", "format0"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2be() - self._debug['version']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - self._debug['format']['start'] = self._io.pos() - self.format = self._io.read_u1() - self._debug['format']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(4) - self._debug['reserved']['end'] = self._io.pos() - self._debug['is_override']['start'] = self._io.pos() - self.is_override = self._io.read_bits_int(1) != 0 - self._debug['is_override']['end'] = self._io.pos() - self._debug['is_cross_stream']['start'] = self._io.pos() - self.is_cross_stream = self._io.read_bits_int(1) != 0 - self._debug['is_cross_stream']['end'] = self._io.pos() - self._debug['is_minimum']['start'] = self._io.pos() - self.is_minimum = self._io.read_bits_int(1) != 0 - self._debug['is_minimum']['end'] = self._io.pos() - self._debug['is_horizontal']['start'] = self._io.pos() - self.is_horizontal = self._io.read_bits_int(1) != 0 - self._debug['is_horizontal']['end'] = self._io.pos() - self._io.align_to_byte() - if self.format == 0: - self._debug['format0']['start'] = self._io.pos() - self.format0 = self._root.Kern.Subtable.Format0(self._io, self, self._root) - self.format0._read() - self._debug['format0']['end'] = self._io.pos() - - - class Format0(KaitaiStruct): - SEQ_FIELDS = ["pair_count", "search_range", "entry_selector", "range_shift", "kerning_pairs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['pair_count']['start'] = self._io.pos() - self.pair_count = self._io.read_u2be() - self._debug['pair_count']['end'] = self._io.pos() - self._debug['search_range']['start'] = self._io.pos() - self.search_range = self._io.read_u2be() - self._debug['search_range']['end'] = self._io.pos() - self._debug['entry_selector']['start'] = self._io.pos() - self.entry_selector = self._io.read_u2be() - self._debug['entry_selector']['end'] = self._io.pos() - self._debug['range_shift']['start'] = self._io.pos() - self.range_shift = self._io.read_u2be() - self._debug['range_shift']['end'] = self._io.pos() - self._debug['kerning_pairs']['start'] = self._io.pos() - self.kerning_pairs = [None] * (self.pair_count) - for i in range(self.pair_count): - if not 'arr' in self._debug['kerning_pairs']: - self._debug['kerning_pairs']['arr'] = [] - self._debug['kerning_pairs']['arr'].append({'start': self._io.pos()}) - _t_kerning_pairs = self._root.Kern.Subtable.Format0.KerningPair(self._io, self, self._root) - _t_kerning_pairs._read() - self.kerning_pairs[i] = _t_kerning_pairs - self._debug['kerning_pairs']['arr'][i]['end'] = self._io.pos() - - self._debug['kerning_pairs']['end'] = self._io.pos() - - class KerningPair(KaitaiStruct): - SEQ_FIELDS = ["left", "right", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['left']['start'] = self._io.pos() - self.left = self._io.read_u2be() - self._debug['left']['end'] = self._io.pos() - self._debug['right']['start'] = self._io.pos() - self.right = self._io.read_u2be() - self._debug['right']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_s2be() - self._debug['value']['end'] = self._io.pos() - - - - - - class DirTableEntry(KaitaiStruct): - SEQ_FIELDS = ["tag", "checksum", "offset", "length"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = (self._io.read_bytes(4)).decode(u"ascii") - self._debug['tag']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u4be() - self._debug['checksum']['end'] = self._io.pos() - self._debug['offset']['start'] = self._io.pos() - self.offset = self._io.read_u4be() - self._debug['offset']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u4be() - self._debug['length']['end'] = self._io.pos() - - @property - def value(self): - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.offset) - self._debug['_m_value']['start'] = io.pos() - _on = self.tag - if _on == u"head": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Head(io, self, self._root) - self._m_value._read() - elif _on == u"cvt ": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Cvt(io, self, self._root) - self._m_value._read() - elif _on == u"prep": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Prep(io, self, self._root) - self._m_value._read() - elif _on == u"kern": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Kern(io, self, self._root) - self._m_value._read() - elif _on == u"hhea": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Hhea(io, self, self._root) - self._m_value._read() - elif _on == u"post": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Post(io, self, self._root) - self._m_value._read() - elif _on == u"OS/2": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Os2(io, self, self._root) - self._m_value._read() - elif _on == u"name": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Name(io, self, self._root) - self._m_value._read() - elif _on == u"maxp": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Maxp(io, self, self._root) - self._m_value._read() - elif _on == u"glyf": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Glyf(io, self, self._root) - self._m_value._read() - elif _on == u"fpgm": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Fpgm(io, self, self._root) - self._m_value._read() - elif _on == u"cmap": - self._raw__m_value = io.read_bytes(self.length) - io = KaitaiStream(BytesIO(self._raw__m_value)) - self._m_value = self._root.Cmap(io, self, self._root) - self._m_value._read() - else: - self._m_value = io.read_bytes(self.length) - self._debug['_m_value']['end'] = io.pos() - io.seek(_pos) - return self._m_value if hasattr(self, '_m_value') else None - - - class Os2(KaitaiStruct): - """The OS/2 table consists of a set of metrics that are required by Windows and OS/2.""" - - class WeightClass(Enum): - thin = 100 - extra_light = 200 - light = 300 - normal = 400 - medium = 500 - semi_bold = 600 - bold = 700 - extra_bold = 800 - black = 900 - - class WidthClass(Enum): - ultra_condensed = 1 - extra_condensed = 2 - condensed = 3 - semi_condensed = 4 - normal = 5 - semi_expanded = 6 - expanded = 7 - extra_expanded = 8 - ultra_expanded = 9 - - class FsType(Enum): - restricted_license_embedding = 2 - preview_and_print_embedding = 4 - editable_embedding = 8 - - class FsSelection(Enum): - italic = 1 - underscore = 2 - negative = 4 - outlined = 8 - strikeout = 16 - bold = 32 - regular = 64 - SEQ_FIELDS = ["version", "x_avg_char_width", "weight_class", "width_class", "fs_type", "y_subscript_x_size", "y_subscript_y_size", "y_subscript_x_offset", "y_subscript_y_offset", "y_superscript_x_size", "y_superscript_y_size", "y_superscript_x_offset", "y_superscript_y_offset", "y_strikeout_size", "y_strikeout_position", "s_family_class", "panose", "unicode_range", "ach_vend_id", "selection", "first_char_index", "last_char_index", "typo_ascender", "typo_descender", "typo_line_gap", "win_ascent", "win_descent", "code_page_range"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2be() - self._debug['version']['end'] = self._io.pos() - self._debug['x_avg_char_width']['start'] = self._io.pos() - self.x_avg_char_width = self._io.read_s2be() - self._debug['x_avg_char_width']['end'] = self._io.pos() - self._debug['weight_class']['start'] = self._io.pos() - self.weight_class = KaitaiStream.resolve_enum(self._root.Os2.WeightClass, self._io.read_u2be()) - self._debug['weight_class']['end'] = self._io.pos() - self._debug['width_class']['start'] = self._io.pos() - self.width_class = KaitaiStream.resolve_enum(self._root.Os2.WidthClass, self._io.read_u2be()) - self._debug['width_class']['end'] = self._io.pos() - self._debug['fs_type']['start'] = self._io.pos() - self.fs_type = KaitaiStream.resolve_enum(self._root.Os2.FsType, self._io.read_s2be()) - self._debug['fs_type']['end'] = self._io.pos() - self._debug['y_subscript_x_size']['start'] = self._io.pos() - self.y_subscript_x_size = self._io.read_s2be() - self._debug['y_subscript_x_size']['end'] = self._io.pos() - self._debug['y_subscript_y_size']['start'] = self._io.pos() - self.y_subscript_y_size = self._io.read_s2be() - self._debug['y_subscript_y_size']['end'] = self._io.pos() - self._debug['y_subscript_x_offset']['start'] = self._io.pos() - self.y_subscript_x_offset = self._io.read_s2be() - self._debug['y_subscript_x_offset']['end'] = self._io.pos() - self._debug['y_subscript_y_offset']['start'] = self._io.pos() - self.y_subscript_y_offset = self._io.read_s2be() - self._debug['y_subscript_y_offset']['end'] = self._io.pos() - self._debug['y_superscript_x_size']['start'] = self._io.pos() - self.y_superscript_x_size = self._io.read_s2be() - self._debug['y_superscript_x_size']['end'] = self._io.pos() - self._debug['y_superscript_y_size']['start'] = self._io.pos() - self.y_superscript_y_size = self._io.read_s2be() - self._debug['y_superscript_y_size']['end'] = self._io.pos() - self._debug['y_superscript_x_offset']['start'] = self._io.pos() - self.y_superscript_x_offset = self._io.read_s2be() - self._debug['y_superscript_x_offset']['end'] = self._io.pos() - self._debug['y_superscript_y_offset']['start'] = self._io.pos() - self.y_superscript_y_offset = self._io.read_s2be() - self._debug['y_superscript_y_offset']['end'] = self._io.pos() - self._debug['y_strikeout_size']['start'] = self._io.pos() - self.y_strikeout_size = self._io.read_s2be() - self._debug['y_strikeout_size']['end'] = self._io.pos() - self._debug['y_strikeout_position']['start'] = self._io.pos() - self.y_strikeout_position = self._io.read_s2be() - self._debug['y_strikeout_position']['end'] = self._io.pos() - self._debug['s_family_class']['start'] = self._io.pos() - self.s_family_class = self._io.read_s2be() - self._debug['s_family_class']['end'] = self._io.pos() - self._debug['panose']['start'] = self._io.pos() - self.panose = self._root.Os2.Panose(self._io, self, self._root) - self.panose._read() - self._debug['panose']['end'] = self._io.pos() - self._debug['unicode_range']['start'] = self._io.pos() - self.unicode_range = self._root.Os2.UnicodeRange(self._io, self, self._root) - self.unicode_range._read() - self._debug['unicode_range']['end'] = self._io.pos() - self._debug['ach_vend_id']['start'] = self._io.pos() - self.ach_vend_id = (self._io.read_bytes(4)).decode(u"ascii") - self._debug['ach_vend_id']['end'] = self._io.pos() - self._debug['selection']['start'] = self._io.pos() - self.selection = KaitaiStream.resolve_enum(self._root.Os2.FsSelection, self._io.read_u2be()) - self._debug['selection']['end'] = self._io.pos() - self._debug['first_char_index']['start'] = self._io.pos() - self.first_char_index = self._io.read_u2be() - self._debug['first_char_index']['end'] = self._io.pos() - self._debug['last_char_index']['start'] = self._io.pos() - self.last_char_index = self._io.read_u2be() - self._debug['last_char_index']['end'] = self._io.pos() - self._debug['typo_ascender']['start'] = self._io.pos() - self.typo_ascender = self._io.read_s2be() - self._debug['typo_ascender']['end'] = self._io.pos() - self._debug['typo_descender']['start'] = self._io.pos() - self.typo_descender = self._io.read_s2be() - self._debug['typo_descender']['end'] = self._io.pos() - self._debug['typo_line_gap']['start'] = self._io.pos() - self.typo_line_gap = self._io.read_s2be() - self._debug['typo_line_gap']['end'] = self._io.pos() - self._debug['win_ascent']['start'] = self._io.pos() - self.win_ascent = self._io.read_u2be() - self._debug['win_ascent']['end'] = self._io.pos() - self._debug['win_descent']['start'] = self._io.pos() - self.win_descent = self._io.read_u2be() - self._debug['win_descent']['end'] = self._io.pos() - self._debug['code_page_range']['start'] = self._io.pos() - self.code_page_range = self._root.Os2.CodePageRange(self._io, self, self._root) - self.code_page_range._read() - self._debug['code_page_range']['end'] = self._io.pos() - - class Panose(KaitaiStruct): - - class Weight(Enum): - any = 0 - no_fit = 1 - very_light = 2 - light = 3 - thin = 4 - book = 5 - medium = 6 - demi = 7 - bold = 8 - heavy = 9 - black = 10 - nord = 11 - - class Proportion(Enum): - any = 0 - no_fit = 1 - old_style = 2 - modern = 3 - even_width = 4 - expanded = 5 - condensed = 6 - very_expanded = 7 - very_condensed = 8 - monospaced = 9 - - class FamilyKind(Enum): - any = 0 - no_fit = 1 - text_and_display = 2 - script = 3 - decorative = 4 - pictorial = 5 - - class LetterForm(Enum): - any = 0 - no_fit = 1 - normal_contact = 2 - normal_weighted = 3 - normal_boxed = 4 - normal_flattened = 5 - normal_rounded = 6 - normal_off_center = 7 - normal_square = 8 - oblique_contact = 9 - oblique_weighted = 10 - oblique_boxed = 11 - oblique_flattened = 12 - oblique_rounded = 13 - oblique_off_center = 14 - oblique_square = 15 - - class SerifStyle(Enum): - any = 0 - no_fit = 1 - cove = 2 - obtuse_cove = 3 - square_cove = 4 - obtuse_square_cove = 5 - square = 6 - thin = 7 - bone = 8 - exaggerated = 9 - triangle = 10 - normal_sans = 11 - obtuse_sans = 12 - perp_sans = 13 - flared = 14 - rounded = 15 - - class XHeight(Enum): - any = 0 - no_fit = 1 - constant_small = 2 - constant_standard = 3 - constant_large = 4 - ducking_small = 5 - ducking_standard = 6 - ducking_large = 7 - - class ArmStyle(Enum): - any = 0 - no_fit = 1 - straight_arms_horizontal = 2 - straight_arms_wedge = 3 - straight_arms_vertical = 4 - straight_arms_single_serif = 5 - straight_arms_double_serif = 6 - non_straight_arms_horizontal = 7 - non_straight_arms_wedge = 8 - non_straight_arms_vertical = 9 - non_straight_arms_single_serif = 10 - non_straight_arms_double_serif = 11 - - class StrokeVariation(Enum): - any = 0 - no_fit = 1 - gradual_diagonal = 2 - gradual_transitional = 3 - gradual_vertical = 4 - gradual_horizontal = 5 - rapid_vertical = 6 - rapid_horizontal = 7 - instant_vertical = 8 - - class Contrast(Enum): - any = 0 - no_fit = 1 - none = 2 - very_low = 3 - low = 4 - medium_low = 5 - medium = 6 - medium_high = 7 - high = 8 - very_high = 9 - - class Midline(Enum): - any = 0 - no_fit = 1 - standard_trimmed = 2 - standard_pointed = 3 - standard_serifed = 4 - high_trimmed = 5 - high_pointed = 6 - high_serifed = 7 - constant_trimmed = 8 - constant_pointed = 9 - constant_serifed = 10 - low_trimmed = 11 - low_pointed = 12 - low_serifed = 13 - SEQ_FIELDS = ["family_type", "serif_style", "weight", "proportion", "contrast", "stroke_variation", "arm_style", "letter_form", "midline", "x_height"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['family_type']['start'] = self._io.pos() - self.family_type = KaitaiStream.resolve_enum(self._root.Os2.Panose.FamilyKind, self._io.read_u1()) - self._debug['family_type']['end'] = self._io.pos() - self._debug['serif_style']['start'] = self._io.pos() - self.serif_style = KaitaiStream.resolve_enum(self._root.Os2.Panose.SerifStyle, self._io.read_u1()) - self._debug['serif_style']['end'] = self._io.pos() - self._debug['weight']['start'] = self._io.pos() - self.weight = KaitaiStream.resolve_enum(self._root.Os2.Panose.Weight, self._io.read_u1()) - self._debug['weight']['end'] = self._io.pos() - self._debug['proportion']['start'] = self._io.pos() - self.proportion = KaitaiStream.resolve_enum(self._root.Os2.Panose.Proportion, self._io.read_u1()) - self._debug['proportion']['end'] = self._io.pos() - self._debug['contrast']['start'] = self._io.pos() - self.contrast = KaitaiStream.resolve_enum(self._root.Os2.Panose.Contrast, self._io.read_u1()) - self._debug['contrast']['end'] = self._io.pos() - self._debug['stroke_variation']['start'] = self._io.pos() - self.stroke_variation = KaitaiStream.resolve_enum(self._root.Os2.Panose.StrokeVariation, self._io.read_u1()) - self._debug['stroke_variation']['end'] = self._io.pos() - self._debug['arm_style']['start'] = self._io.pos() - self.arm_style = KaitaiStream.resolve_enum(self._root.Os2.Panose.ArmStyle, self._io.read_u1()) - self._debug['arm_style']['end'] = self._io.pos() - self._debug['letter_form']['start'] = self._io.pos() - self.letter_form = KaitaiStream.resolve_enum(self._root.Os2.Panose.LetterForm, self._io.read_u1()) - self._debug['letter_form']['end'] = self._io.pos() - self._debug['midline']['start'] = self._io.pos() - self.midline = KaitaiStream.resolve_enum(self._root.Os2.Panose.Midline, self._io.read_u1()) - self._debug['midline']['end'] = self._io.pos() - self._debug['x_height']['start'] = self._io.pos() - self.x_height = KaitaiStream.resolve_enum(self._root.Os2.Panose.XHeight, self._io.read_u1()) - self._debug['x_height']['end'] = self._io.pos() - - - class UnicodeRange(KaitaiStruct): - SEQ_FIELDS = ["basic_latin", "latin_1_supplement", "latin_extended_a", "latin_extended_b", "ipa_extensions", "spacing_modifier_letters", "combining_diacritical_marks", "basic_greek", "greek_symbols_and_coptic", "cyrillic", "armenian", "basic_hebrew", "hebrew_extended", "basic_arabic", "arabic_extended", "devanagari", "bengali", "gurmukhi", "gujarati", "oriya", "tamil", "telugu", "kannada", "malayalam", "thai", "lao", "basic_georgian", "georgian_extended", "hangul_jamo", "latin_extended_additional", "greek_extended", "general_punctuation", "superscripts_and_subscripts", "currency_symbols", "combining_diacritical_marks_for_symbols", "letterlike_symbols", "number_forms", "arrows", "mathematical_operators", "miscellaneous_technical", "control_pictures", "optical_character_recognition", "enclosed_alphanumerics", "box_drawing", "block_elements", "geometric_shapes", "miscellaneous_symbols", "dingbats", "cjk_symbols_and_punctuation", "hiragana", "katakana", "bopomofo", "hangul_compatibility_jamo", "cjk_miscellaneous", "enclosed_cjk_letters_and_months", "cjk_compatibility", "hangul", "reserved_for_unicode_subranges1", "reserved_for_unicode_subranges2", "cjk_unified_ideographs", "private_use_area", "cjk_compatibility_ideographs", "alphabetic_presentation_forms", "arabic_presentation_forms_a", "combining_half_marks", "cjk_compatibility_forms", "small_form_variants", "arabic_presentation_forms_b", "halfwidth_and_fullwidth_forms", "specials", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['basic_latin']['start'] = self._io.pos() - self.basic_latin = self._io.read_bits_int(1) != 0 - self._debug['basic_latin']['end'] = self._io.pos() - self._debug['latin_1_supplement']['start'] = self._io.pos() - self.latin_1_supplement = self._io.read_bits_int(1) != 0 - self._debug['latin_1_supplement']['end'] = self._io.pos() - self._debug['latin_extended_a']['start'] = self._io.pos() - self.latin_extended_a = self._io.read_bits_int(1) != 0 - self._debug['latin_extended_a']['end'] = self._io.pos() - self._debug['latin_extended_b']['start'] = self._io.pos() - self.latin_extended_b = self._io.read_bits_int(1) != 0 - self._debug['latin_extended_b']['end'] = self._io.pos() - self._debug['ipa_extensions']['start'] = self._io.pos() - self.ipa_extensions = self._io.read_bits_int(1) != 0 - self._debug['ipa_extensions']['end'] = self._io.pos() - self._debug['spacing_modifier_letters']['start'] = self._io.pos() - self.spacing_modifier_letters = self._io.read_bits_int(1) != 0 - self._debug['spacing_modifier_letters']['end'] = self._io.pos() - self._debug['combining_diacritical_marks']['start'] = self._io.pos() - self.combining_diacritical_marks = self._io.read_bits_int(1) != 0 - self._debug['combining_diacritical_marks']['end'] = self._io.pos() - self._debug['basic_greek']['start'] = self._io.pos() - self.basic_greek = self._io.read_bits_int(1) != 0 - self._debug['basic_greek']['end'] = self._io.pos() - self._debug['greek_symbols_and_coptic']['start'] = self._io.pos() - self.greek_symbols_and_coptic = self._io.read_bits_int(1) != 0 - self._debug['greek_symbols_and_coptic']['end'] = self._io.pos() - self._debug['cyrillic']['start'] = self._io.pos() - self.cyrillic = self._io.read_bits_int(1) != 0 - self._debug['cyrillic']['end'] = self._io.pos() - self._debug['armenian']['start'] = self._io.pos() - self.armenian = self._io.read_bits_int(1) != 0 - self._debug['armenian']['end'] = self._io.pos() - self._debug['basic_hebrew']['start'] = self._io.pos() - self.basic_hebrew = self._io.read_bits_int(1) != 0 - self._debug['basic_hebrew']['end'] = self._io.pos() - self._debug['hebrew_extended']['start'] = self._io.pos() - self.hebrew_extended = self._io.read_bits_int(1) != 0 - self._debug['hebrew_extended']['end'] = self._io.pos() - self._debug['basic_arabic']['start'] = self._io.pos() - self.basic_arabic = self._io.read_bits_int(1) != 0 - self._debug['basic_arabic']['end'] = self._io.pos() - self._debug['arabic_extended']['start'] = self._io.pos() - self.arabic_extended = self._io.read_bits_int(1) != 0 - self._debug['arabic_extended']['end'] = self._io.pos() - self._debug['devanagari']['start'] = self._io.pos() - self.devanagari = self._io.read_bits_int(1) != 0 - self._debug['devanagari']['end'] = self._io.pos() - self._debug['bengali']['start'] = self._io.pos() - self.bengali = self._io.read_bits_int(1) != 0 - self._debug['bengali']['end'] = self._io.pos() - self._debug['gurmukhi']['start'] = self._io.pos() - self.gurmukhi = self._io.read_bits_int(1) != 0 - self._debug['gurmukhi']['end'] = self._io.pos() - self._debug['gujarati']['start'] = self._io.pos() - self.gujarati = self._io.read_bits_int(1) != 0 - self._debug['gujarati']['end'] = self._io.pos() - self._debug['oriya']['start'] = self._io.pos() - self.oriya = self._io.read_bits_int(1) != 0 - self._debug['oriya']['end'] = self._io.pos() - self._debug['tamil']['start'] = self._io.pos() - self.tamil = self._io.read_bits_int(1) != 0 - self._debug['tamil']['end'] = self._io.pos() - self._debug['telugu']['start'] = self._io.pos() - self.telugu = self._io.read_bits_int(1) != 0 - self._debug['telugu']['end'] = self._io.pos() - self._debug['kannada']['start'] = self._io.pos() - self.kannada = self._io.read_bits_int(1) != 0 - self._debug['kannada']['end'] = self._io.pos() - self._debug['malayalam']['start'] = self._io.pos() - self.malayalam = self._io.read_bits_int(1) != 0 - self._debug['malayalam']['end'] = self._io.pos() - self._debug['thai']['start'] = self._io.pos() - self.thai = self._io.read_bits_int(1) != 0 - self._debug['thai']['end'] = self._io.pos() - self._debug['lao']['start'] = self._io.pos() - self.lao = self._io.read_bits_int(1) != 0 - self._debug['lao']['end'] = self._io.pos() - self._debug['basic_georgian']['start'] = self._io.pos() - self.basic_georgian = self._io.read_bits_int(1) != 0 - self._debug['basic_georgian']['end'] = self._io.pos() - self._debug['georgian_extended']['start'] = self._io.pos() - self.georgian_extended = self._io.read_bits_int(1) != 0 - self._debug['georgian_extended']['end'] = self._io.pos() - self._debug['hangul_jamo']['start'] = self._io.pos() - self.hangul_jamo = self._io.read_bits_int(1) != 0 - self._debug['hangul_jamo']['end'] = self._io.pos() - self._debug['latin_extended_additional']['start'] = self._io.pos() - self.latin_extended_additional = self._io.read_bits_int(1) != 0 - self._debug['latin_extended_additional']['end'] = self._io.pos() - self._debug['greek_extended']['start'] = self._io.pos() - self.greek_extended = self._io.read_bits_int(1) != 0 - self._debug['greek_extended']['end'] = self._io.pos() - self._debug['general_punctuation']['start'] = self._io.pos() - self.general_punctuation = self._io.read_bits_int(1) != 0 - self._debug['general_punctuation']['end'] = self._io.pos() - self._debug['superscripts_and_subscripts']['start'] = self._io.pos() - self.superscripts_and_subscripts = self._io.read_bits_int(1) != 0 - self._debug['superscripts_and_subscripts']['end'] = self._io.pos() - self._debug['currency_symbols']['start'] = self._io.pos() - self.currency_symbols = self._io.read_bits_int(1) != 0 - self._debug['currency_symbols']['end'] = self._io.pos() - self._debug['combining_diacritical_marks_for_symbols']['start'] = self._io.pos() - self.combining_diacritical_marks_for_symbols = self._io.read_bits_int(1) != 0 - self._debug['combining_diacritical_marks_for_symbols']['end'] = self._io.pos() - self._debug['letterlike_symbols']['start'] = self._io.pos() - self.letterlike_symbols = self._io.read_bits_int(1) != 0 - self._debug['letterlike_symbols']['end'] = self._io.pos() - self._debug['number_forms']['start'] = self._io.pos() - self.number_forms = self._io.read_bits_int(1) != 0 - self._debug['number_forms']['end'] = self._io.pos() - self._debug['arrows']['start'] = self._io.pos() - self.arrows = self._io.read_bits_int(1) != 0 - self._debug['arrows']['end'] = self._io.pos() - self._debug['mathematical_operators']['start'] = self._io.pos() - self.mathematical_operators = self._io.read_bits_int(1) != 0 - self._debug['mathematical_operators']['end'] = self._io.pos() - self._debug['miscellaneous_technical']['start'] = self._io.pos() - self.miscellaneous_technical = self._io.read_bits_int(1) != 0 - self._debug['miscellaneous_technical']['end'] = self._io.pos() - self._debug['control_pictures']['start'] = self._io.pos() - self.control_pictures = self._io.read_bits_int(1) != 0 - self._debug['control_pictures']['end'] = self._io.pos() - self._debug['optical_character_recognition']['start'] = self._io.pos() - self.optical_character_recognition = self._io.read_bits_int(1) != 0 - self._debug['optical_character_recognition']['end'] = self._io.pos() - self._debug['enclosed_alphanumerics']['start'] = self._io.pos() - self.enclosed_alphanumerics = self._io.read_bits_int(1) != 0 - self._debug['enclosed_alphanumerics']['end'] = self._io.pos() - self._debug['box_drawing']['start'] = self._io.pos() - self.box_drawing = self._io.read_bits_int(1) != 0 - self._debug['box_drawing']['end'] = self._io.pos() - self._debug['block_elements']['start'] = self._io.pos() - self.block_elements = self._io.read_bits_int(1) != 0 - self._debug['block_elements']['end'] = self._io.pos() - self._debug['geometric_shapes']['start'] = self._io.pos() - self.geometric_shapes = self._io.read_bits_int(1) != 0 - self._debug['geometric_shapes']['end'] = self._io.pos() - self._debug['miscellaneous_symbols']['start'] = self._io.pos() - self.miscellaneous_symbols = self._io.read_bits_int(1) != 0 - self._debug['miscellaneous_symbols']['end'] = self._io.pos() - self._debug['dingbats']['start'] = self._io.pos() - self.dingbats = self._io.read_bits_int(1) != 0 - self._debug['dingbats']['end'] = self._io.pos() - self._debug['cjk_symbols_and_punctuation']['start'] = self._io.pos() - self.cjk_symbols_and_punctuation = self._io.read_bits_int(1) != 0 - self._debug['cjk_symbols_and_punctuation']['end'] = self._io.pos() - self._debug['hiragana']['start'] = self._io.pos() - self.hiragana = self._io.read_bits_int(1) != 0 - self._debug['hiragana']['end'] = self._io.pos() - self._debug['katakana']['start'] = self._io.pos() - self.katakana = self._io.read_bits_int(1) != 0 - self._debug['katakana']['end'] = self._io.pos() - self._debug['bopomofo']['start'] = self._io.pos() - self.bopomofo = self._io.read_bits_int(1) != 0 - self._debug['bopomofo']['end'] = self._io.pos() - self._debug['hangul_compatibility_jamo']['start'] = self._io.pos() - self.hangul_compatibility_jamo = self._io.read_bits_int(1) != 0 - self._debug['hangul_compatibility_jamo']['end'] = self._io.pos() - self._debug['cjk_miscellaneous']['start'] = self._io.pos() - self.cjk_miscellaneous = self._io.read_bits_int(1) != 0 - self._debug['cjk_miscellaneous']['end'] = self._io.pos() - self._debug['enclosed_cjk_letters_and_months']['start'] = self._io.pos() - self.enclosed_cjk_letters_and_months = self._io.read_bits_int(1) != 0 - self._debug['enclosed_cjk_letters_and_months']['end'] = self._io.pos() - self._debug['cjk_compatibility']['start'] = self._io.pos() - self.cjk_compatibility = self._io.read_bits_int(1) != 0 - self._debug['cjk_compatibility']['end'] = self._io.pos() - self._debug['hangul']['start'] = self._io.pos() - self.hangul = self._io.read_bits_int(1) != 0 - self._debug['hangul']['end'] = self._io.pos() - self._debug['reserved_for_unicode_subranges1']['start'] = self._io.pos() - self.reserved_for_unicode_subranges1 = self._io.read_bits_int(1) != 0 - self._debug['reserved_for_unicode_subranges1']['end'] = self._io.pos() - self._debug['reserved_for_unicode_subranges2']['start'] = self._io.pos() - self.reserved_for_unicode_subranges2 = self._io.read_bits_int(1) != 0 - self._debug['reserved_for_unicode_subranges2']['end'] = self._io.pos() - self._debug['cjk_unified_ideographs']['start'] = self._io.pos() - self.cjk_unified_ideographs = self._io.read_bits_int(1) != 0 - self._debug['cjk_unified_ideographs']['end'] = self._io.pos() - self._debug['private_use_area']['start'] = self._io.pos() - self.private_use_area = self._io.read_bits_int(1) != 0 - self._debug['private_use_area']['end'] = self._io.pos() - self._debug['cjk_compatibility_ideographs']['start'] = self._io.pos() - self.cjk_compatibility_ideographs = self._io.read_bits_int(1) != 0 - self._debug['cjk_compatibility_ideographs']['end'] = self._io.pos() - self._debug['alphabetic_presentation_forms']['start'] = self._io.pos() - self.alphabetic_presentation_forms = self._io.read_bits_int(1) != 0 - self._debug['alphabetic_presentation_forms']['end'] = self._io.pos() - self._debug['arabic_presentation_forms_a']['start'] = self._io.pos() - self.arabic_presentation_forms_a = self._io.read_bits_int(1) != 0 - self._debug['arabic_presentation_forms_a']['end'] = self._io.pos() - self._debug['combining_half_marks']['start'] = self._io.pos() - self.combining_half_marks = self._io.read_bits_int(1) != 0 - self._debug['combining_half_marks']['end'] = self._io.pos() - self._debug['cjk_compatibility_forms']['start'] = self._io.pos() - self.cjk_compatibility_forms = self._io.read_bits_int(1) != 0 - self._debug['cjk_compatibility_forms']['end'] = self._io.pos() - self._debug['small_form_variants']['start'] = self._io.pos() - self.small_form_variants = self._io.read_bits_int(1) != 0 - self._debug['small_form_variants']['end'] = self._io.pos() - self._debug['arabic_presentation_forms_b']['start'] = self._io.pos() - self.arabic_presentation_forms_b = self._io.read_bits_int(1) != 0 - self._debug['arabic_presentation_forms_b']['end'] = self._io.pos() - self._debug['halfwidth_and_fullwidth_forms']['start'] = self._io.pos() - self.halfwidth_and_fullwidth_forms = self._io.read_bits_int(1) != 0 - self._debug['halfwidth_and_fullwidth_forms']['end'] = self._io.pos() - self._debug['specials']['start'] = self._io.pos() - self.specials = self._io.read_bits_int(1) != 0 - self._debug['specials']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(7) - self._debug['reserved']['end'] = self._io.pos() - - - class CodePageRange(KaitaiStruct): - SEQ_FIELDS = ["symbol_character_set", "oem_character_set", "macintosh_character_set", "reserved_for_alternate_ansi_oem", "cp1361_korean_johab", "cp950_chinese_traditional_chars_taiwan_and_hong_kong", "cp949_korean_wansung", "cp936_chinese_simplified_chars_prc_and_singapore", "cp932_jis_japan", "cp874_thai", "reserved_for_alternate_ansi", "cp1257_windows_baltic", "cp1256_arabic", "cp1255_hebrew", "cp1254_turkish", "cp1253_greek", "cp1251_cyrillic", "cp1250_latin_2_eastern_europe", "cp1252_latin_1", "cp437_us", "cp850_we_latin_1", "cp708_arabic_asmo_708", "cp737_greek_former_437_g", "cp775_ms_dos_baltic", "cp852_latin_2", "cp855_ibm_cyrillic_primarily_russian", "cp857_ibm_turkish", "cp860_ms_dos_portuguese", "cp861_ms_dos_icelandic", "cp862_hebrew", "cp863_ms_dos_canadian_french", "cp864_arabic", "cp865_ms_dos_nordic", "cp866_ms_dos_russian", "cp869_ibm_greek", "reserved_for_oem"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['symbol_character_set']['start'] = self._io.pos() - self.symbol_character_set = self._io.read_bits_int(1) != 0 - self._debug['symbol_character_set']['end'] = self._io.pos() - self._debug['oem_character_set']['start'] = self._io.pos() - self.oem_character_set = self._io.read_bits_int(1) != 0 - self._debug['oem_character_set']['end'] = self._io.pos() - self._debug['macintosh_character_set']['start'] = self._io.pos() - self.macintosh_character_set = self._io.read_bits_int(1) != 0 - self._debug['macintosh_character_set']['end'] = self._io.pos() - self._debug['reserved_for_alternate_ansi_oem']['start'] = self._io.pos() - self.reserved_for_alternate_ansi_oem = self._io.read_bits_int(7) - self._debug['reserved_for_alternate_ansi_oem']['end'] = self._io.pos() - self._debug['cp1361_korean_johab']['start'] = self._io.pos() - self.cp1361_korean_johab = self._io.read_bits_int(1) != 0 - self._debug['cp1361_korean_johab']['end'] = self._io.pos() - self._debug['cp950_chinese_traditional_chars_taiwan_and_hong_kong']['start'] = self._io.pos() - self.cp950_chinese_traditional_chars_taiwan_and_hong_kong = self._io.read_bits_int(1) != 0 - self._debug['cp950_chinese_traditional_chars_taiwan_and_hong_kong']['end'] = self._io.pos() - self._debug['cp949_korean_wansung']['start'] = self._io.pos() - self.cp949_korean_wansung = self._io.read_bits_int(1) != 0 - self._debug['cp949_korean_wansung']['end'] = self._io.pos() - self._debug['cp936_chinese_simplified_chars_prc_and_singapore']['start'] = self._io.pos() - self.cp936_chinese_simplified_chars_prc_and_singapore = self._io.read_bits_int(1) != 0 - self._debug['cp936_chinese_simplified_chars_prc_and_singapore']['end'] = self._io.pos() - self._debug['cp932_jis_japan']['start'] = self._io.pos() - self.cp932_jis_japan = self._io.read_bits_int(1) != 0 - self._debug['cp932_jis_japan']['end'] = self._io.pos() - self._debug['cp874_thai']['start'] = self._io.pos() - self.cp874_thai = self._io.read_bits_int(1) != 0 - self._debug['cp874_thai']['end'] = self._io.pos() - self._debug['reserved_for_alternate_ansi']['start'] = self._io.pos() - self.reserved_for_alternate_ansi = self._io.read_bits_int(8) - self._debug['reserved_for_alternate_ansi']['end'] = self._io.pos() - self._debug['cp1257_windows_baltic']['start'] = self._io.pos() - self.cp1257_windows_baltic = self._io.read_bits_int(1) != 0 - self._debug['cp1257_windows_baltic']['end'] = self._io.pos() - self._debug['cp1256_arabic']['start'] = self._io.pos() - self.cp1256_arabic = self._io.read_bits_int(1) != 0 - self._debug['cp1256_arabic']['end'] = self._io.pos() - self._debug['cp1255_hebrew']['start'] = self._io.pos() - self.cp1255_hebrew = self._io.read_bits_int(1) != 0 - self._debug['cp1255_hebrew']['end'] = self._io.pos() - self._debug['cp1254_turkish']['start'] = self._io.pos() - self.cp1254_turkish = self._io.read_bits_int(1) != 0 - self._debug['cp1254_turkish']['end'] = self._io.pos() - self._debug['cp1253_greek']['start'] = self._io.pos() - self.cp1253_greek = self._io.read_bits_int(1) != 0 - self._debug['cp1253_greek']['end'] = self._io.pos() - self._debug['cp1251_cyrillic']['start'] = self._io.pos() - self.cp1251_cyrillic = self._io.read_bits_int(1) != 0 - self._debug['cp1251_cyrillic']['end'] = self._io.pos() - self._debug['cp1250_latin_2_eastern_europe']['start'] = self._io.pos() - self.cp1250_latin_2_eastern_europe = self._io.read_bits_int(1) != 0 - self._debug['cp1250_latin_2_eastern_europe']['end'] = self._io.pos() - self._debug['cp1252_latin_1']['start'] = self._io.pos() - self.cp1252_latin_1 = self._io.read_bits_int(1) != 0 - self._debug['cp1252_latin_1']['end'] = self._io.pos() - self._debug['cp437_us']['start'] = self._io.pos() - self.cp437_us = self._io.read_bits_int(1) != 0 - self._debug['cp437_us']['end'] = self._io.pos() - self._debug['cp850_we_latin_1']['start'] = self._io.pos() - self.cp850_we_latin_1 = self._io.read_bits_int(1) != 0 - self._debug['cp850_we_latin_1']['end'] = self._io.pos() - self._debug['cp708_arabic_asmo_708']['start'] = self._io.pos() - self.cp708_arabic_asmo_708 = self._io.read_bits_int(1) != 0 - self._debug['cp708_arabic_asmo_708']['end'] = self._io.pos() - self._debug['cp737_greek_former_437_g']['start'] = self._io.pos() - self.cp737_greek_former_437_g = self._io.read_bits_int(1) != 0 - self._debug['cp737_greek_former_437_g']['end'] = self._io.pos() - self._debug['cp775_ms_dos_baltic']['start'] = self._io.pos() - self.cp775_ms_dos_baltic = self._io.read_bits_int(1) != 0 - self._debug['cp775_ms_dos_baltic']['end'] = self._io.pos() - self._debug['cp852_latin_2']['start'] = self._io.pos() - self.cp852_latin_2 = self._io.read_bits_int(1) != 0 - self._debug['cp852_latin_2']['end'] = self._io.pos() - self._debug['cp855_ibm_cyrillic_primarily_russian']['start'] = self._io.pos() - self.cp855_ibm_cyrillic_primarily_russian = self._io.read_bits_int(1) != 0 - self._debug['cp855_ibm_cyrillic_primarily_russian']['end'] = self._io.pos() - self._debug['cp857_ibm_turkish']['start'] = self._io.pos() - self.cp857_ibm_turkish = self._io.read_bits_int(1) != 0 - self._debug['cp857_ibm_turkish']['end'] = self._io.pos() - self._debug['cp860_ms_dos_portuguese']['start'] = self._io.pos() - self.cp860_ms_dos_portuguese = self._io.read_bits_int(1) != 0 - self._debug['cp860_ms_dos_portuguese']['end'] = self._io.pos() - self._debug['cp861_ms_dos_icelandic']['start'] = self._io.pos() - self.cp861_ms_dos_icelandic = self._io.read_bits_int(1) != 0 - self._debug['cp861_ms_dos_icelandic']['end'] = self._io.pos() - self._debug['cp862_hebrew']['start'] = self._io.pos() - self.cp862_hebrew = self._io.read_bits_int(1) != 0 - self._debug['cp862_hebrew']['end'] = self._io.pos() - self._debug['cp863_ms_dos_canadian_french']['start'] = self._io.pos() - self.cp863_ms_dos_canadian_french = self._io.read_bits_int(1) != 0 - self._debug['cp863_ms_dos_canadian_french']['end'] = self._io.pos() - self._debug['cp864_arabic']['start'] = self._io.pos() - self.cp864_arabic = self._io.read_bits_int(1) != 0 - self._debug['cp864_arabic']['end'] = self._io.pos() - self._debug['cp865_ms_dos_nordic']['start'] = self._io.pos() - self.cp865_ms_dos_nordic = self._io.read_bits_int(1) != 0 - self._debug['cp865_ms_dos_nordic']['end'] = self._io.pos() - self._debug['cp866_ms_dos_russian']['start'] = self._io.pos() - self.cp866_ms_dos_russian = self._io.read_bits_int(1) != 0 - self._debug['cp866_ms_dos_russian']['end'] = self._io.pos() - self._debug['cp869_ibm_greek']['start'] = self._io.pos() - self.cp869_ibm_greek = self._io.read_bits_int(1) != 0 - self._debug['cp869_ibm_greek']['end'] = self._io.pos() - self._debug['reserved_for_oem']['start'] = self._io.pos() - self.reserved_for_oem = self._io.read_bits_int(16) - self._debug['reserved_for_oem']['end'] = self._io.pos() - - - - class Fixed(KaitaiStruct): - SEQ_FIELDS = ["major", "minor"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u2be() - self._debug['major']['end'] = self._io.pos() - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u2be() - self._debug['minor']['end'] = self._io.pos() - - - class Glyf(KaitaiStruct): - SEQ_FIELDS = ["number_of_contours", "x_min", "y_min", "x_max", "y_max", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['number_of_contours']['start'] = self._io.pos() - self.number_of_contours = self._io.read_s2be() - self._debug['number_of_contours']['end'] = self._io.pos() - self._debug['x_min']['start'] = self._io.pos() - self.x_min = self._io.read_s2be() - self._debug['x_min']['end'] = self._io.pos() - self._debug['y_min']['start'] = self._io.pos() - self.y_min = self._io.read_s2be() - self._debug['y_min']['end'] = self._io.pos() - self._debug['x_max']['start'] = self._io.pos() - self.x_max = self._io.read_s2be() - self._debug['x_max']['end'] = self._io.pos() - self._debug['y_max']['start'] = self._io.pos() - self.y_max = self._io.read_s2be() - self._debug['y_max']['end'] = self._io.pos() - if self.number_of_contours > 0: - self._debug['value']['start'] = self._io.pos() - self.value = self._root.Glyf.SimpleGlyph(self._io, self, self._root) - self.value._read() - self._debug['value']['end'] = self._io.pos() - - - class SimpleGlyph(KaitaiStruct): - SEQ_FIELDS = ["end_pts_of_contours", "instruction_length", "instructions", "flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['end_pts_of_contours']['start'] = self._io.pos() - self.end_pts_of_contours = [None] * (self._parent.number_of_contours) - for i in range(self._parent.number_of_contours): - if not 'arr' in self._debug['end_pts_of_contours']: - self._debug['end_pts_of_contours']['arr'] = [] - self._debug['end_pts_of_contours']['arr'].append({'start': self._io.pos()}) - self.end_pts_of_contours[i] = self._io.read_u2be() - self._debug['end_pts_of_contours']['arr'][i]['end'] = self._io.pos() - - self._debug['end_pts_of_contours']['end'] = self._io.pos() - self._debug['instruction_length']['start'] = self._io.pos() - self.instruction_length = self._io.read_u2be() - self._debug['instruction_length']['end'] = self._io.pos() - self._debug['instructions']['start'] = self._io.pos() - self.instructions = self._io.read_bytes(self.instruction_length) - self._debug['instructions']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = [None] * (self.point_count) - for i in range(self.point_count): - if not 'arr' in self._debug['flags']: - self._debug['flags']['arr'] = [] - self._debug['flags']['arr'].append({'start': self._io.pos()}) - _t_flags = self._root.Glyf.SimpleGlyph.Flag(self._io, self, self._root) - _t_flags._read() - self.flags[i] = _t_flags - self._debug['flags']['arr'][i]['end'] = self._io.pos() - - self._debug['flags']['end'] = self._io.pos() - - class Flag(KaitaiStruct): - SEQ_FIELDS = ["reserved", "y_is_same", "x_is_same", "repeat", "y_short_vector", "x_short_vector", "on_curve", "repeat_value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(2) - self._debug['reserved']['end'] = self._io.pos() - self._debug['y_is_same']['start'] = self._io.pos() - self.y_is_same = self._io.read_bits_int(1) != 0 - self._debug['y_is_same']['end'] = self._io.pos() - self._debug['x_is_same']['start'] = self._io.pos() - self.x_is_same = self._io.read_bits_int(1) != 0 - self._debug['x_is_same']['end'] = self._io.pos() - self._debug['repeat']['start'] = self._io.pos() - self.repeat = self._io.read_bits_int(1) != 0 - self._debug['repeat']['end'] = self._io.pos() - self._debug['y_short_vector']['start'] = self._io.pos() - self.y_short_vector = self._io.read_bits_int(1) != 0 - self._debug['y_short_vector']['end'] = self._io.pos() - self._debug['x_short_vector']['start'] = self._io.pos() - self.x_short_vector = self._io.read_bits_int(1) != 0 - self._debug['x_short_vector']['end'] = self._io.pos() - self._debug['on_curve']['start'] = self._io.pos() - self.on_curve = self._io.read_bits_int(1) != 0 - self._debug['on_curve']['end'] = self._io.pos() - self._io.align_to_byte() - if self.repeat: - self._debug['repeat_value']['start'] = self._io.pos() - self.repeat_value = self._io.read_u1() - self._debug['repeat_value']['end'] = self._io.pos() - - - - @property - def point_count(self): - if hasattr(self, '_m_point_count'): - return self._m_point_count if hasattr(self, '_m_point_count') else None - - self._m_point_count = (max(self.end_pts_of_contours) + 1) - return self._m_point_count if hasattr(self, '_m_point_count') else None - - - - class Cvt(KaitaiStruct): - """cvt - Control Value Table This table contains a list of values that can be referenced by instructions. They can be used, among other things, to control characteristics for different glyphs. - """ - SEQ_FIELDS = ["fwords"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['fwords']['start'] = self._io.pos() - self.fwords = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['fwords']: - self._debug['fwords']['arr'] = [] - self._debug['fwords']['arr'].append({'start': self._io.pos()}) - self.fwords.append(self._io.read_s2be()) - self._debug['fwords']['arr'][len(self.fwords) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['fwords']['end'] = self._io.pos() - - - class Maxp(KaitaiStruct): - SEQ_FIELDS = ["table_version_number", "num_glyphs", "max_points", "max_contours", "max_composite_points", "max_composite_contours", "max_zones", "max_twilight_points", "max_storage", "max_function_defs", "max_instruction_defs", "max_stack_elements", "max_size_of_instructions", "max_component_elements", "max_component_depth"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['table_version_number']['start'] = self._io.pos() - self.table_version_number = self._root.Fixed(self._io, self, self._root) - self.table_version_number._read() - self._debug['table_version_number']['end'] = self._io.pos() - self._debug['num_glyphs']['start'] = self._io.pos() - self.num_glyphs = self._io.read_u2be() - self._debug['num_glyphs']['end'] = self._io.pos() - self._debug['max_points']['start'] = self._io.pos() - self.max_points = self._io.read_u2be() - self._debug['max_points']['end'] = self._io.pos() - self._debug['max_contours']['start'] = self._io.pos() - self.max_contours = self._io.read_u2be() - self._debug['max_contours']['end'] = self._io.pos() - self._debug['max_composite_points']['start'] = self._io.pos() - self.max_composite_points = self._io.read_u2be() - self._debug['max_composite_points']['end'] = self._io.pos() - self._debug['max_composite_contours']['start'] = self._io.pos() - self.max_composite_contours = self._io.read_u2be() - self._debug['max_composite_contours']['end'] = self._io.pos() - self._debug['max_zones']['start'] = self._io.pos() - self.max_zones = self._io.read_u2be() - self._debug['max_zones']['end'] = self._io.pos() - self._debug['max_twilight_points']['start'] = self._io.pos() - self.max_twilight_points = self._io.read_u2be() - self._debug['max_twilight_points']['end'] = self._io.pos() - self._debug['max_storage']['start'] = self._io.pos() - self.max_storage = self._io.read_u2be() - self._debug['max_storage']['end'] = self._io.pos() - self._debug['max_function_defs']['start'] = self._io.pos() - self.max_function_defs = self._io.read_u2be() - self._debug['max_function_defs']['end'] = self._io.pos() - self._debug['max_instruction_defs']['start'] = self._io.pos() - self.max_instruction_defs = self._io.read_u2be() - self._debug['max_instruction_defs']['end'] = self._io.pos() - self._debug['max_stack_elements']['start'] = self._io.pos() - self.max_stack_elements = self._io.read_u2be() - self._debug['max_stack_elements']['end'] = self._io.pos() - self._debug['max_size_of_instructions']['start'] = self._io.pos() - self.max_size_of_instructions = self._io.read_u2be() - self._debug['max_size_of_instructions']['end'] = self._io.pos() - self._debug['max_component_elements']['start'] = self._io.pos() - self.max_component_elements = self._io.read_u2be() - self._debug['max_component_elements']['end'] = self._io.pos() - self._debug['max_component_depth']['start'] = self._io.pos() - self.max_component_depth = self._io.read_u2be() - self._debug['max_component_depth']['end'] = self._io.pos() - - - class OffsetTable(KaitaiStruct): - SEQ_FIELDS = ["sfnt_version", "num_tables", "search_range", "entry_selector", "range_shift"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sfnt_version']['start'] = self._io.pos() - self.sfnt_version = self._root.Fixed(self._io, self, self._root) - self.sfnt_version._read() - self._debug['sfnt_version']['end'] = self._io.pos() - self._debug['num_tables']['start'] = self._io.pos() - self.num_tables = self._io.read_u2be() - self._debug['num_tables']['end'] = self._io.pos() - self._debug['search_range']['start'] = self._io.pos() - self.search_range = self._io.read_u2be() - self._debug['search_range']['end'] = self._io.pos() - self._debug['entry_selector']['start'] = self._io.pos() - self.entry_selector = self._io.read_u2be() - self._debug['entry_selector']['end'] = self._io.pos() - self._debug['range_shift']['start'] = self._io.pos() - self.range_shift = self._io.read_u2be() - self._debug['range_shift']['end'] = self._io.pos() - - - class Cmap(KaitaiStruct): - """cmap - Character To Glyph Index Mapping Table This table defines the mapping of character codes to the glyph index values used in the font. - """ - SEQ_FIELDS = ["version_number", "number_of_encoding_tables", "tables"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version_number']['start'] = self._io.pos() - self.version_number = self._io.read_u2be() - self._debug['version_number']['end'] = self._io.pos() - self._debug['number_of_encoding_tables']['start'] = self._io.pos() - self.number_of_encoding_tables = self._io.read_u2be() - self._debug['number_of_encoding_tables']['end'] = self._io.pos() - self._debug['tables']['start'] = self._io.pos() - self.tables = [None] * (self.number_of_encoding_tables) - for i in range(self.number_of_encoding_tables): - if not 'arr' in self._debug['tables']: - self._debug['tables']['arr'] = [] - self._debug['tables']['arr'].append({'start': self._io.pos()}) - _t_tables = self._root.Cmap.SubtableHeader(self._io, self, self._root) - _t_tables._read() - self.tables[i] = _t_tables - self._debug['tables']['arr'][i]['end'] = self._io.pos() - - self._debug['tables']['end'] = self._io.pos() - - class SubtableHeader(KaitaiStruct): - SEQ_FIELDS = ["platform_id", "encoding_id", "subtable_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['platform_id']['start'] = self._io.pos() - self.platform_id = self._io.read_u2be() - self._debug['platform_id']['end'] = self._io.pos() - self._debug['encoding_id']['start'] = self._io.pos() - self.encoding_id = self._io.read_u2be() - self._debug['encoding_id']['end'] = self._io.pos() - self._debug['subtable_offset']['start'] = self._io.pos() - self.subtable_offset = self._io.read_u4be() - self._debug['subtable_offset']['end'] = self._io.pos() - - @property - def table(self): - if hasattr(self, '_m_table'): - return self._m_table if hasattr(self, '_m_table') else None - - io = self._parent._io - _pos = io.pos() - io.seek(self.subtable_offset) - self._debug['_m_table']['start'] = io.pos() - self._m_table = self._root.Cmap.Subtable(io, self, self._root) - self._m_table._read() - self._debug['_m_table']['end'] = io.pos() - io.seek(_pos) - return self._m_table if hasattr(self, '_m_table') else None - - - class Subtable(KaitaiStruct): - - class SubtableFormat(Enum): - byte_encoding_table = 0 - high_byte_mapping_through_table = 2 - segment_mapping_to_delta_values = 4 - trimmed_table_mapping = 6 - SEQ_FIELDS = ["format", "length", "version", "value"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['format']['start'] = self._io.pos() - self.format = KaitaiStream.resolve_enum(self._root.Cmap.Subtable.SubtableFormat, self._io.read_u2be()) - self._debug['format']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2be() - self._debug['version']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - _on = self.format - if _on == self._root.Cmap.Subtable.SubtableFormat.byte_encoding_table: - self._raw_value = self._io.read_bytes((self.length - 6)) - io = KaitaiStream(BytesIO(self._raw_value)) - self.value = self._root.Cmap.Subtable.ByteEncodingTable(io, self, self._root) - self.value._read() - elif _on == self._root.Cmap.Subtable.SubtableFormat.segment_mapping_to_delta_values: - self._raw_value = self._io.read_bytes((self.length - 6)) - io = KaitaiStream(BytesIO(self._raw_value)) - self.value = self._root.Cmap.Subtable.SegmentMappingToDeltaValues(io, self, self._root) - self.value._read() - elif _on == self._root.Cmap.Subtable.SubtableFormat.high_byte_mapping_through_table: - self._raw_value = self._io.read_bytes((self.length - 6)) - io = KaitaiStream(BytesIO(self._raw_value)) - self.value = self._root.Cmap.Subtable.HighByteMappingThroughTable(io, self, self._root) - self.value._read() - elif _on == self._root.Cmap.Subtable.SubtableFormat.trimmed_table_mapping: - self._raw_value = self._io.read_bytes((self.length - 6)) - io = KaitaiStream(BytesIO(self._raw_value)) - self.value = self._root.Cmap.Subtable.TrimmedTableMapping(io, self, self._root) - self.value._read() - else: - self.value = self._io.read_bytes((self.length - 6)) - self._debug['value']['end'] = self._io.pos() - - class ByteEncodingTable(KaitaiStruct): - SEQ_FIELDS = ["glyph_id_array"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['glyph_id_array']['start'] = self._io.pos() - self.glyph_id_array = self._io.read_bytes(256) - self._debug['glyph_id_array']['end'] = self._io.pos() - - - class HighByteMappingThroughTable(KaitaiStruct): - SEQ_FIELDS = ["sub_header_keys"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sub_header_keys']['start'] = self._io.pos() - self.sub_header_keys = [None] * (256) - for i in range(256): - if not 'arr' in self._debug['sub_header_keys']: - self._debug['sub_header_keys']['arr'] = [] - self._debug['sub_header_keys']['arr'].append({'start': self._io.pos()}) - self.sub_header_keys[i] = self._io.read_u2be() - self._debug['sub_header_keys']['arr'][i]['end'] = self._io.pos() - - self._debug['sub_header_keys']['end'] = self._io.pos() - - - class SegmentMappingToDeltaValues(KaitaiStruct): - SEQ_FIELDS = ["seg_count_x2", "search_range", "entry_selector", "range_shift", "end_count", "reserved_pad", "start_count", "id_delta", "id_range_offset", "glyph_id_array"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['seg_count_x2']['start'] = self._io.pos() - self.seg_count_x2 = self._io.read_u2be() - self._debug['seg_count_x2']['end'] = self._io.pos() - self._debug['search_range']['start'] = self._io.pos() - self.search_range = self._io.read_u2be() - self._debug['search_range']['end'] = self._io.pos() - self._debug['entry_selector']['start'] = self._io.pos() - self.entry_selector = self._io.read_u2be() - self._debug['entry_selector']['end'] = self._io.pos() - self._debug['range_shift']['start'] = self._io.pos() - self.range_shift = self._io.read_u2be() - self._debug['range_shift']['end'] = self._io.pos() - self._debug['end_count']['start'] = self._io.pos() - self.end_count = [None] * (self.seg_count) - for i in range(self.seg_count): - if not 'arr' in self._debug['end_count']: - self._debug['end_count']['arr'] = [] - self._debug['end_count']['arr'].append({'start': self._io.pos()}) - self.end_count[i] = self._io.read_u2be() - self._debug['end_count']['arr'][i]['end'] = self._io.pos() - - self._debug['end_count']['end'] = self._io.pos() - self._debug['reserved_pad']['start'] = self._io.pos() - self.reserved_pad = self._io.read_u2be() - self._debug['reserved_pad']['end'] = self._io.pos() - self._debug['start_count']['start'] = self._io.pos() - self.start_count = [None] * (self.seg_count) - for i in range(self.seg_count): - if not 'arr' in self._debug['start_count']: - self._debug['start_count']['arr'] = [] - self._debug['start_count']['arr'].append({'start': self._io.pos()}) - self.start_count[i] = self._io.read_u2be() - self._debug['start_count']['arr'][i]['end'] = self._io.pos() - - self._debug['start_count']['end'] = self._io.pos() - self._debug['id_delta']['start'] = self._io.pos() - self.id_delta = [None] * (self.seg_count) - for i in range(self.seg_count): - if not 'arr' in self._debug['id_delta']: - self._debug['id_delta']['arr'] = [] - self._debug['id_delta']['arr'].append({'start': self._io.pos()}) - self.id_delta[i] = self._io.read_u2be() - self._debug['id_delta']['arr'][i]['end'] = self._io.pos() - - self._debug['id_delta']['end'] = self._io.pos() - self._debug['id_range_offset']['start'] = self._io.pos() - self.id_range_offset = [None] * (self.seg_count) - for i in range(self.seg_count): - if not 'arr' in self._debug['id_range_offset']: - self._debug['id_range_offset']['arr'] = [] - self._debug['id_range_offset']['arr'].append({'start': self._io.pos()}) - self.id_range_offset[i] = self._io.read_u2be() - self._debug['id_range_offset']['arr'][i]['end'] = self._io.pos() - - self._debug['id_range_offset']['end'] = self._io.pos() - self._debug['glyph_id_array']['start'] = self._io.pos() - self.glyph_id_array = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['glyph_id_array']: - self._debug['glyph_id_array']['arr'] = [] - self._debug['glyph_id_array']['arr'].append({'start': self._io.pos()}) - self.glyph_id_array.append(self._io.read_u2be()) - self._debug['glyph_id_array']['arr'][len(self.glyph_id_array) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['glyph_id_array']['end'] = self._io.pos() - - @property - def seg_count(self): - if hasattr(self, '_m_seg_count'): - return self._m_seg_count if hasattr(self, '_m_seg_count') else None - - self._m_seg_count = self.seg_count_x2 // 2 - return self._m_seg_count if hasattr(self, '_m_seg_count') else None - - - class TrimmedTableMapping(KaitaiStruct): - SEQ_FIELDS = ["first_code", "entry_count", "glyph_id_array"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['first_code']['start'] = self._io.pos() - self.first_code = self._io.read_u2be() - self._debug['first_code']['end'] = self._io.pos() - self._debug['entry_count']['start'] = self._io.pos() - self.entry_count = self._io.read_u2be() - self._debug['entry_count']['end'] = self._io.pos() - self._debug['glyph_id_array']['start'] = self._io.pos() - self.glyph_id_array = [None] * (self.entry_count) - for i in range(self.entry_count): - if not 'arr' in self._debug['glyph_id_array']: - self._debug['glyph_id_array']['arr'] = [] - self._debug['glyph_id_array']['arr'].append({'start': self._io.pos()}) - self.glyph_id_array[i] = self._io.read_u2be() - self._debug['glyph_id_array']['arr'][i]['end'] = self._io.pos() - - self._debug['glyph_id_array']['end'] = self._io.pos() - - - - - diff --git a/python/examples/kaitai/udp_datagram.py b/python/examples/kaitai/udp_datagram.py deleted file mode 100644 index fcaadffa..00000000 --- a/python/examples/kaitai/udp_datagram.py +++ /dev/null @@ -1,41 +0,0 @@ -# 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 -import collections - - -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 UdpDatagram(KaitaiStruct): - """UDP is a simple stateless transport layer (AKA OSI layer 4) - protocol, one of the core Internet protocols. It provides source and - destination ports, basic checksumming, but provides not guarantees - of delivery, order of packets, or duplicate delivery. - """ - SEQ_FIELDS = ["src_port", "dst_port", "length", "checksum", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['src_port']['start'] = self._io.pos() - self.src_port = self._io.read_u2be() - self._debug['src_port']['end'] = self._io.pos() - self._debug['dst_port']['start'] = self._io.pos() - self.dst_port = self._io.read_u2be() - self._debug['dst_port']['end'] = self._io.pos() - self._debug['length']['start'] = self._io.pos() - self.length = self._io.read_u2be() - self._debug['length']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2be() - self._debug['checksum']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes_full() - self._debug['body']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/uimage.py b/python/examples/kaitai/uimage.py deleted file mode 100644 index 8d588ae9..00000000 --- a/python/examples/kaitai/uimage.py +++ /dev/null @@ -1,148 +0,0 @@ -# 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 -import collections - - -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 Uimage(KaitaiStruct): - """The new uImage format allows more flexibility in handling images of various - types (kernel, ramdisk, etc.), it also enhances integrity protection of images - with sha1 and md5 checksums. - - .. seealso:: - Source - https://github.com/EmcraftSystems/u-boot/blob/master/include/image.h - """ - - class UimageOs(Enum): - invalid = 0 - openbsd = 1 - netbsd = 2 - freebsd = 3 - bsd4_4 = 4 - linux = 5 - svr4 = 6 - esix = 7 - solaris = 8 - irix = 9 - sco = 10 - dell = 11 - ncr = 12 - lynxos = 13 - vxworks = 14 - psos = 15 - qnx = 16 - u_boot = 17 - rtems = 18 - artos = 19 - unity = 20 - integrity = 21 - - class UimageArch(Enum): - invalid = 0 - alpha = 1 - arm = 2 - i386 = 3 - ia64 = 4 - mips = 5 - mips64 = 6 - ppc = 7 - s390 = 8 - sh = 9 - sparc = 10 - sparc64 = 11 - m68k = 12 - nios = 13 - microblaze = 14 - nios2 = 15 - blackfin = 16 - avr32 = 17 - st200 = 18 - - class UimageComp(Enum): - none = 0 - gzip = 1 - bzip2 = 2 - lzma = 3 - lzo = 4 - - class UimageType(Enum): - invalid = 0 - standalone = 1 - kernel = 2 - ramdisk = 3 - multi = 4 - firmware = 5 - script = 6 - filesystem = 7 - flatdt = 8 - kwbimage = 9 - imximage = 10 - SEQ_FIELDS = ["header", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Uheader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self.header.len_image) - self._debug['data']['end'] = self._io.pos() - - class Uheader(KaitaiStruct): - SEQ_FIELDS = ["magic", "header_crc", "timestamp", "len_image", "load_address", "entry_address", "data_crc", "os_type", "architecture", "image_type", "compression_type", "name"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x27\x05\x19\x56") - self._debug['magic']['end'] = self._io.pos() - self._debug['header_crc']['start'] = self._io.pos() - self.header_crc = self._io.read_u4be() - self._debug['header_crc']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4be() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['len_image']['start'] = self._io.pos() - self.len_image = self._io.read_u4be() - self._debug['len_image']['end'] = self._io.pos() - self._debug['load_address']['start'] = self._io.pos() - self.load_address = self._io.read_u4be() - self._debug['load_address']['end'] = self._io.pos() - self._debug['entry_address']['start'] = self._io.pos() - self.entry_address = self._io.read_u4be() - self._debug['entry_address']['end'] = self._io.pos() - self._debug['data_crc']['start'] = self._io.pos() - self.data_crc = self._io.read_u4be() - self._debug['data_crc']['end'] = self._io.pos() - self._debug['os_type']['start'] = self._io.pos() - self.os_type = KaitaiStream.resolve_enum(self._root.UimageOs, self._io.read_u1()) - self._debug['os_type']['end'] = self._io.pos() - self._debug['architecture']['start'] = self._io.pos() - self.architecture = KaitaiStream.resolve_enum(self._root.UimageArch, self._io.read_u1()) - self._debug['architecture']['end'] = self._io.pos() - self._debug['image_type']['start'] = self._io.pos() - self.image_type = KaitaiStream.resolve_enum(self._root.UimageType, self._io.read_u1()) - self._debug['image_type']['end'] = self._io.pos() - self._debug['compression_type']['start'] = self._io.pos() - self.compression_type = KaitaiStream.resolve_enum(self._root.UimageComp, self._io.read_u1()) - self._debug['compression_type']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = (KaitaiStream.bytes_terminate(self._io.read_bytes(32), 0, False)).decode(u"UTF-8") - self._debug['name']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/vdi.py b/python/examples/kaitai/vdi.py deleted file mode 100644 index 211c2708..00000000 --- a/python/examples/kaitai/vdi.py +++ /dev/null @@ -1,458 +0,0 @@ -# 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 -import collections - - -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 Vdi(KaitaiStruct): - """A native VirtualBox file format - Images for testing can be downloaded from - * https://www.osboxes.org/virtualbox-images/ - * https://virtualboxes.org/images/ - * https://virtualboximages.com/ - or you can convert images of other formats. - - .. seealso:: - Source - https://github.com/qemu/qemu/blob/master/block/vdi.c - """ - - class ImageType(Enum): - dynamic = 1 - static = 2 - undo = 3 - diff = 4 - SEQ_FIELDS = ["header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["text", "signature", "version", "header_size_optional", "header_main"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['text']['start'] = self._io.pos() - self.text = (self._io.read_bytes(64)).decode(u"utf-8") - self._debug['text']['end'] = self._io.pos() - self._debug['signature']['start'] = self._io.pos() - self.signature = self._io.ensure_fixed_contents(b"\x7F\x10\xDA\xBE") - self._debug['signature']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._root.Header.Version(self._io, self, self._root) - self.version._read() - self._debug['version']['end'] = self._io.pos() - if self.subheader_size_is_dynamic: - self._debug['header_size_optional']['start'] = self._io.pos() - self.header_size_optional = self._io.read_u4le() - self._debug['header_size_optional']['end'] = self._io.pos() - - self._debug['header_main']['start'] = self._io.pos() - self._raw_header_main = self._io.read_bytes(self.header_size) - io = KaitaiStream(BytesIO(self._raw_header_main)) - self.header_main = self._root.Header.HeaderMain(io, self, self._root) - self.header_main._read() - self._debug['header_main']['end'] = self._io.pos() - - class Uuid(KaitaiStruct): - SEQ_FIELDS = ["uuid"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['uuid']['start'] = self._io.pos() - self.uuid = self._io.read_bytes(16) - self._debug['uuid']['end'] = self._io.pos() - - - class Version(KaitaiStruct): - SEQ_FIELDS = ["major", "minor"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['major']['start'] = self._io.pos() - self.major = self._io.read_u2le() - self._debug['major']['end'] = self._io.pos() - self._debug['minor']['start'] = self._io.pos() - self.minor = self._io.read_u2le() - self._debug['minor']['end'] = self._io.pos() - - - class HeaderMain(KaitaiStruct): - SEQ_FIELDS = ["image_type", "image_flags", "description", "blocks_map_offset", "offset_data", "geometry", "reserved1", "disk_size", "block_data_size", "block_metadata_size", "blocks_in_image", "blocks_allocated", "uuid_image", "uuid_last_snap", "uuid_link", "uuid_parent", "lchc_geometry"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['image_type']['start'] = self._io.pos() - self.image_type = KaitaiStream.resolve_enum(self._root.ImageType, self._io.read_u4le()) - self._debug['image_type']['end'] = self._io.pos() - self._debug['image_flags']['start'] = self._io.pos() - self.image_flags = self._root.Header.HeaderMain.Flags(self._io, self, self._root) - self.image_flags._read() - self._debug['image_flags']['end'] = self._io.pos() - self._debug['description']['start'] = self._io.pos() - self.description = (self._io.read_bytes(256)).decode(u"utf-8") - self._debug['description']['end'] = self._io.pos() - if self._parent.version.major >= 1: - self._debug['blocks_map_offset']['start'] = self._io.pos() - self.blocks_map_offset = self._io.read_u4le() - self._debug['blocks_map_offset']['end'] = self._io.pos() - - if self._parent.version.major >= 1: - self._debug['offset_data']['start'] = self._io.pos() - self.offset_data = self._io.read_u4le() - self._debug['offset_data']['end'] = self._io.pos() - - self._debug['geometry']['start'] = self._io.pos() - self.geometry = self._root.Header.HeaderMain.Geometry(self._io, self, self._root) - self.geometry._read() - self._debug['geometry']['end'] = self._io.pos() - if self._parent.version.major >= 1: - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_u4le() - self._debug['reserved1']['end'] = self._io.pos() - - self._debug['disk_size']['start'] = self._io.pos() - self.disk_size = self._io.read_u8le() - self._debug['disk_size']['end'] = self._io.pos() - self._debug['block_data_size']['start'] = self._io.pos() - self.block_data_size = self._io.read_u4le() - self._debug['block_data_size']['end'] = self._io.pos() - if self._parent.version.major >= 1: - self._debug['block_metadata_size']['start'] = self._io.pos() - self.block_metadata_size = self._io.read_u4le() - self._debug['block_metadata_size']['end'] = self._io.pos() - - self._debug['blocks_in_image']['start'] = self._io.pos() - self.blocks_in_image = self._io.read_u4le() - self._debug['blocks_in_image']['end'] = self._io.pos() - self._debug['blocks_allocated']['start'] = self._io.pos() - self.blocks_allocated = self._io.read_u4le() - self._debug['blocks_allocated']['end'] = self._io.pos() - self._debug['uuid_image']['start'] = self._io.pos() - self.uuid_image = self._root.Header.Uuid(self._io, self, self._root) - self.uuid_image._read() - self._debug['uuid_image']['end'] = self._io.pos() - self._debug['uuid_last_snap']['start'] = self._io.pos() - self.uuid_last_snap = self._root.Header.Uuid(self._io, self, self._root) - self.uuid_last_snap._read() - self._debug['uuid_last_snap']['end'] = self._io.pos() - self._debug['uuid_link']['start'] = self._io.pos() - self.uuid_link = self._root.Header.Uuid(self._io, self, self._root) - self.uuid_link._read() - self._debug['uuid_link']['end'] = self._io.pos() - if self._parent.version.major >= 1: - self._debug['uuid_parent']['start'] = self._io.pos() - self.uuid_parent = self._root.Header.Uuid(self._io, self, self._root) - self.uuid_parent._read() - self._debug['uuid_parent']['end'] = self._io.pos() - - if ((self._parent.version.major >= 1) and ((self._io.pos() + 16) <= self._io.size())) : - self._debug['lchc_geometry']['start'] = self._io.pos() - self.lchc_geometry = self._root.Header.HeaderMain.Geometry(self._io, self, self._root) - self.lchc_geometry._read() - self._debug['lchc_geometry']['end'] = self._io.pos() - - - class Geometry(KaitaiStruct): - SEQ_FIELDS = ["cylinders", "heads", "sectors", "sector_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cylinders']['start'] = self._io.pos() - self.cylinders = self._io.read_u4le() - self._debug['cylinders']['end'] = self._io.pos() - self._debug['heads']['start'] = self._io.pos() - self.heads = self._io.read_u4le() - self._debug['heads']['end'] = self._io.pos() - self._debug['sectors']['start'] = self._io.pos() - self.sectors = self._io.read_u4le() - self._debug['sectors']['end'] = self._io.pos() - self._debug['sector_size']['start'] = self._io.pos() - self.sector_size = self._io.read_u4le() - self._debug['sector_size']['end'] = self._io.pos() - - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["reserved0", "zero_expand", "reserved1", "diff", "fixed", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved0']['start'] = self._io.pos() - self.reserved0 = self._io.read_bits_int(15) - self._debug['reserved0']['end'] = self._io.pos() - self._debug['zero_expand']['start'] = self._io.pos() - self.zero_expand = self._io.read_bits_int(1) != 0 - self._debug['zero_expand']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(6) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['diff']['start'] = self._io.pos() - self.diff = self._io.read_bits_int(1) != 0 - self._debug['diff']['end'] = self._io.pos() - self._debug['fixed']['start'] = self._io.pos() - self.fixed = self._io.read_bits_int(1) != 0 - self._debug['fixed']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(8) - self._debug['reserved2']['end'] = self._io.pos() - - - - @property - def header_size(self): - if hasattr(self, '_m_header_size'): - return self._m_header_size if hasattr(self, '_m_header_size') else None - - self._m_header_size = (self.header_size_optional if self.subheader_size_is_dynamic else 336) - return self._m_header_size if hasattr(self, '_m_header_size') else None - - @property - def blocks_map_offset(self): - if hasattr(self, '_m_blocks_map_offset'): - return self._m_blocks_map_offset if hasattr(self, '_m_blocks_map_offset') else None - - self._m_blocks_map_offset = self.header_main.blocks_map_offset - return self._m_blocks_map_offset if hasattr(self, '_m_blocks_map_offset') else None - - @property - def subheader_size_is_dynamic(self): - if hasattr(self, '_m_subheader_size_is_dynamic'): - return self._m_subheader_size_is_dynamic if hasattr(self, '_m_subheader_size_is_dynamic') else None - - self._m_subheader_size_is_dynamic = self.version.major >= 1 - return self._m_subheader_size_is_dynamic if hasattr(self, '_m_subheader_size_is_dynamic') else None - - @property - def blocks_offset(self): - if hasattr(self, '_m_blocks_offset'): - return self._m_blocks_offset if hasattr(self, '_m_blocks_offset') else None - - self._m_blocks_offset = self.header_main.offset_data - return self._m_blocks_offset if hasattr(self, '_m_blocks_offset') else None - - @property - def block_size(self): - if hasattr(self, '_m_block_size'): - return self._m_block_size if hasattr(self, '_m_block_size') else None - - self._m_block_size = (self.header_main.block_metadata_size + self.header_main.block_data_size) - return self._m_block_size if hasattr(self, '_m_block_size') else None - - @property - def blocks_map_size(self): - if hasattr(self, '_m_blocks_map_size'): - return self._m_blocks_map_size if hasattr(self, '_m_blocks_map_size') else None - - self._m_blocks_map_size = ((((self.header_main.blocks_in_image * 4) + self.header_main.geometry.sector_size) - 1) // self.header_main.geometry.sector_size * self.header_main.geometry.sector_size) - return self._m_blocks_map_size if hasattr(self, '_m_blocks_map_size') else None - - - class BlocksMap(KaitaiStruct): - SEQ_FIELDS = ["index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['index']['start'] = self._io.pos() - self.index = [None] * (self._root.header.header_main.blocks_in_image) - for i in range(self._root.header.header_main.blocks_in_image): - if not 'arr' in self._debug['index']: - self._debug['index']['arr'] = [] - self._debug['index']['arr'].append({'start': self._io.pos()}) - _t_index = self._root.BlocksMap.BlockIndex(self._io, self, self._root) - _t_index._read() - self.index[i] = _t_index - self._debug['index']['arr'][i]['end'] = self._io.pos() - - self._debug['index']['end'] = self._io.pos() - - class BlockIndex(KaitaiStruct): - SEQ_FIELDS = ["index"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['index']['start'] = self._io.pos() - self.index = self._io.read_u4le() - self._debug['index']['end'] = self._io.pos() - - @property - def is_allocated(self): - if hasattr(self, '_m_is_allocated'): - return self._m_is_allocated if hasattr(self, '_m_is_allocated') else None - - self._m_is_allocated = self.index < self._root.block_discarded - return self._m_is_allocated if hasattr(self, '_m_is_allocated') else None - - @property - def block(self): - if hasattr(self, '_m_block'): - return self._m_block if hasattr(self, '_m_block') else None - - if self.is_allocated: - self._m_block = self._root.disk.blocks[self.index] - - return self._m_block if hasattr(self, '_m_block') else None - - - - class Disk(KaitaiStruct): - SEQ_FIELDS = ["blocks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['blocks']['start'] = self._io.pos() - self.blocks = [None] * (self._root.header.header_main.blocks_in_image) - for i in range(self._root.header.header_main.blocks_in_image): - if not 'arr' in self._debug['blocks']: - self._debug['blocks']['arr'] = [] - self._debug['blocks']['arr'].append({'start': self._io.pos()}) - _t_blocks = self._root.Disk.Block(self._io, self, self._root) - _t_blocks._read() - self.blocks[i] = _t_blocks - self._debug['blocks']['arr'][i]['end'] = self._io.pos() - - self._debug['blocks']['end'] = self._io.pos() - - class Block(KaitaiStruct): - SEQ_FIELDS = ["metadata", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['metadata']['start'] = self._io.pos() - self.metadata = self._io.read_bytes(self._root.header.header_main.block_metadata_size) - self._debug['metadata']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - self._raw_data = [] - self.data = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['data']: - self._debug['data']['arr'] = [] - self._debug['data']['arr'].append({'start': self._io.pos()}) - self._raw_data.append(self._io.read_bytes(self._root.header.header_main.block_data_size)) - io = KaitaiStream(BytesIO(self._raw_data[-1])) - _t_data = self._root.Disk.Block.Sector(io, self, self._root) - _t_data._read() - self.data.append(_t_data) - self._debug['data']['arr'][len(self.data) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['data']['end'] = self._io.pos() - - class Sector(KaitaiStruct): - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes(self._root.header.header_main.geometry.sector_size) - self._debug['data']['end'] = self._io.pos() - - - - - @property - def block_discarded(self): - if hasattr(self, '_m_block_discarded'): - return self._m_block_discarded if hasattr(self, '_m_block_discarded') else None - - self._m_block_discarded = 4294967294 - return self._m_block_discarded if hasattr(self, '_m_block_discarded') else None - - @property - def block_unallocated(self): - if hasattr(self, '_m_block_unallocated'): - return self._m_block_unallocated if hasattr(self, '_m_block_unallocated') else None - - self._m_block_unallocated = 4294967295 - return self._m_block_unallocated if hasattr(self, '_m_block_unallocated') else None - - @property - def blocks_map(self): - """block_index = offset_in_virtual_disk / block_size actual_data_offset = blocks_map[block_index]*block_size+metadata_size+offset_in_block - The blocks_map will take up blocks_in_image_max * sizeof(uint32_t) bytes; since the blocks_map is read and written in a single operation, its size needs to be limited to INT_MAX; furthermore, when opening an image, the blocks_map size is rounded up to be aligned on BDRV_SECTOR_SIZE. Therefore this should satisfy the following: blocks_in_image_max * sizeof(uint32_t) + BDRV_SECTOR_SIZE == INT_MAX + 1 (INT_MAX + 1 is the first value not representable as an int) This guarantees that any value below or equal to the constant will, when multiplied by sizeof(uint32_t) and rounded up to a BDRV_SECTOR_SIZE boundary, still be below or equal to INT_MAX. - """ - if hasattr(self, '_m_blocks_map'): - return self._m_blocks_map if hasattr(self, '_m_blocks_map') else None - - _pos = self._io.pos() - self._io.seek(self.header.blocks_map_offset) - self._debug['_m_blocks_map']['start'] = self._io.pos() - self._raw__m_blocks_map = self._io.read_bytes(self.header.blocks_map_size) - io = KaitaiStream(BytesIO(self._raw__m_blocks_map)) - self._m_blocks_map = self._root.BlocksMap(io, self, self._root) - self._m_blocks_map._read() - self._debug['_m_blocks_map']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_blocks_map if hasattr(self, '_m_blocks_map') else None - - @property - def disk(self): - if hasattr(self, '_m_disk'): - return self._m_disk if hasattr(self, '_m_disk') else None - - _pos = self._io.pos() - self._io.seek(self.header.blocks_offset) - self._debug['_m_disk']['start'] = self._io.pos() - self._m_disk = self._root.Disk(self._io, self, self._root) - self._m_disk._read() - self._debug['_m_disk']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_disk if hasattr(self, '_m_disk') else None - - diff --git a/python/examples/kaitai/vfat.py b/python/examples/kaitai/vfat.py deleted file mode 100644 index ff6b2cbb..00000000 --- a/python/examples/kaitai/vfat.py +++ /dev/null @@ -1,359 +0,0 @@ -# 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 -import collections - - -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 Vfat(KaitaiStruct): - SEQ_FIELDS = ["boot_sector"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['boot_sector']['start'] = self._io.pos() - self.boot_sector = self._root.BootSector(self._io, self, self._root) - self.boot_sector._read() - self._debug['boot_sector']['end'] = self._io.pos() - - class ExtBiosParamBlockFat32(KaitaiStruct): - """Extended BIOS Parameter Block for FAT32.""" - SEQ_FIELDS = ["ls_per_fat", "has_active_fat", "reserved1", "active_fat_id", "reserved2", "fat_version", "root_dir_start_clus", "ls_fs_info", "boot_sectors_copy_start_ls", "reserved3", "phys_drive_num", "reserved4", "ext_boot_sign", "volume_id", "partition_volume_label", "fs_type_str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['ls_per_fat']['start'] = self._io.pos() - self.ls_per_fat = self._io.read_u4le() - self._debug['ls_per_fat']['end'] = self._io.pos() - self._debug['has_active_fat']['start'] = self._io.pos() - self.has_active_fat = self._io.read_bits_int(1) != 0 - self._debug['has_active_fat']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(3) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['active_fat_id']['start'] = self._io.pos() - self.active_fat_id = self._io.read_bits_int(4) - self._debug['active_fat_id']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.ensure_fixed_contents(b"\x00") - self._debug['reserved2']['end'] = self._io.pos() - self._debug['fat_version']['start'] = self._io.pos() - self.fat_version = self._io.read_u2le() - self._debug['fat_version']['end'] = self._io.pos() - self._debug['root_dir_start_clus']['start'] = self._io.pos() - self.root_dir_start_clus = self._io.read_u4le() - self._debug['root_dir_start_clus']['end'] = self._io.pos() - self._debug['ls_fs_info']['start'] = self._io.pos() - self.ls_fs_info = self._io.read_u2le() - self._debug['ls_fs_info']['end'] = self._io.pos() - self._debug['boot_sectors_copy_start_ls']['start'] = self._io.pos() - self.boot_sectors_copy_start_ls = self._io.read_u2le() - self._debug['boot_sectors_copy_start_ls']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_bytes(12) - self._debug['reserved3']['end'] = self._io.pos() - self._debug['phys_drive_num']['start'] = self._io.pos() - self.phys_drive_num = self._io.read_u1() - self._debug['phys_drive_num']['end'] = self._io.pos() - self._debug['reserved4']['start'] = self._io.pos() - self.reserved4 = self._io.read_u1() - self._debug['reserved4']['end'] = self._io.pos() - self._debug['ext_boot_sign']['start'] = self._io.pos() - self.ext_boot_sign = self._io.read_u1() - self._debug['ext_boot_sign']['end'] = self._io.pos() - self._debug['volume_id']['start'] = self._io.pos() - self.volume_id = self._io.read_bytes(4) - self._debug['volume_id']['end'] = self._io.pos() - self._debug['partition_volume_label']['start'] = self._io.pos() - self.partition_volume_label = (KaitaiStream.bytes_strip_right(self._io.read_bytes(11), 32)).decode(u"ASCII") - self._debug['partition_volume_label']['end'] = self._io.pos() - self._debug['fs_type_str']['start'] = self._io.pos() - self.fs_type_str = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 32)).decode(u"ASCII") - self._debug['fs_type_str']['end'] = self._io.pos() - - - class BootSector(KaitaiStruct): - SEQ_FIELDS = ["jmp_instruction", "oem_name", "bpb", "ebpb_fat16", "ebpb_fat32"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['jmp_instruction']['start'] = self._io.pos() - self.jmp_instruction = self._io.read_bytes(3) - self._debug['jmp_instruction']['end'] = self._io.pos() - self._debug['oem_name']['start'] = self._io.pos() - self.oem_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 32)).decode(u"ASCII") - self._debug['oem_name']['end'] = self._io.pos() - self._debug['bpb']['start'] = self._io.pos() - self.bpb = self._root.BiosParamBlock(self._io, self, self._root) - self.bpb._read() - self._debug['bpb']['end'] = self._io.pos() - if not (self.is_fat32): - self._debug['ebpb_fat16']['start'] = self._io.pos() - self.ebpb_fat16 = self._root.ExtBiosParamBlockFat16(self._io, self, self._root) - self.ebpb_fat16._read() - self._debug['ebpb_fat16']['end'] = self._io.pos() - - if self.is_fat32: - self._debug['ebpb_fat32']['start'] = self._io.pos() - self.ebpb_fat32 = self._root.ExtBiosParamBlockFat32(self._io, self, self._root) - self.ebpb_fat32._read() - self._debug['ebpb_fat32']['end'] = self._io.pos() - - - @property - def pos_fats(self): - """Offset of FATs in bytes from start of filesystem.""" - if hasattr(self, '_m_pos_fats'): - return self._m_pos_fats if hasattr(self, '_m_pos_fats') else None - - self._m_pos_fats = (self.bpb.bytes_per_ls * self.bpb.num_reserved_ls) - return self._m_pos_fats if hasattr(self, '_m_pos_fats') else None - - @property - def ls_per_fat(self): - if hasattr(self, '_m_ls_per_fat'): - return self._m_ls_per_fat if hasattr(self, '_m_ls_per_fat') else None - - self._m_ls_per_fat = (self.ebpb_fat32.ls_per_fat if self.is_fat32 else self.bpb.ls_per_fat) - return self._m_ls_per_fat if hasattr(self, '_m_ls_per_fat') else None - - @property - def ls_per_root_dir(self): - """Size of root directory in logical sectors. - - .. seealso:: - FAT: General Overview of On-Disk Format, section "FAT Data Structure" - """ - if hasattr(self, '_m_ls_per_root_dir'): - return self._m_ls_per_root_dir if hasattr(self, '_m_ls_per_root_dir') else None - - self._m_ls_per_root_dir = (((self.bpb.max_root_dir_rec * 32) + self.bpb.bytes_per_ls) - 1) // self.bpb.bytes_per_ls - return self._m_ls_per_root_dir if hasattr(self, '_m_ls_per_root_dir') else None - - @property - def is_fat32(self): - """Determines if filesystem is FAT32 (true) or FAT12/16 (false) - by analyzing some preliminary conditions in BPB. Used to - determine whether we should parse post-BPB data as - `ext_bios_param_block_fat16` or `ext_bios_param_block_fat32`. - """ - if hasattr(self, '_m_is_fat32'): - return self._m_is_fat32 if hasattr(self, '_m_is_fat32') else None - - self._m_is_fat32 = self.bpb.max_root_dir_rec == 0 - return self._m_is_fat32 if hasattr(self, '_m_is_fat32') else None - - @property - def size_fat(self): - """Size of one FAT in bytes.""" - if hasattr(self, '_m_size_fat'): - return self._m_size_fat if hasattr(self, '_m_size_fat') else None - - self._m_size_fat = (self.bpb.bytes_per_ls * self.ls_per_fat) - return self._m_size_fat if hasattr(self, '_m_size_fat') else None - - @property - def pos_root_dir(self): - """Offset of root directory in bytes from start of filesystem.""" - if hasattr(self, '_m_pos_root_dir'): - return self._m_pos_root_dir if hasattr(self, '_m_pos_root_dir') else None - - self._m_pos_root_dir = (self.bpb.bytes_per_ls * (self.bpb.num_reserved_ls + (self.ls_per_fat * self.bpb.num_fats))) - return self._m_pos_root_dir if hasattr(self, '_m_pos_root_dir') else None - - @property - def size_root_dir(self): - """Size of root directory in bytes.""" - if hasattr(self, '_m_size_root_dir'): - return self._m_size_root_dir if hasattr(self, '_m_size_root_dir') else None - - self._m_size_root_dir = (self.ls_per_root_dir * self.bpb.bytes_per_ls) - return self._m_size_root_dir if hasattr(self, '_m_size_root_dir') else None - - - class BiosParamBlock(KaitaiStruct): - SEQ_FIELDS = ["bytes_per_ls", "ls_per_clus", "num_reserved_ls", "num_fats", "max_root_dir_rec", "total_ls_2", "media_code", "ls_per_fat", "ps_per_track", "num_heads", "num_hidden_sectors", "total_ls_4"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bytes_per_ls']['start'] = self._io.pos() - self.bytes_per_ls = self._io.read_u2le() - self._debug['bytes_per_ls']['end'] = self._io.pos() - self._debug['ls_per_clus']['start'] = self._io.pos() - self.ls_per_clus = self._io.read_u1() - self._debug['ls_per_clus']['end'] = self._io.pos() - self._debug['num_reserved_ls']['start'] = self._io.pos() - self.num_reserved_ls = self._io.read_u2le() - self._debug['num_reserved_ls']['end'] = self._io.pos() - self._debug['num_fats']['start'] = self._io.pos() - self.num_fats = self._io.read_u1() - self._debug['num_fats']['end'] = self._io.pos() - self._debug['max_root_dir_rec']['start'] = self._io.pos() - self.max_root_dir_rec = self._io.read_u2le() - self._debug['max_root_dir_rec']['end'] = self._io.pos() - self._debug['total_ls_2']['start'] = self._io.pos() - self.total_ls_2 = self._io.read_u2le() - self._debug['total_ls_2']['end'] = self._io.pos() - self._debug['media_code']['start'] = self._io.pos() - self.media_code = self._io.read_u1() - self._debug['media_code']['end'] = self._io.pos() - self._debug['ls_per_fat']['start'] = self._io.pos() - self.ls_per_fat = self._io.read_u2le() - self._debug['ls_per_fat']['end'] = self._io.pos() - self._debug['ps_per_track']['start'] = self._io.pos() - self.ps_per_track = self._io.read_u2le() - self._debug['ps_per_track']['end'] = self._io.pos() - self._debug['num_heads']['start'] = self._io.pos() - self.num_heads = self._io.read_u2le() - self._debug['num_heads']['end'] = self._io.pos() - self._debug['num_hidden_sectors']['start'] = self._io.pos() - self.num_hidden_sectors = self._io.read_u4le() - self._debug['num_hidden_sectors']['end'] = self._io.pos() - self._debug['total_ls_4']['start'] = self._io.pos() - self.total_ls_4 = self._io.read_u4le() - self._debug['total_ls_4']['end'] = self._io.pos() - - - class RootDirectoryRec(KaitaiStruct): - SEQ_FIELDS = ["file_name", "attribute", "reserved", "time", "date", "start_clus", "file_size"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_name']['start'] = self._io.pos() - self.file_name = self._io.read_bytes(11) - self._debug['file_name']['end'] = self._io.pos() - self._debug['attribute']['start'] = self._io.pos() - self.attribute = self._io.read_u1() - self._debug['attribute']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(10) - self._debug['reserved']['end'] = self._io.pos() - self._debug['time']['start'] = self._io.pos() - self.time = self._io.read_u2le() - self._debug['time']['end'] = self._io.pos() - self._debug['date']['start'] = self._io.pos() - self.date = self._io.read_u2le() - self._debug['date']['end'] = self._io.pos() - self._debug['start_clus']['start'] = self._io.pos() - self.start_clus = self._io.read_u2le() - self._debug['start_clus']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u4le() - self._debug['file_size']['end'] = self._io.pos() - - - class RootDirectory(KaitaiStruct): - SEQ_FIELDS = ["records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['records']['start'] = self._io.pos() - self.records = [None] * (self._root.boot_sector.bpb.max_root_dir_rec) - for i in range(self._root.boot_sector.bpb.max_root_dir_rec): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.RootDirectoryRec(self._io, self, self._root) - _t_records._read() - self.records[i] = _t_records - self._debug['records']['arr'][i]['end'] = self._io.pos() - - self._debug['records']['end'] = self._io.pos() - - - class ExtBiosParamBlockFat16(KaitaiStruct): - """Extended BIOS Parameter Block (DOS 4.0+, OS/2 1.0+). Used only - for FAT12 and FAT16. - """ - SEQ_FIELDS = ["phys_drive_num", "reserved1", "ext_boot_sign", "volume_id", "partition_volume_label", "fs_type_str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['phys_drive_num']['start'] = self._io.pos() - self.phys_drive_num = self._io.read_u1() - self._debug['phys_drive_num']['end'] = self._io.pos() - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_u1() - self._debug['reserved1']['end'] = self._io.pos() - self._debug['ext_boot_sign']['start'] = self._io.pos() - self.ext_boot_sign = self._io.read_u1() - self._debug['ext_boot_sign']['end'] = self._io.pos() - self._debug['volume_id']['start'] = self._io.pos() - self.volume_id = self._io.read_bytes(4) - self._debug['volume_id']['end'] = self._io.pos() - self._debug['partition_volume_label']['start'] = self._io.pos() - self.partition_volume_label = (KaitaiStream.bytes_strip_right(self._io.read_bytes(11), 32)).decode(u"ASCII") - self._debug['partition_volume_label']['end'] = self._io.pos() - self._debug['fs_type_str']['start'] = self._io.pos() - self.fs_type_str = (KaitaiStream.bytes_strip_right(self._io.read_bytes(8), 32)).decode(u"ASCII") - self._debug['fs_type_str']['end'] = self._io.pos() - - - @property - def fats(self): - if hasattr(self, '_m_fats'): - return self._m_fats if hasattr(self, '_m_fats') else None - - _pos = self._io.pos() - self._io.seek(self.boot_sector.pos_fats) - self._debug['_m_fats']['start'] = self._io.pos() - self._m_fats = [None] * (self.boot_sector.bpb.num_fats) - for i in range(self.boot_sector.bpb.num_fats): - if not 'arr' in self._debug['_m_fats']: - self._debug['_m_fats']['arr'] = [] - self._debug['_m_fats']['arr'].append({'start': self._io.pos()}) - self._m_fats[i] = self._io.read_bytes(self.boot_sector.size_fat) - self._debug['_m_fats']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_fats']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_fats if hasattr(self, '_m_fats') else None - - @property - def root_dir(self): - if hasattr(self, '_m_root_dir'): - return self._m_root_dir if hasattr(self, '_m_root_dir') else None - - _pos = self._io.pos() - self._io.seek(self.boot_sector.pos_root_dir) - self._debug['_m_root_dir']['start'] = self._io.pos() - self._raw__m_root_dir = self._io.read_bytes(self.boot_sector.size_root_dir) - io = KaitaiStream(BytesIO(self._raw__m_root_dir)) - self._m_root_dir = self._root.RootDirectory(io, self, self._root) - self._m_root_dir._read() - self._debug['_m_root_dir']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_root_dir if hasattr(self, '_m_root_dir') else None - - diff --git a/python/examples/kaitai/view.py b/python/examples/kaitai/view.py deleted file mode 100644 index fa2d458f..00000000 --- a/python/examples/kaitai/view.py +++ /dev/null @@ -1,367 +0,0 @@ -# -*- coding: utf-8 -*- - -# python stuff -import io -import os -import sys -import types -import traceback - -# binja stuff -from binaryninja import log -from binaryninja import binaryview -from binaryninja.settings import Settings -from binaryninja import _binaryninjacore as core -from binaryninjaui import View, ViewType, ViewFrame, UIContext, HexEditor, getMonospaceFont - -from PySide2.QtCore import Qt -from PySide2.QtWidgets import QScrollArea, QWidget, QVBoxLayout, QGroupBox, QTreeWidget, QTreeWidgetItem, QLineEdit, QHeaderView, QSplitter - -from . import menu - -if sys.version_info[0] == 2: - import kshelpers -else: - from . import kshelpers - -class MyQTreeWidget(QTreeWidget): - def __init__(self): - QTreeWidget.__init__(self) - - self.oldWidth = 0 - self.oldHeight = 0 - - self.queueInitialPresentation = False - - def resizeEvent(self, event): - QTreeWidget.resizeEvent(self, event) - - if self.queueInitialPresentation: - self.initialPresentation() - - self.scrollTo(self.currentIndex()) - - newWidth = self.width() - newHeight = self.height() - - #log.log_debug('QTreeWidget resizeEvent(), now I\'m %dx%d' % (newWidth, newHeight)) - - if newWidth == self.oldWidth and newHeight == self.oldHeight: - return - - self.oldWidth = newWidth - self.oldHeight = newHeight - - self.setColumnWidthsNicely() - - def initialPresentation(self): - self.expandNicely() - - if self.topLevelItemCount(): - self.topLevelItem(0).setSelected(True) - - self.queueInitialPresentation = False - - def setColumnWidthsNicely(self): - width = self.width() - self.setColumnWidth(0, .6*width) - self.setColumnWidth(1, .2*width) - self.setColumnWidth(2, .1*width) - self.setColumnWidth(3, .1*width) - - def expandNicely(self): - visibleRows = self.topLevelItemCount() - if not visibleRows: - return - - height = self.height() - rowHeight = self.visualItemRect(self.topLevelItem(0)).height() - rowCapacity = height / rowHeight - - queue = [] - for i in range(visibleRows): - queue.append(self.topLevelItem(i)) - - while visibleRows < rowCapacity: - #log.log_debug('visibleRows=%d, rowCapacity=%d len(queue)=%d' % (visibleRows, rowCapacity, len(queue))) - if not queue: - break - - item = queue[0] - queue = queue[1:] - - if not item.isExpanded(): - item.setExpanded(True) - for i in range(item.childCount()): - queue.append(item.child(i)) - visibleRows += 1 - -class KaitaiView(QScrollArea, View): - def __init__(self, parent, binaryView): - QScrollArea.__init__(self, parent) - - View.__init__(self) - View.setBinaryDataNavigable(self, True) - self.setupView(self) - - # BinaryViewType - self.binaryView = binaryView - - self.rootSelectionStart = 0 - self.rootSelectionEnd = 1 - - self.ioRoot = None - self.ioCurrent = None - - # top half = treeWidget + structPath - self.treeWidget = MyQTreeWidget() - self.treeWidget.setColumnCount(4) - self.treeWidget.setHeaderLabels(['label','value','start','end']) - self.treeWidget.itemSelectionChanged.connect(self.onTreeSelect) - - self.structPath = QLineEdit("root") - self.structPath.setReadOnly(True) - - topHalf = QWidget(self) - layout = QVBoxLayout() - layout.addWidget(self.treeWidget) - layout.addWidget(self.structPath) - topHalf.setLayout(layout) - - # bottom half = hexWidget - self.hexWidget = HexEditor(binaryView, ViewFrame.viewFrameForWidget(self), 0) - - # splitter = top half, bottom half - self.splitter = QSplitter(self) - self.splitter.setOrientation(Qt.Vertical) - self.splitter.addWidget(topHalf) - self.splitter.addWidget(self.hexWidget) - - self.setWidgetResizable(True) - self.setWidget(self.splitter) - - self.kaitaiParse() - - # parse the file using Kaitai, construct the TreeWidget - def kaitaiParse(self, ksModuleName=None): - log.log_debug('kaitaiParse() with len(bv)=%d and bv.file.filename=%s' % (len(self.binaryView), self.binaryView.file.filename)) - - if len(self.binaryView) == 0: - return - - kaitaiIO = kshelpers.KaitaiBinaryViewIO(self.binaryView) - parsed = kshelpers.parseIo(kaitaiIO, ksModuleName) - if not parsed: - return - - # it SEEMS as if parsing is finished at this moment, but some parsing - # is postponed until attributes are accessed, so we must try/catch here - tree = None - if True: - try: - tree = kshelpers.buildQtree(parsed) - except Exception as e: - log.log_error('kaitai module %s threw exception, check file type' % ksModuleName) - tree = None - else: - tree = kshelpers.buildQtree(parsed) - - if not tree: - return - - self.ioRoot = tree.ksobj._io - self.ioCurrent = tree.ksobj._io - - self.treeWidget.clear() - self.treeWidget.setSortingEnabled(False) # temporarily, for efficiency - # two options with how we create the hierarchy - if False: - # treat root as top level "file" container - tree.setLabel('file') - tree.setValue(None) - tree.setStart(0) - tree.setEnd(0) - self.treeWidget.insertTopLevelItem(0, tree) - else: - # add root's children as top level items - self.treeWidget.insertTopLevelItems(0, tree.takeChildren()) - - # enable sorting - self.treeWidget.setSortingEnabled(True) - self.treeWidget.sortByColumn(2, Qt.AscendingOrder) - - # TODO: select first item, maybe expand a few things - self.rootSelectionStart = 0 - self.rootSelectionEnd = 1 - - self.treeWidget.setUniformRowHeights(True) - self.treeWidget.queueInitialPresentation = True - - - # binja callbacks - def getData(self): - return self.binaryView - - def getStart(self): - result = self.binaryView.start - #log.log_debug('getStart() returning '+str(result)) - return result - - def getEnd(self): - result = self.binaryView.end - #log.log_debug('getEnd() returning '+str(result)) - return result - - def getLength(self): - result = len(self.binaryView) - #log.log_debug('getLength() returning '+str(result)) - return result - - def getCurrentOffset(self): - result = self.rootSelectionStart + int((self.rootSelectionEnd - self.rootSelectionStart)/2) - #result = self.rootSelectionStart - #log.log_debug('getCurrentOffset() returning '+str(result)) - return result - - def getSelectionOffsets(self): - result = None - if self.hexWidget: - result = self.hexWidget.getSelectionOffsets() - else: - result = (self.rootSelectionStart, self.rootSelectionStart) - #log.log_debug('getSelectionOffsets() returning '+str(result)) - return result - - def setCurrentOffset(self, offset): - #log.log_debug('setCurrentOffset(0x%X)' % offset) - self.rootSelectionStart = offset - UIContext.updateStatus(True) - - def getFont(self): - return binaryninjaui.getMonospaceFont(self) - - def navigate(self, addr): - self.rootSelectionStart = addr - self.rootSelectionEnd = addr+1 - self.hexWidget.setSelectionRange(addr, addr+1) - return True - - def navigateToFileOffset(self, offset): - #log.log_debug('navigateToFileOffset()') - return False - - def onTreeSelect(self, wtf=None): - # get KaitaiTreeWidgetItem - items = self.treeWidget.selectedItems() - if not items or len(items)<1: - return - item = items[0] - - # build path, inform user - structPath = item.label - itemTmp = item - while itemTmp.parent(): - itemTmp = itemTmp.parent() - label = itemTmp.label - if label.startswith('_m_'): - label = label[3:] - structPath = label + '.' + structPath - self.structPath.setText('root.' + structPath) - - # - (start, end) = (item.start, item.end) - if start == None or end == None: - return - - # determine current IO we're in (the Kaitai input/output abstraction) - _io = None - # if the tree item is linked to a KaitaiNode, simply read the IO - if item.ksobj: - _io = item.ksobj._parent._io - else: - # else we're a leaf - parent = item.parent() - if parent: - # a leaf with a parent -> read parent's IO - _io = parent.ksobj._io - else: - # a leaf without a parent -> we must be at root -> use root IO - _io = self.ioRoot - - # if the selection is in the root view, store the interval so that upon - # getCurrentOffset() callback, we return the middle and feature map is - # updated - if _io == self.ioRoot: - self.rootSelectionStart = start - self.rootSelectionEnd = end - - # current kaitai object is on a different io? then swap HexEditor - if _io != self.ioCurrent: - # delete old view - self.hexWidget.hide() - self.hexWidget.setParent(None) - self.hexWidget.deleteLater() - self.hexWidget = None - - # if it's the original file IO, wrap the already-open file binary view - if _io == self.ioRoot: - self.hexWidget = HexEditor(self.binaryView, ViewFrame.viewFrameForWidget(self), 0) - # otherwise delete old view, create a temporary view - else: - # create new view - length = _io.size() - _io.seek(0) - data = _io.read_bytes(length) - bv = binaryview.BinaryView.new(data) - self.hexWidget = HexEditor(bv, ViewFrame.viewFrameForWidget(self), 0) - - self.splitter.addWidget(self.hexWidget) - self.ioCurrent = _io - - # now position selection in whatever HexEditor is current - #log.log_debug('selecting to [0x%X, 0x%X)' % (start, end)) - self.hexWidget.setSelectionRange(start, end) - - # set hex group title to reflect current selection - #self.hexGroup.setTitle('Hex View @ [0x%X, 0x%X)' % (start, end)) - - def getStatusBarWidget(self): - return menu.KaitaiStatusBarWidget(self) - -class KaitaiViewType(ViewType): - def __init__(self): - super(KaitaiViewType, self).__init__("Kaitai", "Kaitai") - - # binaryView: BinaryView - def getPriority(self, binaryView, filename): - #return 100 - #log.log_debug('len(bv)=0x%X executable=%d bytes=%s' % (len(binaryView), binaryView.executable, repr(binaryView.read(0,4)))) - - # executable means the view is mapped like an OS loader would load an executable (eg: view=ELF) - # !executable means executable image is not mapped (eg: view=Raw) (or something like .png is loaded) - if binaryView.executable: - return 0 - - if binaryView.start != 0: - return 1 - - dataSample = binaryView.read(0, 16) - if len(dataSample) != 16: - return 1 - - # if we don't recognize it, return 0 - ksModuleName = kshelpers.idData(dataSample, len(binaryView)) - if not ksModuleName: - return 1 - - # for executables, yield to triage (25) - if ksModuleName in ['elf', 'microsoft_pe', 'mach_o']: - return 24 - - # - return 100 - - def create(self, binaryView, view_frame): - return KaitaiView(view_frame, binaryView) - -ViewType.registerViewType(KaitaiViewType()) diff --git a/python/examples/kaitai/vlq_base128_be.py b/python/examples/kaitai/vlq_base128_be.py deleted file mode 100644 index 69dce835..00000000 --- a/python/examples/kaitai/vlq_base128_be.py +++ /dev/null @@ -1,102 +0,0 @@ -# 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 -import collections - - -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 VlqBase128Be(KaitaiStruct): - """A variable-length unsigned integer using base128 encoding. 1-byte groups - consist of 1-bit flag of continuation and 7-bit value chunk, and are ordered - "most significant group first", i.e. in "big-endian" manner. - - This particular encoding is specified and used in: - - * Standard MIDI file format - * ASN.1 BER encoding - - More information on this encoding is available at - https://en.wikipedia.org/wiki/Variable-length_quantity - - This particular implementation supports serialized values to up 8 bytes long. - """ - SEQ_FIELDS = ["groups"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['groups']['start'] = self._io.pos() - self.groups = [] - i = 0 - while True: - if not 'arr' in self._debug['groups']: - self._debug['groups']['arr'] = [] - self._debug['groups']['arr'].append({'start': self._io.pos()}) - _t_groups = self._root.Group(self._io, self, self._root) - _t_groups._read() - _ = _t_groups - self.groups.append(_) - self._debug['groups']['arr'][len(self.groups) - 1]['end'] = self._io.pos() - if not (_.has_next): - break - i += 1 - self._debug['groups']['end'] = self._io.pos() - - class Group(KaitaiStruct): - """One byte group, clearly divided into 7-bit "value" chunk and 1-bit "continuation" flag. - """ - SEQ_FIELDS = ["b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - - @property - def has_next(self): - """If true, then we have more bytes to read.""" - if hasattr(self, '_m_has_next'): - return self._m_has_next if hasattr(self, '_m_has_next') else None - - self._m_has_next = (self.b & 128) != 0 - return self._m_has_next if hasattr(self, '_m_has_next') else None - - @property - def value(self): - """The 7-bit (base128) numeric value chunk of this group.""" - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (self.b & 127) - return self._m_value if hasattr(self, '_m_value') else None - - - @property - def last(self): - if hasattr(self, '_m_last'): - return self._m_last if hasattr(self, '_m_last') else None - - self._m_last = (len(self.groups) - 1) - return self._m_last if hasattr(self, '_m_last') else None - - @property - def value(self): - """Resulting value as normal integer.""" - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (((((((self.groups[self.last].value + ((self.groups[(self.last - 1)].value << 7) if self.last >= 1 else 0)) + ((self.groups[(self.last - 2)].value << 14) if self.last >= 2 else 0)) + ((self.groups[(self.last - 3)].value << 21) if self.last >= 3 else 0)) + ((self.groups[(self.last - 4)].value << 28) if self.last >= 4 else 0)) + ((self.groups[(self.last - 5)].value << 35) if self.last >= 5 else 0)) + ((self.groups[(self.last - 6)].value << 42) if self.last >= 6 else 0)) + ((self.groups[(self.last - 7)].value << 49) if self.last >= 7 else 0)) - return self._m_value if hasattr(self, '_m_value') else None - - diff --git a/python/examples/kaitai/vlq_base128_le.py b/python/examples/kaitai/vlq_base128_le.py deleted file mode 100644 index 6fa8d43b..00000000 --- a/python/examples/kaitai/vlq_base128_le.py +++ /dev/null @@ -1,108 +0,0 @@ -# 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 -import collections - - -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 VlqBase128Le(KaitaiStruct): - """A variable-length unsigned integer using base128 encoding. 1-byte groups - consist of 1-bit flag of continuation and 7-bit value chunk, and are ordered - "least significant group first", i.e. in "little-endian" manner. - - This particular encoding is specified and used in: - - * DWARF debug file format, where it's dubbed "unsigned LEB128" or "ULEB128". - http://dwarfstd.org/doc/dwarf-2.0.0.pdf - page 139 - * Google Protocol Buffers, where it's called "Base 128 Varints". - https://developers.google.com/protocol-buffers/docs/encoding?csw=1#varints - * Apache Lucene, where it's called "VInt" - http://lucene.apache.org/core/3_5_0/fileformats.html#VInt - * Apache Avro uses this as a basis for integer encoding, adding ZigZag on - top of it for signed ints - http://avro.apache.org/docs/current/spec.html#binary_encode_primitive - - More information on this encoding is available at https://en.wikipedia.org/wiki/LEB128 - - This particular implementation supports serialized values to up 8 bytes long. - """ - SEQ_FIELDS = ["groups"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['groups']['start'] = self._io.pos() - self.groups = [] - i = 0 - while True: - if not 'arr' in self._debug['groups']: - self._debug['groups']['arr'] = [] - self._debug['groups']['arr'].append({'start': self._io.pos()}) - _t_groups = self._root.Group(self._io, self, self._root) - _t_groups._read() - _ = _t_groups - self.groups.append(_) - self._debug['groups']['arr'][len(self.groups) - 1]['end'] = self._io.pos() - if not (_.has_next): - break - i += 1 - self._debug['groups']['end'] = self._io.pos() - - class Group(KaitaiStruct): - """One byte group, clearly divided into 7-bit "value" chunk and 1-bit "continuation" flag. - """ - SEQ_FIELDS = ["b"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['b']['start'] = self._io.pos() - self.b = self._io.read_u1() - self._debug['b']['end'] = self._io.pos() - - @property - def has_next(self): - """If true, then we have more bytes to read.""" - if hasattr(self, '_m_has_next'): - return self._m_has_next if hasattr(self, '_m_has_next') else None - - self._m_has_next = (self.b & 128) != 0 - return self._m_has_next if hasattr(self, '_m_has_next') else None - - @property - def value(self): - """The 7-bit (base128) numeric value chunk of this group.""" - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (self.b & 127) - return self._m_value if hasattr(self, '_m_value') else None - - - @property - def len(self): - if hasattr(self, '_m_len'): - return self._m_len if hasattr(self, '_m_len') else None - - self._m_len = len(self.groups) - return self._m_len if hasattr(self, '_m_len') else None - - @property - def value(self): - """Resulting value as normal integer.""" - if hasattr(self, '_m_value'): - return self._m_value if hasattr(self, '_m_value') else None - - self._m_value = (((((((self.groups[0].value + ((self.groups[1].value << 7) if self.len >= 2 else 0)) + ((self.groups[2].value << 14) if self.len >= 3 else 0)) + ((self.groups[3].value << 21) if self.len >= 4 else 0)) + ((self.groups[4].value << 28) if self.len >= 5 else 0)) + ((self.groups[5].value << 35) if self.len >= 6 else 0)) + ((self.groups[6].value << 42) if self.len >= 7 else 0)) + ((self.groups[7].value << 49) if self.len >= 8 else 0)) - return self._m_value if hasattr(self, '_m_value') else None - - diff --git a/python/examples/kaitai/vmware_vmdk.py b/python/examples/kaitai/vmware_vmdk.py deleted file mode 100644 index 224d4c7a..00000000 --- a/python/examples/kaitai/vmware_vmdk.py +++ /dev/null @@ -1,164 +0,0 @@ -# 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 -import collections - - -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 VmwareVmdk(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/libyal/libvmdk/blob/master/documentation/VMWare%20Virtual%20Disk%20Format%20(VMDK).asciidoc#41-file-header - """ - - class CompressionMethods(Enum): - none = 0 - deflate = 1 - SEQ_FIELDS = ["magic", "version", "flags", "size_max", "size_grain", "start_descriptor", "size_descriptor", "num_grain_table_entries", "start_secondary_grain", "start_primary_grain", "size_metadata", "is_dirty", "stuff", "compression_method"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4B\x44\x4D\x56") - self._debug['magic']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_s4le() - self._debug['version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.HeaderFlags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['size_max']['start'] = self._io.pos() - self.size_max = self._io.read_s8le() - self._debug['size_max']['end'] = self._io.pos() - self._debug['size_grain']['start'] = self._io.pos() - self.size_grain = self._io.read_s8le() - self._debug['size_grain']['end'] = self._io.pos() - self._debug['start_descriptor']['start'] = self._io.pos() - self.start_descriptor = self._io.read_s8le() - self._debug['start_descriptor']['end'] = self._io.pos() - self._debug['size_descriptor']['start'] = self._io.pos() - self.size_descriptor = self._io.read_s8le() - self._debug['size_descriptor']['end'] = self._io.pos() - self._debug['num_grain_table_entries']['start'] = self._io.pos() - self.num_grain_table_entries = self._io.read_s4le() - self._debug['num_grain_table_entries']['end'] = self._io.pos() - self._debug['start_secondary_grain']['start'] = self._io.pos() - self.start_secondary_grain = self._io.read_s8le() - self._debug['start_secondary_grain']['end'] = self._io.pos() - self._debug['start_primary_grain']['start'] = self._io.pos() - self.start_primary_grain = self._io.read_s8le() - self._debug['start_primary_grain']['end'] = self._io.pos() - self._debug['size_metadata']['start'] = self._io.pos() - self.size_metadata = self._io.read_s8le() - self._debug['size_metadata']['end'] = self._io.pos() - self._debug['is_dirty']['start'] = self._io.pos() - self.is_dirty = self._io.read_u1() - self._debug['is_dirty']['end'] = self._io.pos() - self._debug['stuff']['start'] = self._io.pos() - self.stuff = self._io.read_bytes(4) - self._debug['stuff']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.CompressionMethods, self._io.read_u2le()) - self._debug['compression_method']['end'] = self._io.pos() - - class HeaderFlags(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/libyal/libvmdk/blob/master/documentation/VMWare%20Virtual%20Disk%20Format%20(VMDK).asciidoc#411-flags - """ - SEQ_FIELDS = ["reserved1", "zeroed_grain_table_entry", "use_secondary_grain_dir", "valid_new_line_detection_test", "reserved2", "reserved3", "has_metadata", "has_compressed_grain", "reserved4"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(5) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['zeroed_grain_table_entry']['start'] = self._io.pos() - self.zeroed_grain_table_entry = self._io.read_bits_int(1) != 0 - self._debug['zeroed_grain_table_entry']['end'] = self._io.pos() - self._debug['use_secondary_grain_dir']['start'] = self._io.pos() - self.use_secondary_grain_dir = self._io.read_bits_int(1) != 0 - self._debug['use_secondary_grain_dir']['end'] = self._io.pos() - self._debug['valid_new_line_detection_test']['start'] = self._io.pos() - self.valid_new_line_detection_test = self._io.read_bits_int(1) != 0 - self._debug['valid_new_line_detection_test']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_u1() - self._debug['reserved2']['end'] = self._io.pos() - self._debug['reserved3']['start'] = self._io.pos() - self.reserved3 = self._io.read_bits_int(6) - self._debug['reserved3']['end'] = self._io.pos() - self._debug['has_metadata']['start'] = self._io.pos() - self.has_metadata = self._io.read_bits_int(1) != 0 - self._debug['has_metadata']['end'] = self._io.pos() - self._debug['has_compressed_grain']['start'] = self._io.pos() - self.has_compressed_grain = self._io.read_bits_int(1) != 0 - self._debug['has_compressed_grain']['end'] = self._io.pos() - self._io.align_to_byte() - self._debug['reserved4']['start'] = self._io.pos() - self.reserved4 = self._io.read_u1() - self._debug['reserved4']['end'] = self._io.pos() - - - @property - def len_sector(self): - if hasattr(self, '_m_len_sector'): - return self._m_len_sector if hasattr(self, '_m_len_sector') else None - - self._m_len_sector = 512 - return self._m_len_sector if hasattr(self, '_m_len_sector') else None - - @property - def descriptor(self): - if hasattr(self, '_m_descriptor'): - return self._m_descriptor if hasattr(self, '_m_descriptor') else None - - _pos = self._io.pos() - self._io.seek((self.start_descriptor * self._root.len_sector)) - self._debug['_m_descriptor']['start'] = self._io.pos() - self._m_descriptor = self._io.read_bytes((self.size_descriptor * self._root.len_sector)) - self._debug['_m_descriptor']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_descriptor if hasattr(self, '_m_descriptor') else None - - @property - def grain_primary(self): - if hasattr(self, '_m_grain_primary'): - return self._m_grain_primary if hasattr(self, '_m_grain_primary') else None - - _pos = self._io.pos() - self._io.seek((self.start_primary_grain * self._root.len_sector)) - self._debug['_m_grain_primary']['start'] = self._io.pos() - self._m_grain_primary = self._io.read_bytes((self.size_grain * self._root.len_sector)) - self._debug['_m_grain_primary']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_grain_primary if hasattr(self, '_m_grain_primary') else None - - @property - def grain_secondary(self): - if hasattr(self, '_m_grain_secondary'): - return self._m_grain_secondary if hasattr(self, '_m_grain_secondary') else None - - _pos = self._io.pos() - self._io.seek((self.start_secondary_grain * self._root.len_sector)) - self._debug['_m_grain_secondary']['start'] = self._io.pos() - self._m_grain_secondary = self._io.read_bytes((self.size_grain * self._root.len_sector)) - self._debug['_m_grain_secondary']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_grain_secondary if hasattr(self, '_m_grain_secondary') else None - - diff --git a/python/examples/kaitai/vp8_ivf.py b/python/examples/kaitai/vp8_ivf.py deleted file mode 100644 index 05c19326..00000000 --- a/python/examples/kaitai/vp8_ivf.py +++ /dev/null @@ -1,107 +0,0 @@ -# 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 -import collections - - -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 Vp8Ivf(KaitaiStruct): - """IVF is a simple container format for raw VP8 data, which is an open - and royalty-free video compression format, currently developed by - Google. - - Test .ivf files are available at https://chromium.googlesource.com/webm/vp8-test-vectors - - .. seealso:: - Source - https://wiki.multimedia.cx/index.php/IVF - """ - SEQ_FIELDS = ["magic1", "version", "len_header", "codec", "width", "height", "framerate", "timescale", "num_frames", "unused", "image_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic1']['start'] = self._io.pos() - self.magic1 = self._io.ensure_fixed_contents(b"\x44\x4B\x49\x46") - self._debug['magic1']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u2le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['codec']['start'] = self._io.pos() - self.codec = self._io.ensure_fixed_contents(b"\x56\x50\x38\x30") - self._debug['codec']['end'] = self._io.pos() - self._debug['width']['start'] = self._io.pos() - self.width = self._io.read_u2le() - self._debug['width']['end'] = self._io.pos() - self._debug['height']['start'] = self._io.pos() - self.height = self._io.read_u2le() - self._debug['height']['end'] = self._io.pos() - self._debug['framerate']['start'] = self._io.pos() - self.framerate = self._io.read_u4le() - self._debug['framerate']['end'] = self._io.pos() - self._debug['timescale']['start'] = self._io.pos() - self.timescale = self._io.read_u4le() - self._debug['timescale']['end'] = self._io.pos() - self._debug['num_frames']['start'] = self._io.pos() - self.num_frames = self._io.read_u4le() - self._debug['num_frames']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_u4le() - self._debug['unused']['end'] = self._io.pos() - self._debug['image_data']['start'] = self._io.pos() - self.image_data = [None] * (self.num_frames) - for i in range(self.num_frames): - if not 'arr' in self._debug['image_data']: - self._debug['image_data']['arr'] = [] - self._debug['image_data']['arr'].append({'start': self._io.pos()}) - _t_image_data = self._root.Blocks(self._io, self, self._root) - _t_image_data._read() - self.image_data[i] = _t_image_data - self._debug['image_data']['arr'][i]['end'] = self._io.pos() - - self._debug['image_data']['end'] = self._io.pos() - - class Blocks(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entries']['start'] = self._io.pos() - self.entries = self._root.Block(self._io, self, self._root) - self.entries._read() - self._debug['entries']['end'] = self._io.pos() - - - class Block(KaitaiStruct): - SEQ_FIELDS = ["len_frame", "timestamp", "framedata"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_frame']['start'] = self._io.pos() - self.len_frame = self._io.read_u4le() - self._debug['len_frame']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u8le() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['framedata']['start'] = self._io.pos() - self.framedata = self._io.read_bytes(self.len_frame) - self._debug['framedata']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/warcraft_2_pud.py b/python/examples/kaitai/warcraft_2_pud.py deleted file mode 100644 index 760b0134..00000000 --- a/python/examples/kaitai/warcraft_2_pud.py +++ /dev/null @@ -1,420 +0,0 @@ -# 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 -import collections - - -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 Warcraft2Pud(KaitaiStruct): - """Warcraft II game engine uses this format for map files. External - maps can be edited by official Warcraft II map editor and saved in - .pud files. Maps supplied with the game (i.e. single player - campaign) follow the same format, but are instead embedded inside - the game container files. - - There are two major versions: 0x11 (original one) and 0x13 (roughly - corresponds to v1.33 of the game engine, although some of the - features got limited support in v1.3). - - File consists of a sequence of typed sections. - - .. seealso:: - Source - http://cade.datamax.bg/war2x/pudspec.html - """ - - class Controller(Enum): - computer = 1 - passive_computer = 2 - nobody = 3 - computer_ = 4 - human = 5 - rescue_passive = 6 - rescue_active = 7 - - class TerrainType(Enum): - forest = 0 - winter = 1 - wasteland = 2 - swamp = 3 - - class UnitType(Enum): - infantry = 0 - grunt = 1 - peasant = 2 - peon = 3 - ballista = 4 - catapult = 5 - knight = 6 - ogre = 7 - archer = 8 - axethrower = 9 - mage = 10 - death_knight = 11 - paladin = 12 - ogre_mage = 13 - dwarves = 14 - goblin_sapper = 15 - attack_peasant = 16 - attack_peon = 17 - ranger = 18 - berserker = 19 - alleria = 20 - teron_gorefiend = 21 - kurdan_and_sky_ree = 22 - dentarg = 23 - khadgar = 24 - grom_hellscream = 25 - human_tanker = 26 - orc_tanker = 27 - human_transport = 28 - orc_transport = 29 - elven_destroyer = 30 - troll_destroyer = 31 - battleship = 32 - juggernaught = 33 - deathwing = 35 - gnomish_submarine = 38 - giant_turtle = 39 - gnomish_flying_machine = 40 - goblin_zepplin = 41 - gryphon_rider = 42 - dragon = 43 - turalyon = 44 - eye_of_kilrogg = 45 - danath = 46 - khorgath_bladefist = 47 - cho_gall = 49 - lothar = 50 - gul_dan = 51 - uther_lightbringer = 52 - zuljin = 53 - skeleton = 55 - daemon = 56 - critter = 57 - farm = 58 - pig_farm = 59 - human_barracks = 60 - orc_barracks = 61 - church = 62 - altar_of_storms = 63 - human_scout_tower = 64 - orc_scout_tower = 65 - stables = 66 - ogre_mound = 67 - gnomish_inventor = 68 - goblin_alchemist = 69 - gryphon_aviary = 70 - dragon_roost = 71 - human_shipyard = 72 - orc_shipyard = 73 - town_hall = 74 - great_hall = 75 - elven_lumber_mill = 76 - troll_lumber_mill = 77 - human_foundry = 78 - orc_foundry = 79 - mage_tower = 80 - temple_of_the_damned = 81 - human_blacksmith = 82 - orc_blacksmith = 83 - human_refinery = 84 - orc_refinery = 85 - human_oil_well = 86 - orc_oil_well = 87 - keep = 88 - stronghold = 89 - castle = 90 - fortress = 91 - gold_mine = 92 - oil_patch = 93 - human_start = 94 - orc_start = 95 - human_guard_tower = 96 - orc_guard_tower = 97 - human_cannon_tower = 98 - orc_cannon_tower = 99 - circle_of_power = 100 - dark_portal = 101 - runestone = 102 - human_wall = 103 - orc_wall = 104 - SEQ_FIELDS = ["sections"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sections']['start'] = self._io.pos() - self.sections = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['sections']: - self._debug['sections']['arr'] = [] - self._debug['sections']['arr'].append({'start': self._io.pos()}) - _t_sections = self._root.Section(self._io, self, self._root) - _t_sections._read() - self.sections.append(_t_sections) - self._debug['sections']['arr'][len(self.sections) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['sections']['end'] = self._io.pos() - - class SectionStartingResource(KaitaiStruct): - SEQ_FIELDS = ["resources_by_player"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['resources_by_player']['start'] = self._io.pos() - self.resources_by_player = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['resources_by_player']: - self._debug['resources_by_player']['arr'] = [] - self._debug['resources_by_player']['arr'].append({'start': self._io.pos()}) - self.resources_by_player.append(self._io.read_u2le()) - self._debug['resources_by_player']['arr'][len(self.resources_by_player) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['resources_by_player']['end'] = self._io.pos() - - - class SectionEra(KaitaiStruct): - """Section that specifies terrain type for this map.""" - SEQ_FIELDS = ["terrain"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['terrain']['start'] = self._io.pos() - self.terrain = KaitaiStream.resolve_enum(self._root.TerrainType, self._io.read_u2le()) - self._debug['terrain']['end'] = self._io.pos() - - - class SectionVer(KaitaiStruct): - """Section that specifies format version.""" - SEQ_FIELDS = ["version"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - - - class SectionDim(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_u2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_u2le() - self._debug['y']['end'] = self._io.pos() - - - class SectionType(KaitaiStruct): - """Section that confirms that this file is a "map file" by certain - magic string and supplies a tag that could be used in - multiplayer to check that all player use the same version of the - map. - """ - SEQ_FIELDS = ["magic", "unused", "id_tag"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x57\x41\x52\x32\x20\x4D\x41\x50\x00\x00") - self._debug['magic']['end'] = self._io.pos() - self._debug['unused']['start'] = self._io.pos() - self.unused = self._io.read_bytes(2) - self._debug['unused']['end'] = self._io.pos() - self._debug['id_tag']['start'] = self._io.pos() - self.id_tag = self._io.read_u4le() - self._debug['id_tag']['end'] = self._io.pos() - - - class SectionUnit(KaitaiStruct): - SEQ_FIELDS = ["units"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['units']['start'] = self._io.pos() - self.units = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['units']: - self._debug['units']['arr'] = [] - self._debug['units']['arr'].append({'start': self._io.pos()}) - _t_units = self._root.Unit(self._io, self, self._root) - _t_units._read() - self.units.append(_t_units) - self._debug['units']['arr'][len(self.units) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['units']['end'] = self._io.pos() - - - class Section(KaitaiStruct): - SEQ_FIELDS = ["name", "size", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - 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 = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionStartingResource(io, self, self._root) - self.body._read() - elif _on == u"ERAX": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionEra(io, self, self._root) - self.body._read() - elif _on == u"OWNR": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionOwnr(io, self, self._root) - self.body._read() - elif _on == u"ERA ": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionEra(io, self, self._root) - self.body._read() - elif _on == u"SGLD": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionStartingResource(io, self, self._root) - self.body._read() - elif _on == u"VER ": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionVer(io, self, self._root) - self.body._read() - elif _on == u"SOIL": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionStartingResource(io, self, self._root) - self.body._read() - elif _on == u"UNIT": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionUnit(io, self, self._root) - self.body._read() - elif _on == u"DIM ": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionDim(io, self, self._root) - self.body._read() - elif _on == u"TYPE": - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.SectionType(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.size) - self._debug['body']['end'] = self._io.pos() - - - class SectionOwnr(KaitaiStruct): - """Section that specifies who controls each player.""" - SEQ_FIELDS = ["controller_by_player"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['controller_by_player']['start'] = self._io.pos() - self.controller_by_player = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['controller_by_player']: - self._debug['controller_by_player']['arr'] = [] - self._debug['controller_by_player']['arr'].append({'start': self._io.pos()}) - self.controller_by_player.append(KaitaiStream.resolve_enum(self._root.Controller, self._io.read_u1())) - self._debug['controller_by_player']['arr'][len(self.controller_by_player) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['controller_by_player']['end'] = self._io.pos() - - - class Unit(KaitaiStruct): - SEQ_FIELDS = ["x", "y", "u_type", "owner", "options"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_u2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_u2le() - self._debug['y']['end'] = self._io.pos() - self._debug['u_type']['start'] = self._io.pos() - self.u_type = KaitaiStream.resolve_enum(self._root.UnitType, self._io.read_u1()) - self._debug['u_type']['end'] = self._io.pos() - self._debug['owner']['start'] = self._io.pos() - self.owner = self._io.read_u1() - self._debug['owner']['end'] = self._io.pos() - self._debug['options']['start'] = self._io.pos() - self.options = self._io.read_u2le() - self._debug['options']['end'] = self._io.pos() - - @property - def resource(self): - if hasattr(self, '_m_resource'): - return self._m_resource if hasattr(self, '_m_resource') else None - - if ((self.u_type == self._root.UnitType.gold_mine) or (self.u_type == self._root.UnitType.human_oil_well) or (self.u_type == self._root.UnitType.orc_oil_well) or (self.u_type == self._root.UnitType.oil_patch)) : - self._m_resource = (self.options * 2500) - - return self._m_resource if hasattr(self, '_m_resource') else None - - - diff --git a/python/examples/kaitai/wav.py b/python/examples/kaitai/wav.py deleted file mode 100644 index f05f958f..00000000 --- a/python/examples/kaitai/wav.py +++ /dev/null @@ -1,491 +0,0 @@ -# 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 -import collections - - -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 Wav(KaitaiStruct): - """The WAVE file format is a subset of Microsoft's RIFF specification for the - storage of multimedia files. A RIFF file starts out with a file header - followed by a sequence of data chunks. A WAVE file is often just a RIFF - file with a single "WAVE" chunk which consists of two sub-chunks -- - a "fmt " chunk specifying the data format and a "data" chunk containing - the actual sample data. - - This Kaitai implementation was written by John Byrd of Gigantic Software - (jbyrd@giganticsoftware.com), and it is likely to contain bugs. - - .. seealso:: - Source - https://www.loc.gov/preservation/digital/formats/fdd/fdd000001.shtml - """ - - class WFormatTagType(Enum): - unknown = 0 - pcm = 1 - adpcm = 2 - ieee_float = 3 - alaw = 6 - mulaw = 7 - dvi_adpcm = 17 - dolby_ac3_spdif = 146 - extensible = 65534 - development = 65535 - - class ChunkType(Enum): - fmt = 544501094 - bext = 1650817140 - cue = 1668637984 - data = 1684108385 - minf = 1835626086 - regn = 1919248238 - umid = 1970104676 - SEQ_FIELDS = ["riff_id", "file_size", "wave_id", "chunks"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['riff_id']['start'] = self._io.pos() - self.riff_id = self._io.ensure_fixed_contents(b"\x52\x49\x46\x46") - self._debug['riff_id']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u4le() - self._debug['file_size']['end'] = self._io.pos() - self._debug['wave_id']['start'] = self._io.pos() - self.wave_id = self._io.ensure_fixed_contents(b"\x57\x41\x56\x45") - self._debug['wave_id']['end'] = self._io.pos() - self._debug['chunks']['start'] = self._io.pos() - self._raw_chunks = self._io.read_bytes((self.file_size - 5)) - io = KaitaiStream(BytesIO(self._raw_chunks)) - self.chunks = self._root.ChunksType(io, self, self._root) - self.chunks._read() - self._debug['chunks']['end'] = self._io.pos() - - class SampleType(KaitaiStruct): - SEQ_FIELDS = ["sample"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sample']['start'] = self._io.pos() - self.sample = self._io.read_u2le() - self._debug['sample']['end'] = self._io.pos() - - - class FormatChunkType(KaitaiStruct): - SEQ_FIELDS = ["w_format_tag", "n_channels", "n_samples_per_sec", "n_avg_bytes_per_sec", "n_block_align", "w_bits_per_sample", "cb_size", "w_valid_bits_per_sample", "channel_mask_and_subformat"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['w_format_tag']['start'] = self._io.pos() - self.w_format_tag = KaitaiStream.resolve_enum(self._root.WFormatTagType, self._io.read_u2le()) - self._debug['w_format_tag']['end'] = self._io.pos() - self._debug['n_channels']['start'] = self._io.pos() - self.n_channels = self._io.read_u2le() - self._debug['n_channels']['end'] = self._io.pos() - self._debug['n_samples_per_sec']['start'] = self._io.pos() - self.n_samples_per_sec = self._io.read_u4le() - self._debug['n_samples_per_sec']['end'] = self._io.pos() - self._debug['n_avg_bytes_per_sec']['start'] = self._io.pos() - self.n_avg_bytes_per_sec = self._io.read_u4le() - self._debug['n_avg_bytes_per_sec']['end'] = self._io.pos() - self._debug['n_block_align']['start'] = self._io.pos() - self.n_block_align = self._io.read_u2le() - self._debug['n_block_align']['end'] = self._io.pos() - self._debug['w_bits_per_sample']['start'] = self._io.pos() - self.w_bits_per_sample = self._io.read_u2le() - self._debug['w_bits_per_sample']['end'] = self._io.pos() - if not (self.is_basic_pcm): - self._debug['cb_size']['start'] = self._io.pos() - self.cb_size = self._io.read_u2le() - self._debug['cb_size']['end'] = self._io.pos() - - if self.is_cb_size_meaningful: - self._debug['w_valid_bits_per_sample']['start'] = self._io.pos() - self.w_valid_bits_per_sample = self._io.read_u2le() - self._debug['w_valid_bits_per_sample']['end'] = self._io.pos() - - if self.is_extensible: - self._debug['channel_mask_and_subformat']['start'] = self._io.pos() - self.channel_mask_and_subformat = self._root.ChannelMaskAndSubformatType(self._io, self, self._root) - self.channel_mask_and_subformat._read() - self._debug['channel_mask_and_subformat']['end'] = self._io.pos() - - - @property - def is_extensible(self): - if hasattr(self, '_m_is_extensible'): - return self._m_is_extensible if hasattr(self, '_m_is_extensible') else None - - self._m_is_extensible = self.w_format_tag == self._root.WFormatTagType.extensible - return self._m_is_extensible if hasattr(self, '_m_is_extensible') else None - - @property - def is_basic_pcm(self): - if hasattr(self, '_m_is_basic_pcm'): - return self._m_is_basic_pcm if hasattr(self, '_m_is_basic_pcm') else None - - self._m_is_basic_pcm = self.w_format_tag == self._root.WFormatTagType.pcm - return self._m_is_basic_pcm if hasattr(self, '_m_is_basic_pcm') else None - - @property - def is_basic_float(self): - if hasattr(self, '_m_is_basic_float'): - return self._m_is_basic_float if hasattr(self, '_m_is_basic_float') else None - - self._m_is_basic_float = self.w_format_tag == self._root.WFormatTagType.ieee_float - return self._m_is_basic_float if hasattr(self, '_m_is_basic_float') else None - - @property - def is_cb_size_meaningful(self): - if hasattr(self, '_m_is_cb_size_meaningful'): - return self._m_is_cb_size_meaningful if hasattr(self, '_m_is_cb_size_meaningful') else None - - self._m_is_cb_size_meaningful = ((not (self.is_basic_pcm)) and (self.cb_size != 0)) - return self._m_is_cb_size_meaningful if hasattr(self, '_m_is_cb_size_meaningful') else None - - - class GuidType(KaitaiStruct): - SEQ_FIELDS = ["data1", "data2", "data3", "data4", "data4a"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data1']['start'] = self._io.pos() - self.data1 = self._io.read_u4le() - self._debug['data1']['end'] = self._io.pos() - self._debug['data2']['start'] = self._io.pos() - self.data2 = self._io.read_u2le() - self._debug['data2']['end'] = self._io.pos() - self._debug['data3']['start'] = self._io.pos() - self.data3 = self._io.read_u2le() - self._debug['data3']['end'] = self._io.pos() - self._debug['data4']['start'] = self._io.pos() - self.data4 = self._io.read_u4be() - self._debug['data4']['end'] = self._io.pos() - self._debug['data4a']['start'] = self._io.pos() - self.data4a = self._io.read_u4be() - self._debug['data4a']['end'] = self._io.pos() - - - class CuePointType(KaitaiStruct): - SEQ_FIELDS = ["dw_name", "dw_position", "fcc_chunk", "dw_chunk_start", "dw_block_start", "dw_sample_offset"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dw_name']['start'] = self._io.pos() - self.dw_name = self._io.read_u4le() - self._debug['dw_name']['end'] = self._io.pos() - self._debug['dw_position']['start'] = self._io.pos() - self.dw_position = self._io.read_u4le() - self._debug['dw_position']['end'] = self._io.pos() - self._debug['fcc_chunk']['start'] = self._io.pos() - self.fcc_chunk = self._io.read_u4le() - self._debug['fcc_chunk']['end'] = self._io.pos() - self._debug['dw_chunk_start']['start'] = self._io.pos() - self.dw_chunk_start = self._io.read_u4le() - self._debug['dw_chunk_start']['end'] = self._io.pos() - self._debug['dw_block_start']['start'] = self._io.pos() - self.dw_block_start = self._io.read_u4le() - self._debug['dw_block_start']['end'] = self._io.pos() - self._debug['dw_sample_offset']['start'] = self._io.pos() - self.dw_sample_offset = self._io.read_u4le() - self._debug['dw_sample_offset']['end'] = self._io.pos() - - - class DataChunkType(KaitaiStruct): - SEQ_FIELDS = ["data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['data']['start'] = self._io.pos() - self.data = self._io.read_bytes_full() - self._debug['data']['end'] = self._io.pos() - - - class SamplesType(KaitaiStruct): - SEQ_FIELDS = ["samples"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['samples']['start'] = self._io.pos() - self.samples = self._io.read_u4le() - self._debug['samples']['end'] = self._io.pos() - - - class ChannelMaskAndSubformatType(KaitaiStruct): - SEQ_FIELDS = ["dw_channel_mask", "subformat"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dw_channel_mask']['start'] = self._io.pos() - self.dw_channel_mask = self._root.ChannelMaskType(self._io, self, self._root) - self.dw_channel_mask._read() - self._debug['dw_channel_mask']['end'] = self._io.pos() - self._debug['subformat']['start'] = self._io.pos() - self.subformat = self._root.GuidType(self._io, self, self._root) - self.subformat._read() - self._debug['subformat']['end'] = self._io.pos() - - - class ChunksType(KaitaiStruct): - SEQ_FIELDS = ["chunk"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['chunk']['start'] = self._io.pos() - self.chunk = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['chunk']: - self._debug['chunk']['arr'] = [] - self._debug['chunk']['arr'].append({'start': self._io.pos()}) - _t_chunk = self._root.ChunkType(self._io, self, self._root) - _t_chunk._read() - self.chunk.append(_t_chunk) - self._debug['chunk']['arr'][len(self.chunk) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['chunk']['end'] = self._io.pos() - - - class CueChunkType(KaitaiStruct): - SEQ_FIELDS = ["dw_cue_points", "cue_points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['dw_cue_points']['start'] = self._io.pos() - self.dw_cue_points = self._io.read_u4le() - self._debug['dw_cue_points']['end'] = self._io.pos() - if self.dw_cue_points != 0: - self._debug['cue_points']['start'] = self._io.pos() - self.cue_points = [None] * (self.dw_cue_points) - for i in range(self.dw_cue_points): - if not 'arr' in self._debug['cue_points']: - self._debug['cue_points']['arr'] = [] - self._debug['cue_points']['arr'].append({'start': self._io.pos()}) - _t_cue_points = self._root.CuePointType(self._io, self, self._root) - _t_cue_points._read() - self.cue_points[i] = _t_cue_points - self._debug['cue_points']['arr'][i]['end'] = self._io.pos() - - self._debug['cue_points']['end'] = self._io.pos() - - - - class ChannelMaskType(KaitaiStruct): - SEQ_FIELDS = ["front_right_of_center", "front_left_of_center", "back_right", "back_left", "low_frequency", "front_center", "front_right", "front_left", "top_center", "side_right", "side_left", "back_center", "top_back_left", "top_front_right", "top_front_center", "top_front_left", "unused1", "top_back_right", "top_back_center", "unused2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['front_right_of_center']['start'] = self._io.pos() - self.front_right_of_center = self._io.read_bits_int(1) != 0 - self._debug['front_right_of_center']['end'] = self._io.pos() - self._debug['front_left_of_center']['start'] = self._io.pos() - self.front_left_of_center = self._io.read_bits_int(1) != 0 - self._debug['front_left_of_center']['end'] = self._io.pos() - self._debug['back_right']['start'] = self._io.pos() - self.back_right = self._io.read_bits_int(1) != 0 - self._debug['back_right']['end'] = self._io.pos() - self._debug['back_left']['start'] = self._io.pos() - self.back_left = self._io.read_bits_int(1) != 0 - self._debug['back_left']['end'] = self._io.pos() - self._debug['low_frequency']['start'] = self._io.pos() - self.low_frequency = self._io.read_bits_int(1) != 0 - self._debug['low_frequency']['end'] = self._io.pos() - self._debug['front_center']['start'] = self._io.pos() - self.front_center = self._io.read_bits_int(1) != 0 - self._debug['front_center']['end'] = self._io.pos() - self._debug['front_right']['start'] = self._io.pos() - self.front_right = self._io.read_bits_int(1) != 0 - self._debug['front_right']['end'] = self._io.pos() - self._debug['front_left']['start'] = self._io.pos() - self.front_left = self._io.read_bits_int(1) != 0 - self._debug['front_left']['end'] = self._io.pos() - self._debug['top_center']['start'] = self._io.pos() - self.top_center = self._io.read_bits_int(1) != 0 - self._debug['top_center']['end'] = self._io.pos() - self._debug['side_right']['start'] = self._io.pos() - self.side_right = self._io.read_bits_int(1) != 0 - self._debug['side_right']['end'] = self._io.pos() - self._debug['side_left']['start'] = self._io.pos() - self.side_left = self._io.read_bits_int(1) != 0 - self._debug['side_left']['end'] = self._io.pos() - self._debug['back_center']['start'] = self._io.pos() - self.back_center = self._io.read_bits_int(1) != 0 - self._debug['back_center']['end'] = self._io.pos() - self._debug['top_back_left']['start'] = self._io.pos() - self.top_back_left = self._io.read_bits_int(1) != 0 - self._debug['top_back_left']['end'] = self._io.pos() - self._debug['top_front_right']['start'] = self._io.pos() - self.top_front_right = self._io.read_bits_int(1) != 0 - self._debug['top_front_right']['end'] = self._io.pos() - self._debug['top_front_center']['start'] = self._io.pos() - self.top_front_center = self._io.read_bits_int(1) != 0 - self._debug['top_front_center']['end'] = self._io.pos() - self._debug['top_front_left']['start'] = self._io.pos() - self.top_front_left = self._io.read_bits_int(1) != 0 - self._debug['top_front_left']['end'] = self._io.pos() - self._debug['unused1']['start'] = self._io.pos() - self.unused1 = self._io.read_bits_int(6) - self._debug['unused1']['end'] = self._io.pos() - self._debug['top_back_right']['start'] = self._io.pos() - self.top_back_right = self._io.read_bits_int(1) != 0 - self._debug['top_back_right']['end'] = self._io.pos() - self._debug['top_back_center']['start'] = self._io.pos() - self.top_back_center = self._io.read_bits_int(1) != 0 - self._debug['top_back_center']['end'] = self._io.pos() - self._debug['unused2']['start'] = self._io.pos() - self.unused2 = self._io.read_bits_int(8) - self._debug['unused2']['end'] = self._io.pos() - - - class ChunkType(KaitaiStruct): - SEQ_FIELDS = ["chunk_id", "len", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['chunk_id']['start'] = self._io.pos() - self.chunk_id = self._io.read_u4be() - self._debug['chunk_id']['end'] = self._io.pos() - self._debug['len']['start'] = self._io.pos() - self.len = self._io.read_u4le() - self._debug['len']['end'] = self._io.pos() - self._debug['data']['start'] = self._io.pos() - _on = self.chunk_id - if _on == 1684108385: - self._raw_data = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.DataChunkType(io, self, self._root) - self.data._read() - elif _on == 1668637984: - self._raw_data = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.CueChunkType(io, self, self._root) - self.data._read() - elif _on == 1650817140: - self._raw_data = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.BextChunkType(io, self, self._root) - self.data._read() - elif _on == 1718449184: - self._raw_data = self._io.read_bytes(self.len) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.FormatChunkType(io, self, self._root) - self.data._read() - else: - self.data = self._io.read_bytes(self.len) - self._debug['data']['end'] = self._io.pos() - - - class BextChunkType(KaitaiStruct): - SEQ_FIELDS = ["description", "originator", "originator_reference", "origination_date", "origination_time", "time_reference_low", "time_reference_high", "version", "umid", "loudness_value", "loudness_range", "max_true_peak_level", "max_momentary_loudness", "max_short_term_loudness"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['description']['start'] = self._io.pos() - self.description = (self._io.read_bytes(256)).decode(u"ASCII") - self._debug['description']['end'] = self._io.pos() - self._debug['originator']['start'] = self._io.pos() - self.originator = (self._io.read_bytes(32)).decode(u"ASCII") - self._debug['originator']['end'] = self._io.pos() - self._debug['originator_reference']['start'] = self._io.pos() - self.originator_reference = (self._io.read_bytes(32)).decode(u"ASCII") - self._debug['originator_reference']['end'] = self._io.pos() - self._debug['origination_date']['start'] = self._io.pos() - self.origination_date = (self._io.read_bytes(10)).decode(u"ASCII") - self._debug['origination_date']['end'] = self._io.pos() - self._debug['origination_time']['start'] = self._io.pos() - self.origination_time = (self._io.read_bytes(8)).decode(u"ASCII") - self._debug['origination_time']['end'] = self._io.pos() - self._debug['time_reference_low']['start'] = self._io.pos() - self.time_reference_low = self._io.read_u4le() - self._debug['time_reference_low']['end'] = self._io.pos() - self._debug['time_reference_high']['start'] = self._io.pos() - self.time_reference_high = self._io.read_u4le() - self._debug['time_reference_high']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['umid']['start'] = self._io.pos() - self.umid = self._io.read_bytes(64) - self._debug['umid']['end'] = self._io.pos() - self._debug['loudness_value']['start'] = self._io.pos() - self.loudness_value = self._io.read_u2le() - self._debug['loudness_value']['end'] = self._io.pos() - self._debug['loudness_range']['start'] = self._io.pos() - self.loudness_range = self._io.read_u2le() - self._debug['loudness_range']['end'] = self._io.pos() - self._debug['max_true_peak_level']['start'] = self._io.pos() - self.max_true_peak_level = self._io.read_u2le() - self._debug['max_true_peak_level']['end'] = self._io.pos() - self._debug['max_momentary_loudness']['start'] = self._io.pos() - self.max_momentary_loudness = self._io.read_u2le() - self._debug['max_momentary_loudness']['end'] = self._io.pos() - self._debug['max_short_term_loudness']['start'] = self._io.pos() - self.max_short_term_loudness = self._io.read_u2le() - self._debug['max_short_term_loudness']['end'] = self._io.pos() - - - @property - def format_chunk(self): - if hasattr(self, '_m_format_chunk'): - return self._m_format_chunk if hasattr(self, '_m_format_chunk') else None - - self._m_format_chunk = self.chunks.chunk[0].data - return self._m_format_chunk if hasattr(self, '_m_format_chunk') else None - - diff --git a/python/examples/kaitai/windows_evt_log.py b/python/examples/kaitai/windows_evt_log.py deleted file mode 100644 index 99c8e26b..00000000 --- a/python/examples/kaitai/windows_evt_log.py +++ /dev/null @@ -1,299 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 WindowsEvtLog(KaitaiStruct): - """EVT files are Windows Event Log files written by older Windows - operating systems (2000, XP, 2003). They are used as binary log - files by several major Windows subsystems and - applications. Typically, several of them can be found in - `%WINDIR%\system32\config` directory: - - * Application = `AppEvent.evt` - * System = `SysEvent.evt` - * Security = `SecEvent.evt` - - Alternatively, one can export any system event log as distinct .evt - file using relevant option in Event Viewer application. - - A Windows application can submit an entry into these logs using - [ReportEvent](https://msdn.microsoft.com/en-us/library/aa363679(v=vs.85).aspx) - function of Windows API. - - Internally, EVT files consist of a fixed-size header and event - records. There are several usage scenarios (non-wrapping vs wrapping - log files) which result in slightly different organization of - records. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/bb309026(v=vs.85).aspx - """ - SEQ_FIELDS = ["header", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.Record(self._io, self, self._root) - _t_records._read() - self.records.append(_t_records) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['records']['end'] = self._io.pos() - - class Header(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/bb309024(v=vs.85).aspx - """ - SEQ_FIELDS = ["len_header", "magic", "version_major", "version_minor", "ofs_start", "ofs_end", "cur_rec_idx", "oldest_rec_idx", "len_file_max", "flags", "retention", "len_header_2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u4le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x4C\x66\x4C\x65") - self._debug['magic']['end'] = self._io.pos() - self._debug['version_major']['start'] = self._io.pos() - self.version_major = self._io.read_u4le() - self._debug['version_major']['end'] = self._io.pos() - self._debug['version_minor']['start'] = self._io.pos() - self.version_minor = self._io.read_u4le() - self._debug['version_minor']['end'] = self._io.pos() - self._debug['ofs_start']['start'] = self._io.pos() - self.ofs_start = self._io.read_u4le() - self._debug['ofs_start']['end'] = self._io.pos() - self._debug['ofs_end']['start'] = self._io.pos() - self.ofs_end = self._io.read_u4le() - self._debug['ofs_end']['end'] = self._io.pos() - self._debug['cur_rec_idx']['start'] = self._io.pos() - self.cur_rec_idx = self._io.read_u4le() - self._debug['cur_rec_idx']['end'] = self._io.pos() - self._debug['oldest_rec_idx']['start'] = self._io.pos() - self.oldest_rec_idx = self._io.read_u4le() - self._debug['oldest_rec_idx']['end'] = self._io.pos() - self._debug['len_file_max']['start'] = self._io.pos() - self.len_file_max = self._io.read_u4le() - self._debug['len_file_max']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.Header.Flags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['retention']['start'] = self._io.pos() - self.retention = self._io.read_u4le() - self._debug['retention']['end'] = self._io.pos() - self._debug['len_header_2']['start'] = self._io.pos() - self.len_header_2 = self._io.read_u4le() - self._debug['len_header_2']['end'] = self._io.pos() - - class Flags(KaitaiStruct): - SEQ_FIELDS = ["reserved", "archive", "log_full", "wrap", "dirty"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(28) - self._debug['reserved']['end'] = self._io.pos() - self._debug['archive']['start'] = self._io.pos() - self.archive = self._io.read_bits_int(1) != 0 - self._debug['archive']['end'] = self._io.pos() - self._debug['log_full']['start'] = self._io.pos() - self.log_full = self._io.read_bits_int(1) != 0 - self._debug['log_full']['end'] = self._io.pos() - self._debug['wrap']['start'] = self._io.pos() - self.wrap = self._io.read_bits_int(1) != 0 - self._debug['wrap']['end'] = self._io.pos() - self._debug['dirty']['start'] = self._io.pos() - self.dirty = self._io.read_bits_int(1) != 0 - self._debug['dirty']['end'] = self._io.pos() - - - - class Record(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/aa363646(v=vs.85).aspx - """ - SEQ_FIELDS = ["len_record", "type", "body", "len_record2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_record']['start'] = self._io.pos() - self.len_record = self._io.read_u4le() - self._debug['len_record']['end'] = self._io.pos() - self._debug['type']['start'] = self._io.pos() - self.type = self._io.read_u4le() - self._debug['type']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.type - if _on == 1699505740: - self._raw_body = self._io.read_bytes((self.len_record - 12)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.RecordBody(io, self, self._root) - self.body._read() - elif _on == 286331153: - self._raw_body = self._io.read_bytes((self.len_record - 12)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.CursorRecordBody(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes((self.len_record - 12)) - self._debug['body']['end'] = self._io.pos() - self._debug['len_record2']['start'] = self._io.pos() - self.len_record2 = self._io.read_u4le() - self._debug['len_record2']['end'] = self._io.pos() - - - class RecordBody(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/aa363646(v=vs.85).aspx - """ - - class EventTypes(Enum): - error = 1 - audit_failure = 2 - audit_success = 3 - info = 4 - warning = 5 - SEQ_FIELDS = ["idx", "time_generated", "time_written", "event_id", "event_type", "num_strings", "event_category", "reserved", "ofs_strings", "len_user_sid", "ofs_user_sid", "len_data", "ofs_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['idx']['start'] = self._io.pos() - self.idx = self._io.read_u4le() - self._debug['idx']['end'] = self._io.pos() - self._debug['time_generated']['start'] = self._io.pos() - self.time_generated = self._io.read_u4le() - self._debug['time_generated']['end'] = self._io.pos() - self._debug['time_written']['start'] = self._io.pos() - self.time_written = self._io.read_u4le() - self._debug['time_written']['end'] = self._io.pos() - self._debug['event_id']['start'] = self._io.pos() - self.event_id = self._io.read_u4le() - self._debug['event_id']['end'] = self._io.pos() - self._debug['event_type']['start'] = self._io.pos() - self.event_type = KaitaiStream.resolve_enum(self._root.RecordBody.EventTypes, self._io.read_u2le()) - self._debug['event_type']['end'] = self._io.pos() - self._debug['num_strings']['start'] = self._io.pos() - self.num_strings = self._io.read_u2le() - self._debug['num_strings']['end'] = self._io.pos() - self._debug['event_category']['start'] = self._io.pos() - self.event_category = self._io.read_u2le() - self._debug['event_category']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bytes(6) - self._debug['reserved']['end'] = self._io.pos() - self._debug['ofs_strings']['start'] = self._io.pos() - self.ofs_strings = self._io.read_u4le() - self._debug['ofs_strings']['end'] = self._io.pos() - self._debug['len_user_sid']['start'] = self._io.pos() - self.len_user_sid = self._io.read_u4le() - self._debug['len_user_sid']['end'] = self._io.pos() - self._debug['ofs_user_sid']['start'] = self._io.pos() - self.ofs_user_sid = self._io.read_u4le() - self._debug['ofs_user_sid']['end'] = self._io.pos() - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u4le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['ofs_data']['start'] = self._io.pos() - self.ofs_data = self._io.read_u4le() - self._debug['ofs_data']['end'] = self._io.pos() - - @property - def user_sid(self): - if hasattr(self, '_m_user_sid'): - return self._m_user_sid if hasattr(self, '_m_user_sid') else None - - _pos = self._io.pos() - self._io.seek((self.ofs_user_sid - 8)) - self._debug['_m_user_sid']['start'] = self._io.pos() - self._m_user_sid = self._io.read_bytes(self.len_user_sid) - self._debug['_m_user_sid']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_user_sid if hasattr(self, '_m_user_sid') else None - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - _pos = self._io.pos() - self._io.seek((self.ofs_data - 8)) - self._debug['_m_data']['start'] = self._io.pos() - self._m_data = self._io.read_bytes(self.len_data) - self._debug['_m_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - class CursorRecordBody(KaitaiStruct): - """ - .. seealso:: - Source - http://www.forensicswiki.org/wiki/Windows_Event_Log_(EVT)#Cursor_Record - """ - SEQ_FIELDS = ["magic", "ofs_first_record", "ofs_next_record", "idx_next_record", "idx_first_record"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x22\x22\x22\x22\x33\x33\x33\x33\x44\x44\x44\x44") - self._debug['magic']['end'] = self._io.pos() - self._debug['ofs_first_record']['start'] = self._io.pos() - self.ofs_first_record = self._io.read_u4le() - self._debug['ofs_first_record']['end'] = self._io.pos() - self._debug['ofs_next_record']['start'] = self._io.pos() - self.ofs_next_record = self._io.read_u4le() - self._debug['ofs_next_record']['end'] = self._io.pos() - self._debug['idx_next_record']['start'] = self._io.pos() - self.idx_next_record = self._io.read_u4le() - self._debug['idx_next_record']['end'] = self._io.pos() - self._debug['idx_first_record']['start'] = self._io.pos() - self.idx_first_record = self._io.read_u4le() - self._debug['idx_first_record']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/windows_lnk_file.py b/python/examples/kaitai/windows_lnk_file.py deleted file mode 100644 index c1dca73b..00000000 --- a/python/examples/kaitai/windows_lnk_file.py +++ /dev/null @@ -1,460 +0,0 @@ -# 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 -import collections - - -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)) - -from .windows_shell_items import WindowsShellItems -class WindowsLnkFile(KaitaiStruct): - """Windows .lnk files (AKA "shell link" file) are most frequently used - in Windows shell to create "shortcuts" to another files, usually for - purposes of running a program from some other directory, sometimes - with certain preconfigured arguments and some other options. - - .. seealso:: - Source - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - - class WindowState(Enum): - normal = 1 - maximized = 3 - min_no_active = 7 - - class DriveTypes(Enum): - unknown = 0 - no_root_dir = 1 - removable = 2 - fixed = 3 - remote = 4 - cdrom = 5 - ramdisk = 6 - SEQ_FIELDS = ["header", "target_id_list", "info", "name", "rel_path", "work_dir", "arguments", "icon_location"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.FileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - if self.header.flags.has_link_target_id_list: - self._debug['target_id_list']['start'] = self._io.pos() - self.target_id_list = self._root.LinkTargetIdList(self._io, self, self._root) - self.target_id_list._read() - self._debug['target_id_list']['end'] = self._io.pos() - - if self.header.flags.has_link_info: - self._debug['info']['start'] = self._io.pos() - self.info = self._root.LinkInfo(self._io, self, self._root) - self.info._read() - self._debug['info']['end'] = self._io.pos() - - if self.header.flags.has_name: - self._debug['name']['start'] = self._io.pos() - self.name = self._root.StringData(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - - if self.header.flags.has_rel_path: - self._debug['rel_path']['start'] = self._io.pos() - self.rel_path = self._root.StringData(self._io, self, self._root) - self.rel_path._read() - self._debug['rel_path']['end'] = self._io.pos() - - if self.header.flags.has_work_dir: - self._debug['work_dir']['start'] = self._io.pos() - self.work_dir = self._root.StringData(self._io, self, self._root) - self.work_dir._read() - self._debug['work_dir']['end'] = self._io.pos() - - if self.header.flags.has_arguments: - self._debug['arguments']['start'] = self._io.pos() - self.arguments = self._root.StringData(self._io, self, self._root) - self.arguments._read() - self._debug['arguments']['end'] = self._io.pos() - - if self.header.flags.has_icon_location: - self._debug['icon_location']['start'] = self._io.pos() - self.icon_location = self._root.StringData(self._io, self, self._root) - self.icon_location._read() - self._debug['icon_location']['end'] = self._io.pos() - - - class LinkTargetIdList(KaitaiStruct): - """ - .. seealso:: - Section 2.2 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_id_list", "id_list"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_id_list']['start'] = self._io.pos() - self.len_id_list = self._io.read_u2le() - self._debug['len_id_list']['end'] = self._io.pos() - self._debug['id_list']['start'] = self._io.pos() - self._raw_id_list = self._io.read_bytes(self.len_id_list) - io = KaitaiStream(BytesIO(self._raw_id_list)) - self.id_list = WindowsShellItems(io) - self.id_list._read() - self._debug['id_list']['end'] = self._io.pos() - - - class StringData(KaitaiStruct): - SEQ_FIELDS = ["chars_str", "str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['chars_str']['start'] = self._io.pos() - self.chars_str = self._io.read_u2le() - self._debug['chars_str']['end'] = self._io.pos() - self._debug['str']['start'] = self._io.pos() - self.str = (self._io.read_bytes((self.chars_str * 2))).decode(u"UTF-16LE") - self._debug['str']['end'] = self._io.pos() - - - class LinkInfo(KaitaiStruct): - """ - .. seealso:: - Section 2.3 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_all", "all"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_all']['start'] = self._io.pos() - self.len_all = self._io.read_u4le() - self._debug['len_all']['end'] = self._io.pos() - self._debug['all']['start'] = self._io.pos() - self._raw_all = self._io.read_bytes((self.len_all - 4)) - io = KaitaiStream(BytesIO(self._raw_all)) - self.all = self._root.LinkInfo.All(io, self, self._root) - self.all._read() - self._debug['all']['end'] = self._io.pos() - - class VolumeIdBody(KaitaiStruct): - """ - .. seealso:: - Section 2.3.1 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["drive_type", "drive_serial_number", "ofs_volume_label", "ofs_volume_label_unicode"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['drive_type']['start'] = self._io.pos() - self.drive_type = KaitaiStream.resolve_enum(self._root.DriveTypes, self._io.read_u4le()) - self._debug['drive_type']['end'] = self._io.pos() - self._debug['drive_serial_number']['start'] = self._io.pos() - self.drive_serial_number = self._io.read_u4le() - self._debug['drive_serial_number']['end'] = self._io.pos() - self._debug['ofs_volume_label']['start'] = self._io.pos() - self.ofs_volume_label = self._io.read_u4le() - self._debug['ofs_volume_label']['end'] = self._io.pos() - if self.is_unicode: - self._debug['ofs_volume_label_unicode']['start'] = self._io.pos() - self.ofs_volume_label_unicode = self._io.read_u4le() - self._debug['ofs_volume_label_unicode']['end'] = self._io.pos() - - - @property - def is_unicode(self): - if hasattr(self, '_m_is_unicode'): - return self._m_is_unicode if hasattr(self, '_m_is_unicode') else None - - self._m_is_unicode = self.ofs_volume_label == 20 - return self._m_is_unicode if hasattr(self, '_m_is_unicode') else None - - @property - def volume_label_ansi(self): - if hasattr(self, '_m_volume_label_ansi'): - return self._m_volume_label_ansi if hasattr(self, '_m_volume_label_ansi') else None - - if not (self.is_unicode): - _pos = self._io.pos() - self._io.seek((self.ofs_volume_label - 4)) - self._debug['_m_volume_label_ansi']['start'] = self._io.pos() - self._m_volume_label_ansi = (self._io.read_bytes_term(0, False, True, True)).decode(u"cp437") - self._debug['_m_volume_label_ansi']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_volume_label_ansi if hasattr(self, '_m_volume_label_ansi') else None - - - class All(KaitaiStruct): - """ - .. seealso:: - Section 2.3 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_header", "header"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.read_u4le() - self._debug['len_header']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self._raw_header = self._io.read_bytes((self.len_header - 8)) - io = KaitaiStream(BytesIO(self._raw_header)) - self.header = self._root.LinkInfo.Header(io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - - @property - def volume_id(self): - if hasattr(self, '_m_volume_id'): - return self._m_volume_id if hasattr(self, '_m_volume_id') else None - - if self.header.flags.has_volume_id_and_local_base_path: - _pos = self._io.pos() - self._io.seek((self.header.ofs_volume_id - 4)) - self._debug['_m_volume_id']['start'] = self._io.pos() - self._m_volume_id = self._root.LinkInfo.VolumeIdSpec(self._io, self, self._root) - self._m_volume_id._read() - self._debug['_m_volume_id']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_volume_id if hasattr(self, '_m_volume_id') else None - - @property - def local_base_path(self): - if hasattr(self, '_m_local_base_path'): - return self._m_local_base_path if hasattr(self, '_m_local_base_path') else None - - if self.header.flags.has_volume_id_and_local_base_path: - _pos = self._io.pos() - self._io.seek((self.header.ofs_local_base_path - 4)) - self._debug['_m_local_base_path']['start'] = self._io.pos() - self._m_local_base_path = self._io.read_bytes_term(0, False, True, True) - self._debug['_m_local_base_path']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_local_base_path if hasattr(self, '_m_local_base_path') else None - - - class VolumeIdSpec(KaitaiStruct): - """ - .. seealso:: - Section 2.3.1 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_all", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_all']['start'] = self._io.pos() - self.len_all = self._io.read_u4le() - self._debug['len_all']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self._raw_body = self._io.read_bytes((self.len_all - 4)) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.LinkInfo.VolumeIdBody(io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class LinkInfoFlags(KaitaiStruct): - """ - .. seealso:: - Section 2.3 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["reserved1", "has_common_net_rel_link", "has_volume_id_and_local_base_path", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved1']['start'] = self._io.pos() - self.reserved1 = self._io.read_bits_int(6) - self._debug['reserved1']['end'] = self._io.pos() - self._debug['has_common_net_rel_link']['start'] = self._io.pos() - self.has_common_net_rel_link = self._io.read_bits_int(1) != 0 - self._debug['has_common_net_rel_link']['end'] = self._io.pos() - self._debug['has_volume_id_and_local_base_path']['start'] = self._io.pos() - self.has_volume_id_and_local_base_path = self._io.read_bits_int(1) != 0 - self._debug['has_volume_id_and_local_base_path']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_bits_int(24) - self._debug['reserved2']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - """ - .. seealso:: - Section 2.3 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["flags", "ofs_volume_id", "ofs_local_base_path", "ofs_common_net_rel_link", "ofs_common_path_suffix", "ofs_local_base_path_unicode", "ofs_common_path_suffix_unicode"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._root.LinkInfo.LinkInfoFlags(self._io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['ofs_volume_id']['start'] = self._io.pos() - self.ofs_volume_id = self._io.read_u4le() - self._debug['ofs_volume_id']['end'] = self._io.pos() - self._debug['ofs_local_base_path']['start'] = self._io.pos() - self.ofs_local_base_path = self._io.read_u4le() - self._debug['ofs_local_base_path']['end'] = self._io.pos() - self._debug['ofs_common_net_rel_link']['start'] = self._io.pos() - self.ofs_common_net_rel_link = self._io.read_u4le() - self._debug['ofs_common_net_rel_link']['end'] = self._io.pos() - self._debug['ofs_common_path_suffix']['start'] = self._io.pos() - self.ofs_common_path_suffix = self._io.read_u4le() - self._debug['ofs_common_path_suffix']['end'] = self._io.pos() - if not (self._io.is_eof()): - self._debug['ofs_local_base_path_unicode']['start'] = self._io.pos() - self.ofs_local_base_path_unicode = self._io.read_u4le() - self._debug['ofs_local_base_path_unicode']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['ofs_common_path_suffix_unicode']['start'] = self._io.pos() - self.ofs_common_path_suffix_unicode = self._io.read_u4le() - self._debug['ofs_common_path_suffix_unicode']['end'] = self._io.pos() - - - - - class LinkFlags(KaitaiStruct): - """ - .. seealso:: - Section 2.1.1 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["is_unicode", "has_icon_location", "has_arguments", "has_work_dir", "has_rel_path", "has_name", "has_link_info", "has_link_target_id_list", "_unnamed8", "reserved", "keep_local_id_list_for_unc_target", "_unnamed11"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['is_unicode']['start'] = self._io.pos() - self.is_unicode = self._io.read_bits_int(1) != 0 - self._debug['is_unicode']['end'] = self._io.pos() - self._debug['has_icon_location']['start'] = self._io.pos() - self.has_icon_location = self._io.read_bits_int(1) != 0 - self._debug['has_icon_location']['end'] = self._io.pos() - self._debug['has_arguments']['start'] = self._io.pos() - self.has_arguments = self._io.read_bits_int(1) != 0 - self._debug['has_arguments']['end'] = self._io.pos() - self._debug['has_work_dir']['start'] = self._io.pos() - self.has_work_dir = self._io.read_bits_int(1) != 0 - self._debug['has_work_dir']['end'] = self._io.pos() - self._debug['has_rel_path']['start'] = self._io.pos() - self.has_rel_path = self._io.read_bits_int(1) != 0 - self._debug['has_rel_path']['end'] = self._io.pos() - self._debug['has_name']['start'] = self._io.pos() - self.has_name = self._io.read_bits_int(1) != 0 - self._debug['has_name']['end'] = self._io.pos() - self._debug['has_link_info']['start'] = self._io.pos() - self.has_link_info = self._io.read_bits_int(1) != 0 - self._debug['has_link_info']['end'] = self._io.pos() - self._debug['has_link_target_id_list']['start'] = self._io.pos() - self.has_link_target_id_list = self._io.read_bits_int(1) != 0 - self._debug['has_link_target_id_list']['end'] = self._io.pos() - self._debug['_unnamed8']['start'] = self._io.pos() - self._unnamed8 = self._io.read_bits_int(16) - self._debug['_unnamed8']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_bits_int(5) - self._debug['reserved']['end'] = self._io.pos() - self._debug['keep_local_id_list_for_unc_target']['start'] = self._io.pos() - self.keep_local_id_list_for_unc_target = self._io.read_bits_int(1) != 0 - self._debug['keep_local_id_list_for_unc_target']['end'] = self._io.pos() - self._debug['_unnamed11']['start'] = self._io.pos() - self._unnamed11 = self._io.read_bits_int(2) - self._debug['_unnamed11']['end'] = self._io.pos() - - - class FileHeader(KaitaiStruct): - """ - .. seealso:: - Section 2.1 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_header", "link_clsid", "flags", "file_attrs", "time_creation", "time_access", "time_write", "target_file_size", "icon_index", "show_command", "hotkey", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_header']['start'] = self._io.pos() - self.len_header = self._io.ensure_fixed_contents(b"\x4C\x00\x00\x00") - self._debug['len_header']['end'] = self._io.pos() - self._debug['link_clsid']['start'] = self._io.pos() - self.link_clsid = self._io.ensure_fixed_contents(b"\x01\x14\x02\x00\x00\x00\x00\x00\xC0\x00\x00\x00\x00\x00\x00\x46") - self._debug['link_clsid']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self._raw_flags = self._io.read_bytes(4) - io = KaitaiStream(BytesIO(self._raw_flags)) - self.flags = self._root.LinkFlags(io, self, self._root) - self.flags._read() - self._debug['flags']['end'] = self._io.pos() - self._debug['file_attrs']['start'] = self._io.pos() - self.file_attrs = self._io.read_u4le() - self._debug['file_attrs']['end'] = self._io.pos() - self._debug['time_creation']['start'] = self._io.pos() - self.time_creation = self._io.read_u8le() - self._debug['time_creation']['end'] = self._io.pos() - self._debug['time_access']['start'] = self._io.pos() - self.time_access = self._io.read_u8le() - self._debug['time_access']['end'] = self._io.pos() - self._debug['time_write']['start'] = self._io.pos() - self.time_write = self._io.read_u8le() - self._debug['time_write']['end'] = self._io.pos() - self._debug['target_file_size']['start'] = self._io.pos() - self.target_file_size = self._io.read_u4le() - self._debug['target_file_size']['end'] = self._io.pos() - self._debug['icon_index']['start'] = self._io.pos() - self.icon_index = self._io.read_s4le() - self._debug['icon_index']['end'] = self._io.pos() - self._debug['show_command']['start'] = self._io.pos() - self.show_command = KaitaiStream.resolve_enum(self._root.WindowState, self._io.read_u4le()) - self._debug['show_command']['end'] = self._io.pos() - self._debug['hotkey']['start'] = self._io.pos() - self.hotkey = self._io.read_u2le() - self._debug['hotkey']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/windows_minidump.py b/python/examples/kaitai/windows_minidump.py deleted file mode 100644 index 8a9a0502..00000000 --- a/python/examples/kaitai/windows_minidump.py +++ /dev/null @@ -1,540 +0,0 @@ -# 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 -import collections - - -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 WindowsMinidump(KaitaiStruct): - """Windows MiniDump (MDMP) file provides a concise way to store process - core dumps, which is useful for debugging. Given its small size, - modularity, some cross-platform features and native support in some - debuggers, it is particularly useful for crash reporting, and is - used for that purpose in Windows and Google Chrome projects. - - The file itself is a container, which contains a number of typed - "streams", which contain some data according to its type attribute. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680378(VS.85).aspx - """ - - class StreamTypes(Enum): - unused = 0 - reserved_0 = 1 - reserved_1 = 2 - thread_list = 3 - module_list = 4 - memory_list = 5 - exception = 6 - system_info = 7 - thread_ex_list = 8 - memory_64_list = 9 - comment_a = 10 - comment_w = 11 - handle_data = 12 - function_table = 13 - unloaded_module_list = 14 - misc_info = 15 - memory_info_list = 16 - thread_info_list = 17 - handle_operation_list = 18 - SEQ_FIELDS = ["magic1", "magic2", "version", "num_streams", "ofs_streams", "checksum", "timestamp", "flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic1']['start'] = self._io.pos() - self.magic1 = self._io.ensure_fixed_contents(b"\x4D\x44\x4D\x50") - self._debug['magic1']['end'] = self._io.pos() - self._debug['magic2']['start'] = self._io.pos() - self.magic2 = self._io.ensure_fixed_contents(b"\x93\xA7") - self._debug['magic2']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['num_streams']['start'] = self._io.pos() - self.num_streams = self._io.read_u4le() - self._debug['num_streams']['end'] = self._io.pos() - self._debug['ofs_streams']['start'] = self._io.pos() - self.ofs_streams = self._io.read_u4le() - self._debug['ofs_streams']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u4le() - self._debug['checksum']['end'] = self._io.pos() - self._debug['timestamp']['start'] = self._io.pos() - self.timestamp = self._io.read_u4le() - self._debug['timestamp']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u8le() - self._debug['flags']['end'] = self._io.pos() - - class ThreadList(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680515(v=vs.85).aspx - """ - SEQ_FIELDS = ["num_threads", "threads"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_threads']['start'] = self._io.pos() - self.num_threads = self._io.read_u4le() - self._debug['num_threads']['end'] = self._io.pos() - self._debug['threads']['start'] = self._io.pos() - self.threads = [None] * (self.num_threads) - for i in range(self.num_threads): - if not 'arr' in self._debug['threads']: - self._debug['threads']['arr'] = [] - self._debug['threads']['arr'].append({'start': self._io.pos()}) - _t_threads = self._root.Thread(self._io, self, self._root) - _t_threads._read() - self.threads[i] = _t_threads - self._debug['threads']['arr'][i]['end'] = self._io.pos() - - self._debug['threads']['end'] = self._io.pos() - - - class LocationDescriptor(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680383(v=vs.85).aspx - """ - SEQ_FIELDS = ["len_data", "ofs_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u4le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['ofs_data']['start'] = self._io.pos() - self.ofs_data = self._io.read_u4le() - self._debug['ofs_data']['end'] = self._io.pos() - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_data) - self._debug['_m_data']['start'] = io.pos() - self._m_data = io.read_bytes(self.len_data) - self._debug['_m_data']['end'] = io.pos() - io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - class MinidumpString(KaitaiStruct): - """Specific string serialization scheme used in MiniDump format is - actually a simple 32-bit length-prefixed UTF-16 string. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680395(v=vs.85).aspx - """ - SEQ_FIELDS = ["len_str", "str"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_str']['start'] = self._io.pos() - self.len_str = self._io.read_u4le() - self._debug['len_str']['end'] = self._io.pos() - self._debug['str']['start'] = self._io.pos() - self.str = (self._io.read_bytes(self.len_str)).decode(u"UTF-16LE") - self._debug['str']['end'] = self._io.pos() - - - class SystemInfo(KaitaiStruct): - """"System info" stream provides basic information about the - hardware and operating system which produces this dump. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680396(v=vs.85).aspx - """ - - class CpuArchs(Enum): - intel = 0 - arm = 5 - ia64 = 6 - amd64 = 9 - unknown = 65535 - SEQ_FIELDS = ["cpu_arch", "cpu_level", "cpu_revision", "num_cpus", "os_type", "os_ver_major", "os_ver_minor", "os_build", "os_platform", "ofs_service_pack", "os_suite_mask", "reserved2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['cpu_arch']['start'] = self._io.pos() - self.cpu_arch = KaitaiStream.resolve_enum(self._root.SystemInfo.CpuArchs, self._io.read_u2le()) - self._debug['cpu_arch']['end'] = self._io.pos() - self._debug['cpu_level']['start'] = self._io.pos() - self.cpu_level = self._io.read_u2le() - self._debug['cpu_level']['end'] = self._io.pos() - self._debug['cpu_revision']['start'] = self._io.pos() - self.cpu_revision = self._io.read_u2le() - self._debug['cpu_revision']['end'] = self._io.pos() - self._debug['num_cpus']['start'] = self._io.pos() - self.num_cpus = self._io.read_u1() - self._debug['num_cpus']['end'] = self._io.pos() - self._debug['os_type']['start'] = self._io.pos() - self.os_type = self._io.read_u1() - self._debug['os_type']['end'] = self._io.pos() - self._debug['os_ver_major']['start'] = self._io.pos() - self.os_ver_major = self._io.read_u4le() - self._debug['os_ver_major']['end'] = self._io.pos() - self._debug['os_ver_minor']['start'] = self._io.pos() - self.os_ver_minor = self._io.read_u4le() - self._debug['os_ver_minor']['end'] = self._io.pos() - self._debug['os_build']['start'] = self._io.pos() - self.os_build = self._io.read_u4le() - self._debug['os_build']['end'] = self._io.pos() - self._debug['os_platform']['start'] = self._io.pos() - self.os_platform = self._io.read_u4le() - self._debug['os_platform']['end'] = self._io.pos() - self._debug['ofs_service_pack']['start'] = self._io.pos() - self.ofs_service_pack = self._io.read_u4le() - self._debug['ofs_service_pack']['end'] = self._io.pos() - self._debug['os_suite_mask']['start'] = self._io.pos() - self.os_suite_mask = self._io.read_u2le() - self._debug['os_suite_mask']['end'] = self._io.pos() - self._debug['reserved2']['start'] = self._io.pos() - self.reserved2 = self._io.read_u2le() - self._debug['reserved2']['end'] = self._io.pos() - - @property - def service_pack(self): - if hasattr(self, '_m_service_pack'): - return self._m_service_pack if hasattr(self, '_m_service_pack') else None - - if self.ofs_service_pack > 0: - io = self._root._io - _pos = io.pos() - io.seek(self.ofs_service_pack) - self._debug['_m_service_pack']['start'] = io.pos() - self._m_service_pack = self._root.MinidumpString(io, self, self._root) - self._m_service_pack._read() - self._debug['_m_service_pack']['end'] = io.pos() - io.seek(_pos) - - return self._m_service_pack if hasattr(self, '_m_service_pack') else None - - - class ExceptionRecord(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680367(v=vs.85).aspx - """ - SEQ_FIELDS = ["code", "flags", "inner_exception", "addr", "num_params", "reserved", "params"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = self._io.read_u4le() - self._debug['code']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u4le() - self._debug['flags']['end'] = self._io.pos() - self._debug['inner_exception']['start'] = self._io.pos() - self.inner_exception = self._io.read_u8le() - self._debug['inner_exception']['end'] = self._io.pos() - self._debug['addr']['start'] = self._io.pos() - self.addr = self._io.read_u8le() - self._debug['addr']['end'] = self._io.pos() - self._debug['num_params']['start'] = self._io.pos() - self.num_params = self._io.read_u4le() - self._debug['num_params']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u4le() - self._debug['reserved']['end'] = self._io.pos() - self._debug['params']['start'] = self._io.pos() - self.params = [None] * (15) - for i in range(15): - if not 'arr' in self._debug['params']: - self._debug['params']['arr'] = [] - self._debug['params']['arr'].append({'start': self._io.pos()}) - self.params[i] = self._io.read_u8le() - self._debug['params']['arr'][i]['end'] = self._io.pos() - - self._debug['params']['end'] = self._io.pos() - - - class MiscInfo(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680389(v=vs.85).aspx - """ - SEQ_FIELDS = ["len_info", "flags1", "process_id", "process_create_time", "process_user_time", "process_kernel_time", "cpu_max_mhz", "cpu_cur_mhz", "cpu_limit_mhz", "cpu_max_idle_state", "cpu_cur_idle_state"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_info']['start'] = self._io.pos() - self.len_info = self._io.read_u4le() - self._debug['len_info']['end'] = self._io.pos() - self._debug['flags1']['start'] = self._io.pos() - self.flags1 = self._io.read_u4le() - self._debug['flags1']['end'] = self._io.pos() - self._debug['process_id']['start'] = self._io.pos() - self.process_id = self._io.read_u4le() - self._debug['process_id']['end'] = self._io.pos() - self._debug['process_create_time']['start'] = self._io.pos() - self.process_create_time = self._io.read_u4le() - self._debug['process_create_time']['end'] = self._io.pos() - self._debug['process_user_time']['start'] = self._io.pos() - self.process_user_time = self._io.read_u4le() - self._debug['process_user_time']['end'] = self._io.pos() - self._debug['process_kernel_time']['start'] = self._io.pos() - self.process_kernel_time = self._io.read_u4le() - self._debug['process_kernel_time']['end'] = self._io.pos() - self._debug['cpu_max_mhz']['start'] = self._io.pos() - self.cpu_max_mhz = self._io.read_u4le() - self._debug['cpu_max_mhz']['end'] = self._io.pos() - self._debug['cpu_cur_mhz']['start'] = self._io.pos() - self.cpu_cur_mhz = self._io.read_u4le() - self._debug['cpu_cur_mhz']['end'] = self._io.pos() - self._debug['cpu_limit_mhz']['start'] = self._io.pos() - self.cpu_limit_mhz = self._io.read_u4le() - self._debug['cpu_limit_mhz']['end'] = self._io.pos() - self._debug['cpu_max_idle_state']['start'] = self._io.pos() - self.cpu_max_idle_state = self._io.read_u4le() - self._debug['cpu_max_idle_state']['end'] = self._io.pos() - self._debug['cpu_cur_idle_state']['start'] = self._io.pos() - self.cpu_cur_idle_state = self._io.read_u4le() - self._debug['cpu_cur_idle_state']['end'] = self._io.pos() - - - class Dir(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680365(v=vs.85).aspx - """ - SEQ_FIELDS = ["stream_type", "len_data", "ofs_data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['stream_type']['start'] = self._io.pos() - self.stream_type = KaitaiStream.resolve_enum(self._root.StreamTypes, self._io.read_u4le()) - self._debug['stream_type']['end'] = self._io.pos() - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u4le() - self._debug['len_data']['end'] = self._io.pos() - self._debug['ofs_data']['start'] = self._io.pos() - self.ofs_data = self._io.read_u4le() - self._debug['ofs_data']['end'] = self._io.pos() - - @property - def data(self): - if hasattr(self, '_m_data'): - return self._m_data if hasattr(self, '_m_data') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_data) - self._debug['_m_data']['start'] = self._io.pos() - _on = self.stream_type - if _on == self._root.StreamTypes.memory_list: - self._raw__m_data = self._io.read_bytes(self.len_data) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.MemoryList(io, self, self._root) - self._m_data._read() - elif _on == self._root.StreamTypes.misc_info: - self._raw__m_data = self._io.read_bytes(self.len_data) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.MiscInfo(io, self, self._root) - self._m_data._read() - elif _on == self._root.StreamTypes.thread_list: - self._raw__m_data = self._io.read_bytes(self.len_data) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.ThreadList(io, self, self._root) - self._m_data._read() - elif _on == self._root.StreamTypes.exception: - self._raw__m_data = self._io.read_bytes(self.len_data) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.ExceptionStream(io, self, self._root) - self._m_data._read() - elif _on == self._root.StreamTypes.system_info: - self._raw__m_data = self._io.read_bytes(self.len_data) - io = KaitaiStream(BytesIO(self._raw__m_data)) - self._m_data = self._root.SystemInfo(io, self, self._root) - self._m_data._read() - else: - self._m_data = self._io.read_bytes(self.len_data) - self._debug['_m_data']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_data if hasattr(self, '_m_data') else None - - - class Thread(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680517(v=vs.85).aspx - """ - SEQ_FIELDS = ["thread_id", "suspend_count", "priority_class", "priority", "teb", "stack", "thread_context"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['thread_id']['start'] = self._io.pos() - self.thread_id = self._io.read_u4le() - self._debug['thread_id']['end'] = self._io.pos() - self._debug['suspend_count']['start'] = self._io.pos() - self.suspend_count = self._io.read_u4le() - self._debug['suspend_count']['end'] = self._io.pos() - self._debug['priority_class']['start'] = self._io.pos() - self.priority_class = self._io.read_u4le() - self._debug['priority_class']['end'] = self._io.pos() - self._debug['priority']['start'] = self._io.pos() - self.priority = self._io.read_u4le() - self._debug['priority']['end'] = self._io.pos() - self._debug['teb']['start'] = self._io.pos() - self.teb = self._io.read_u8le() - self._debug['teb']['end'] = self._io.pos() - self._debug['stack']['start'] = self._io.pos() - self.stack = self._root.MemoryDescriptor(self._io, self, self._root) - self.stack._read() - self._debug['stack']['end'] = self._io.pos() - self._debug['thread_context']['start'] = self._io.pos() - self.thread_context = self._root.LocationDescriptor(self._io, self, self._root) - self.thread_context._read() - self._debug['thread_context']['end'] = self._io.pos() - - - class MemoryList(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680387(v=vs.85).aspx - """ - SEQ_FIELDS = ["num_mem_ranges", "mem_ranges"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_mem_ranges']['start'] = self._io.pos() - self.num_mem_ranges = self._io.read_u4le() - self._debug['num_mem_ranges']['end'] = self._io.pos() - self._debug['mem_ranges']['start'] = self._io.pos() - self.mem_ranges = [None] * (self.num_mem_ranges) - for i in range(self.num_mem_ranges): - if not 'arr' in self._debug['mem_ranges']: - self._debug['mem_ranges']['arr'] = [] - self._debug['mem_ranges']['arr'].append({'start': self._io.pos()}) - _t_mem_ranges = self._root.MemoryDescriptor(self._io, self, self._root) - _t_mem_ranges._read() - self.mem_ranges[i] = _t_mem_ranges - self._debug['mem_ranges']['arr'][i]['end'] = self._io.pos() - - self._debug['mem_ranges']['end'] = self._io.pos() - - - class MemoryDescriptor(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680384(v=vs.85).aspx - """ - SEQ_FIELDS = ["addr_memory_range", "memory"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['addr_memory_range']['start'] = self._io.pos() - self.addr_memory_range = self._io.read_u8le() - self._debug['addr_memory_range']['end'] = self._io.pos() - self._debug['memory']['start'] = self._io.pos() - self.memory = self._root.LocationDescriptor(self._io, self, self._root) - self.memory._read() - self._debug['memory']['end'] = self._io.pos() - - - class ExceptionStream(KaitaiStruct): - """ - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/ms680368(v=vs.85).aspx - """ - SEQ_FIELDS = ["thread_id", "reserved", "exception_rec", "thread_context"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['thread_id']['start'] = self._io.pos() - self.thread_id = self._io.read_u4le() - self._debug['thread_id']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u4le() - self._debug['reserved']['end'] = self._io.pos() - self._debug['exception_rec']['start'] = self._io.pos() - self.exception_rec = self._root.ExceptionRecord(self._io, self, self._root) - self.exception_rec._read() - self._debug['exception_rec']['end'] = self._io.pos() - self._debug['thread_context']['start'] = self._io.pos() - self.thread_context = self._root.LocationDescriptor(self._io, self, self._root) - self.thread_context._read() - self._debug['thread_context']['end'] = self._io.pos() - - - @property - def streams(self): - if hasattr(self, '_m_streams'): - return self._m_streams if hasattr(self, '_m_streams') else None - - _pos = self._io.pos() - self._io.seek(self.ofs_streams) - self._debug['_m_streams']['start'] = self._io.pos() - self._m_streams = [None] * (self.num_streams) - for i in range(self.num_streams): - if not 'arr' in self._debug['_m_streams']: - self._debug['_m_streams']['arr'] = [] - self._debug['_m_streams']['arr'].append({'start': self._io.pos()}) - _t__m_streams = self._root.Dir(self._io, self, self._root) - _t__m_streams._read() - self._m_streams[i] = _t__m_streams - self._debug['_m_streams']['arr'][i]['end'] = self._io.pos() - - self._debug['_m_streams']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_streams if hasattr(self, '_m_streams') else None - - diff --git a/python/examples/kaitai/windows_resource_file.py b/python/examples/kaitai/windows_resource_file.py deleted file mode 100644 index c18fd91b..00000000 --- a/python/examples/kaitai/windows_resource_file.py +++ /dev/null @@ -1,242 +0,0 @@ -# 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 -import collections -from enum import Enum - - -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 WindowsResourceFile(KaitaiStruct): - """Windows resource file (.res) are binary bundles of - "resources". Resource has some sort of ID (numerical or string), - type (predefined or user-defined), and raw value. Resource files can - be seen standalone (as .res file), or embedded inside PE executable - (.exe, .dll) files. - - Typical use cases include: - - * providing information about the application (such as title, copyrights, etc) - * embedding icon(s) to be displayed in file managers into .exe - * adding non-code data into the binary, such as menus, dialog forms, - cursor images, fonts, various misc bitmaps, and locale-aware - strings - - Windows provides special API to access "resources" from a binary. - - Normally, resources files are created with `rc` compiler: it takes a - .rc file (so called "resource-definition script") + all the raw - resource binary files for input, and outputs .res file. That .res - file can be linked into an .exe / .dll afterwards using a linker. - - Internally, resource file is just a sequence of individual resource - definitions. RC tool ensures that first resource (#0) is always - empty. - """ - SEQ_FIELDS = ["resources"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['resources']['start'] = self._io.pos() - self.resources = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['resources']: - self._debug['resources']['arr'] = [] - self._debug['resources']['arr'].append({'start': self._io.pos()}) - _t_resources = self._root.Resource(self._io, self, self._root) - _t_resources._read() - self.resources.append(_t_resources) - self._debug['resources']['arr'][len(self.resources) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['resources']['end'] = self._io.pos() - - class Resource(KaitaiStruct): - """Each resource has a `type` and a `name`, which can be used to - identify it, and a `value`. Both `type` and `name` can be a - number or a string. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/ms648027.aspx - """ - - class PredefTypes(Enum): - cursor = 1 - bitmap = 2 - icon = 3 - menu = 4 - dialog = 5 - string = 6 - fontdir = 7 - font = 8 - accelerator = 9 - rcdata = 10 - messagetable = 11 - group_cursor = 12 - group_icon = 14 - version = 16 - dlginclude = 17 - plugplay = 19 - vxd = 20 - anicursor = 21 - aniicon = 22 - html = 23 - manifest = 24 - SEQ_FIELDS = ["value_size", "header_size", "type", "name", "padding1", "format_version", "flags", "language", "value_version", "characteristics", "value", "padding2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['value_size']['start'] = self._io.pos() - self.value_size = self._io.read_u4le() - self._debug['value_size']['end'] = self._io.pos() - 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['type']['start'] = self._io.pos() - self.type = self._root.UnicodeOrId(self._io, self, self._root) - self.type._read() - self._debug['type']['end'] = self._io.pos() - self._debug['name']['start'] = self._io.pos() - self.name = self._root.UnicodeOrId(self._io, self, self._root) - self.name._read() - self._debug['name']['end'] = self._io.pos() - self._debug['padding1']['start'] = self._io.pos() - self.padding1 = self._io.read_bytes(((4 - self._io.pos()) % 4)) - self._debug['padding1']['end'] = self._io.pos() - self._debug['format_version']['start'] = self._io.pos() - self.format_version = self._io.read_u4le() - self._debug['format_version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['language']['start'] = self._io.pos() - self.language = self._io.read_u2le() - self._debug['language']['end'] = self._io.pos() - self._debug['value_version']['start'] = self._io.pos() - self.value_version = self._io.read_u4le() - self._debug['value_version']['end'] = self._io.pos() - self._debug['characteristics']['start'] = self._io.pos() - self.characteristics = self._io.read_u4le() - self._debug['characteristics']['end'] = self._io.pos() - self._debug['value']['start'] = self._io.pos() - self.value = self._io.read_bytes(self.value_size) - self._debug['value']['end'] = self._io.pos() - self._debug['padding2']['start'] = self._io.pos() - self.padding2 = self._io.read_bytes(((4 - self._io.pos()) % 4)) - self._debug['padding2']['end'] = self._io.pos() - - @property - def type_as_predef(self): - """Numeric type IDs in range of [0..0xff] are reserved for - system usage in Windows, and there are some predefined, - well-known values in that range. This instance allows to get - it as enum value, if applicable. - """ - if hasattr(self, '_m_type_as_predef'): - return self._m_type_as_predef if hasattr(self, '_m_type_as_predef') else None - - if ((not (self.type.is_string)) and (self.type.as_numeric <= 255)) : - self._m_type_as_predef = KaitaiStream.resolve_enum(self._root.Resource.PredefTypes, self.type.as_numeric) - - return self._m_type_as_predef if hasattr(self, '_m_type_as_predef') else None - - - class UnicodeOrId(KaitaiStruct): - """Resources use a special serialization of names and types: they - can be either a number or a string. - - Use `is_string` to check which kind we've got here, and then use - `as_numeric` or `as_string` to get relevant value. - """ - SEQ_FIELDS = ["first", "as_numeric", "rest", "noop"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - if self.save_pos1 >= 0: - self._debug['first']['start'] = self._io.pos() - self.first = self._io.read_u2le() - self._debug['first']['end'] = self._io.pos() - - if not (self.is_string): - self._debug['as_numeric']['start'] = self._io.pos() - self.as_numeric = self._io.read_u2le() - self._debug['as_numeric']['end'] = self._io.pos() - - if self.is_string: - self._debug['rest']['start'] = self._io.pos() - self.rest = [] - i = 0 - while True: - if not 'arr' in self._debug['rest']: - self._debug['rest']['arr'] = [] - self._debug['rest']['arr'].append({'start': self._io.pos()}) - _ = self._io.read_u2le() - self.rest.append(_) - self._debug['rest']['arr'][len(self.rest) - 1]['end'] = self._io.pos() - if _ == 0: - break - i += 1 - self._debug['rest']['end'] = self._io.pos() - - if ((self.is_string) and (self.save_pos2 >= 0)) : - self._debug['noop']['start'] = self._io.pos() - self.noop = self._io.read_bytes(0) - self._debug['noop']['end'] = self._io.pos() - - - @property - def save_pos1(self): - if hasattr(self, '_m_save_pos1'): - return self._m_save_pos1 if hasattr(self, '_m_save_pos1') else None - - self._m_save_pos1 = self._io.pos() - return self._m_save_pos1 if hasattr(self, '_m_save_pos1') else None - - @property - def save_pos2(self): - if hasattr(self, '_m_save_pos2'): - return self._m_save_pos2 if hasattr(self, '_m_save_pos2') else None - - self._m_save_pos2 = self._io.pos() - return self._m_save_pos2 if hasattr(self, '_m_save_pos2') else None - - @property - def is_string(self): - if hasattr(self, '_m_is_string'): - return self._m_is_string if hasattr(self, '_m_is_string') else None - - self._m_is_string = self.first != 65535 - return self._m_is_string if hasattr(self, '_m_is_string') else None - - @property - def as_string(self): - if hasattr(self, '_m_as_string'): - return self._m_as_string if hasattr(self, '_m_as_string') else None - - if self.is_string: - _pos = self._io.pos() - self._io.seek(self.save_pos1) - self._debug['_m_as_string']['start'] = self._io.pos() - self._m_as_string = (self._io.read_bytes(((self.save_pos2 - self.save_pos1) - 2))).decode(u"UTF-16LE") - self._debug['_m_as_string']['end'] = self._io.pos() - self._io.seek(_pos) - - return self._m_as_string if hasattr(self, '_m_as_string') else None - - - diff --git a/python/examples/kaitai/windows_shell_items.py b/python/examples/kaitai/windows_shell_items.py deleted file mode 100644 index 93a1ccbc..00000000 --- a/python/examples/kaitai/windows_shell_items.py +++ /dev/null @@ -1,189 +0,0 @@ -# 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 -import collections - - -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 WindowsShellItems(KaitaiStruct): - """Windows Shell Items (AKA "shellbags") is an undocumented set of - structures used internally within Windows to identify paths in - Windows Folder Hierarchy. It is widely used in Windows Shell (and - most visible in File Explorer), both as in-memory and in-file - structures. Some formats embed them, namely: - - * Windows Shell link files (.lnk) Windows registry - * Windows registry "ShellBags" keys - - The format is mostly undocumented, and is known to vary between - various Windows versions. - - .. seealso:: - Source - https://github.com/libyal/libfwsi/blob/master/documentation/Windows%20Shell%20Item%20format.asciidoc - """ - SEQ_FIELDS = ["items"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['items']['start'] = self._io.pos() - self.items = [] - i = 0 - while True: - if not 'arr' in self._debug['items']: - self._debug['items']['arr'] = [] - self._debug['items']['arr'].append({'start': self._io.pos()}) - _t_items = self._root.ShellItem(self._io, self, self._root) - _t_items._read() - _ = _t_items - self.items.append(_) - self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos() - if _.len_data == 0: - break - i += 1 - self._debug['items']['end'] = self._io.pos() - - class ShellItemData(KaitaiStruct): - SEQ_FIELDS = ["code", "body1", "body2"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = self._io.read_u1() - self._debug['code']['end'] = self._io.pos() - self._debug['body1']['start'] = self._io.pos() - _on = self.code - if _on == 31: - self.body1 = self._root.RootFolderBody(self._io, self, self._root) - self.body1._read() - self._debug['body1']['end'] = self._io.pos() - self._debug['body2']['start'] = self._io.pos() - _on = (self.code & 112) - if _on == 32: - self.body2 = self._root.VolumeBody(self._io, self, self._root) - self.body2._read() - elif _on == 48: - self.body2 = self._root.FileEntryBody(self._io, self, self._root) - self.body2._read() - self._debug['body2']['end'] = self._io.pos() - - - class ShellItem(KaitaiStruct): - """ - .. seealso:: - Section 2.2.2 - https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/[MS-SHLLINK].pdf - """ - SEQ_FIELDS = ["len_data", "data"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['len_data']['start'] = self._io.pos() - self.len_data = self._io.read_u2le() - self._debug['len_data']['end'] = self._io.pos() - if self.len_data >= 2: - self._debug['data']['start'] = self._io.pos() - self._raw_data = self._io.read_bytes((self.len_data - 2)) - io = KaitaiStream(BytesIO(self._raw_data)) - self.data = self._root.ShellItemData(io, self, self._root) - self.data._read() - self._debug['data']['end'] = self._io.pos() - - - - class RootFolderBody(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/libyal/libfwsi/blob/master/documentation/Windows%20Shell%20Item%20format.asciidoc#32-root-folder-shell-item - """ - SEQ_FIELDS = ["sort_index", "shell_folder_id"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sort_index']['start'] = self._io.pos() - self.sort_index = self._io.read_u1() - self._debug['sort_index']['end'] = self._io.pos() - self._debug['shell_folder_id']['start'] = self._io.pos() - self.shell_folder_id = self._io.read_bytes(16) - self._debug['shell_folder_id']['end'] = self._io.pos() - - - class VolumeBody(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/libyal/libfwsi/blob/master/documentation/Windows%20Shell%20Item%20format.asciidoc#33-volume-shell-item - """ - SEQ_FIELDS = ["flags"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - - - class FileEntryBody(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/libyal/libfwsi/blob/master/documentation/Windows%20Shell%20Item%20format.asciidoc#34-file-entry-shell-item - """ - SEQ_FIELDS = ["_unnamed0", "file_size", "last_mod_time", "file_attrs"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['_unnamed0']['start'] = self._io.pos() - self._unnamed0 = self._io.read_u1() - self._debug['_unnamed0']['end'] = self._io.pos() - self._debug['file_size']['start'] = self._io.pos() - self.file_size = self._io.read_u4le() - self._debug['file_size']['end'] = self._io.pos() - self._debug['last_mod_time']['start'] = self._io.pos() - self.last_mod_time = self._io.read_u4le() - self._debug['last_mod_time']['end'] = self._io.pos() - self._debug['file_attrs']['start'] = self._io.pos() - self.file_attrs = self._io.read_u2le() - self._debug['file_attrs']['end'] = self._io.pos() - - @property - def is_dir(self): - if hasattr(self, '_m_is_dir'): - return self._m_is_dir if hasattr(self, '_m_is_dir') else None - - self._m_is_dir = (self._parent.code & 1) != 0 - return self._m_is_dir if hasattr(self, '_m_is_dir') else None - - @property - def is_file(self): - if hasattr(self, '_m_is_file'): - return self._m_is_file if hasattr(self, '_m_is_file') else None - - self._m_is_file = (self._parent.code & 2) != 0 - return self._m_is_file if hasattr(self, '_m_is_file') else None - - - diff --git a/python/examples/kaitai/windows_systemtime.py b/python/examples/kaitai/windows_systemtime.py deleted file mode 100644 index 18823c8a..00000000 --- a/python/examples/kaitai/windows_systemtime.py +++ /dev/null @@ -1,51 +0,0 @@ -# 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 -import collections - - -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 WindowsSystemtime(KaitaiStruct): - """Microsoft Windows SYSTEMTIME structure, stores individual components - of date and time as individual fields, up to millisecond precision. - - .. seealso:: - Source - https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950.aspx - """ - SEQ_FIELDS = ["year", "month", "dow", "day", "hour", "min", "sec", "msec"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['year']['start'] = self._io.pos() - self.year = self._io.read_u2le() - self._debug['year']['end'] = self._io.pos() - self._debug['month']['start'] = self._io.pos() - self.month = self._io.read_u2le() - self._debug['month']['end'] = self._io.pos() - self._debug['dow']['start'] = self._io.pos() - self.dow = self._io.read_u2le() - self._debug['dow']['end'] = self._io.pos() - self._debug['day']['start'] = self._io.pos() - self.day = self._io.read_u2le() - self._debug['day']['end'] = self._io.pos() - self._debug['hour']['start'] = self._io.pos() - self.hour = self._io.read_u2le() - self._debug['hour']['end'] = self._io.pos() - self._debug['min']['start'] = self._io.pos() - self.min = self._io.read_u2le() - self._debug['min']['end'] = self._io.pos() - self._debug['sec']['start'] = self._io.pos() - self.sec = self._io.read_u2le() - self._debug['sec']['end'] = self._io.pos() - self._debug['msec']['start'] = self._io.pos() - self.msec = self._io.read_u2le() - self._debug['msec']['end'] = self._io.pos() - - diff --git a/python/examples/kaitai/wmf.py b/python/examples/kaitai/wmf.py deleted file mode 100644 index 6cb1c74e..00000000 --- a/python/examples/kaitai/wmf.py +++ /dev/null @@ -1,459 +0,0 @@ -# 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 -import collections - - -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 Wmf(KaitaiStruct): - """WMF (Windows Metafile) is a relatively early vector image format - introduced for Microsoft Windows in 1990. - - Inside, it provides a serialized list of Windows GDI (Graphics - Device Interface) function calls, which, if played back, result in - an image being drawn on a given surface (display, off-screen buffer, - printer, etc). - - .. seealso:: - Source - http://www.digitalpreservation.gov/formats/digformatspecs/WindowsMetafileFormat(wmf)Specification.pdf - """ - - class Func(Enum): - eof = 0 - savedc = 30 - realizepalette = 53 - setpalentries = 55 - createpalette = 247 - setbkmode = 258 - setmapmode = 259 - setrop2 = 260 - setrelabs = 261 - setpolyfillmode = 262 - setstretchbltmode = 263 - settextcharextra = 264 - restoredc = 295 - invertregion = 298 - paintregion = 299 - selectclipregion = 300 - selectobject = 301 - settextalign = 302 - resizepalette = 313 - dibcreatepatternbrush = 322 - setlayout = 329 - deleteobject = 496 - createpatternbrush = 505 - setbkcolor = 513 - settextcolor = 521 - settextjustification = 522 - setwindoworg = 523 - setwindowext = 524 - setviewportorg = 525 - setviewportext = 526 - offsetwindoworg = 527 - offsetviewportorg = 529 - lineto = 531 - moveto = 532 - offsetcliprgn = 544 - fillregion = 552 - setmapperflags = 561 - selectpalette = 564 - createpenindirect = 762 - createfontindirect = 763 - createbrushindirect = 764 - polygon = 804 - polyline = 805 - scalewindowext = 1040 - scaleviewportext = 1042 - excludecliprect = 1045 - intersectcliprect = 1046 - ellipse = 1048 - floodfill = 1049 - rectangle = 1051 - setpixel = 1055 - frameregion = 1065 - animatepalette = 1078 - textout = 1313 - polypolygon = 1336 - extfloodfill = 1352 - roundrect = 1564 - patblt = 1565 - escape = 1574 - createregion = 1791 - arc = 2071 - pie = 2074 - chord = 2096 - bitblt = 2338 - dibbitblt = 2368 - exttextout = 2610 - stretchblt = 2851 - dibstretchblt = 2881 - setdibtodev = 3379 - stretchdib = 3907 - - class BinRasterOp(Enum): - black = 1 - notmergepen = 2 - masknotpen = 3 - notcopypen = 4 - maskpennot = 5 - not_ = 6 - xorpen = 7 - notmaskpen = 8 - maskpen = 9 - notxorpen = 10 - nop = 11 - mergenotpen = 12 - copypen = 13 - mergepennot = 14 - mergepen = 15 - white = 16 - - class MixMode(Enum): - transparent = 1 - opaque = 2 - - class PolyFillMode(Enum): - alternate = 1 - winding = 2 - SEQ_FIELDS = ["special_header", "header", "records"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['special_header']['start'] = self._io.pos() - self.special_header = self._root.SpecialHeader(self._io, self, self._root) - self.special_header._read() - self._debug['special_header']['end'] = self._io.pos() - self._debug['header']['start'] = self._io.pos() - self.header = self._root.Header(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['records']['start'] = self._io.pos() - self.records = [] - i = 0 - while True: - if not 'arr' in self._debug['records']: - self._debug['records']['arr'] = [] - self._debug['records']['arr'].append({'start': self._io.pos()}) - _t_records = self._root.Record(self._io, self, self._root) - _t_records._read() - _ = _t_records - self.records.append(_) - self._debug['records']['arr'][len(self.records) - 1]['end'] = self._io.pos() - if _.function == self._root.Func.eof: - break - i += 1 - self._debug['records']['end'] = self._io.pos() - - class ParamsSetwindoworg(KaitaiStruct): - SEQ_FIELDS = ["y", "x"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - - - class ParamsSetbkmode(KaitaiStruct): - SEQ_FIELDS = ["bk_mode"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['bk_mode']['start'] = self._io.pos() - self.bk_mode = KaitaiStream.resolve_enum(self._root.MixMode, self._io.read_u2le()) - self._debug['bk_mode']['end'] = self._io.pos() - - - class PointS(KaitaiStruct): - SEQ_FIELDS = ["x", "y"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - - - class ParamsSetwindowext(KaitaiStruct): - SEQ_FIELDS = ["y", "x"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['y']['start'] = self._io.pos() - self.y = self._io.read_s2le() - self._debug['y']['end'] = self._io.pos() - self._debug['x']['start'] = self._io.pos() - self.x = self._io.read_s2le() - self._debug['x']['end'] = self._io.pos() - - - class ParamsPolygon(KaitaiStruct): - SEQ_FIELDS = ["num_points", "points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_points']['start'] = self._io.pos() - self.num_points = self._io.read_s2le() - self._debug['num_points']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.num_points) - for i in range(self.num_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.PointS(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - - - class Header(KaitaiStruct): - - class MetafileType(Enum): - memory_metafile = 1 - disk_metafile = 2 - SEQ_FIELDS = ["metafile_type", "header_size", "version", "size", "number_of_objects", "max_record", "number_of_members"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['metafile_type']['start'] = self._io.pos() - self.metafile_type = KaitaiStream.resolve_enum(self._root.Header.MetafileType, self._io.read_u2le()) - self._debug['metafile_type']['end'] = self._io.pos() - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_u2le() - self._debug['header_size']['end'] = self._io.pos() - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['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['number_of_objects']['start'] = self._io.pos() - self.number_of_objects = self._io.read_u2le() - self._debug['number_of_objects']['end'] = self._io.pos() - self._debug['max_record']['start'] = self._io.pos() - self.max_record = self._io.read_u4le() - self._debug['max_record']['end'] = self._io.pos() - self._debug['number_of_members']['start'] = self._io.pos() - self.number_of_members = self._io.read_u2le() - self._debug['number_of_members']['end'] = self._io.pos() - - - class ColorRef(KaitaiStruct): - SEQ_FIELDS = ["red", "green", "blue", "reserved"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['red']['start'] = self._io.pos() - self.red = self._io.read_u1() - self._debug['red']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._io.read_u1() - self._debug['green']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._io.read_u1() - self._debug['blue']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u1() - self._debug['reserved']['end'] = self._io.pos() - - - class ParamsSetrop2(KaitaiStruct): - SEQ_FIELDS = ["draw_mode"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['draw_mode']['start'] = self._io.pos() - self.draw_mode = KaitaiStream.resolve_enum(self._root.BinRasterOp, self._io.read_u2le()) - self._debug['draw_mode']['end'] = self._io.pos() - - - class ParamsSetpolyfillmode(KaitaiStruct): - SEQ_FIELDS = ["poly_fill_mode"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['poly_fill_mode']['start'] = self._io.pos() - self.poly_fill_mode = KaitaiStream.resolve_enum(self._root.PolyFillMode, self._io.read_u2le()) - self._debug['poly_fill_mode']['end'] = self._io.pos() - - - class ParamsPolyline(KaitaiStruct): - SEQ_FIELDS = ["num_points", "points"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['num_points']['start'] = self._io.pos() - self.num_points = self._io.read_s2le() - self._debug['num_points']['end'] = self._io.pos() - self._debug['points']['start'] = self._io.pos() - self.points = [None] * (self.num_points) - for i in range(self.num_points): - if not 'arr' in self._debug['points']: - self._debug['points']['arr'] = [] - self._debug['points']['arr'].append({'start': self._io.pos()}) - _t_points = self._root.PointS(self._io, self, self._root) - _t_points._read() - self.points[i] = _t_points - self._debug['points']['arr'][i]['end'] = self._io.pos() - - self._debug['points']['end'] = self._io.pos() - - - class SpecialHeader(KaitaiStruct): - SEQ_FIELDS = ["magic", "handle", "left", "top", "right", "bottom", "inch", "reserved", "checksum"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\xD7\xCD\xC6\x9A") - self._debug['magic']['end'] = self._io.pos() - self._debug['handle']['start'] = self._io.pos() - self.handle = self._io.ensure_fixed_contents(b"\x00\x00") - self._debug['handle']['end'] = self._io.pos() - self._debug['left']['start'] = self._io.pos() - self.left = self._io.read_s2le() - self._debug['left']['end'] = self._io.pos() - self._debug['top']['start'] = self._io.pos() - self.top = self._io.read_s2le() - self._debug['top']['end'] = self._io.pos() - self._debug['right']['start'] = self._io.pos() - self.right = self._io.read_s2le() - self._debug['right']['end'] = self._io.pos() - self._debug['bottom']['start'] = self._io.pos() - self.bottom = self._io.read_s2le() - self._debug['bottom']['end'] = self._io.pos() - self._debug['inch']['start'] = self._io.pos() - self.inch = self._io.read_u2le() - self._debug['inch']['end'] = self._io.pos() - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.ensure_fixed_contents(b"\x00\x00\x00\x00") - self._debug['reserved']['end'] = self._io.pos() - self._debug['checksum']['start'] = self._io.pos() - self.checksum = self._io.read_u2le() - self._debug['checksum']['end'] = self._io.pos() - - - class Record(KaitaiStruct): - SEQ_FIELDS = ["size", "function", "params"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u4le() - self._debug['size']['end'] = self._io.pos() - self._debug['function']['start'] = self._io.pos() - self.function = KaitaiStream.resolve_enum(self._root.Func, self._io.read_u2le()) - self._debug['function']['end'] = self._io.pos() - self._debug['params']['start'] = self._io.pos() - _on = self.function - if _on == self._root.Func.setbkmode: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsSetbkmode(io, self, self._root) - self.params._read() - elif _on == self._root.Func.polygon: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsPolygon(io, self, self._root) - self.params._read() - elif _on == self._root.Func.setbkcolor: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ColorRef(io, self, self._root) - self.params._read() - elif _on == self._root.Func.setpolyfillmode: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsSetpolyfillmode(io, self, self._root) - self.params._read() - elif _on == self._root.Func.setwindoworg: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsSetwindoworg(io, self, self._root) - self.params._read() - elif _on == self._root.Func.setrop2: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsSetrop2(io, self, self._root) - self.params._read() - elif _on == self._root.Func.setwindowext: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsSetwindowext(io, self, self._root) - self.params._read() - elif _on == self._root.Func.polyline: - self._raw_params = self._io.read_bytes(((self.size - 3) * 2)) - io = KaitaiStream(BytesIO(self._raw_params)) - self.params = self._root.ParamsPolyline(io, self, self._root) - self.params._read() - else: - self.params = self._io.read_bytes(((self.size - 3) * 2)) - self._debug['params']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/xwd.py b/python/examples/kaitai/xwd.py deleted file mode 100644 index 93dfb534..00000000 --- a/python/examples/kaitai/xwd.py +++ /dev/null @@ -1,188 +0,0 @@ -# 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 -import collections - - -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 Xwd(KaitaiStruct): - """xwd is a file format written by eponymous X11 screen capture - application (xwd stands for "X Window Dump"). Typically, an average - user transforms xwd format into something more widespread by any of - `xwdtopnm` and `pnmto...` utilities right away. - - xwd format itself provides a raw uncompressed bitmap with some - metainformation, like pixel format, width, height, bit depth, - etc. Note that technically format includes machine-dependent fields - and thus is probably a poor choice for true cross-platform usage. - """ - - class PixmapFormat(Enum): - x_y_bitmap = 0 - x_y_pixmap = 1 - z_pixmap = 2 - - class ByteOrder(Enum): - le = 0 - be = 1 - - class VisualClass(Enum): - static_gray = 0 - gray_scale = 1 - static_color = 2 - pseudo_color = 3 - true_color = 4 - direct_color = 5 - SEQ_FIELDS = ["header_size", "hdr", "color_map"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header_size']['start'] = self._io.pos() - self.header_size = self._io.read_u4be() - self._debug['header_size']['end'] = self._io.pos() - self._debug['hdr']['start'] = self._io.pos() - self._raw_hdr = self._io.read_bytes((self.header_size - 4)) - io = KaitaiStream(BytesIO(self._raw_hdr)) - self.hdr = self._root.Header(io, self, self._root) - self.hdr._read() - self._debug['hdr']['end'] = self._io.pos() - self._debug['color_map']['start'] = self._io.pos() - self._raw_color_map = [None] * (self.hdr.color_map_entries) - self.color_map = [None] * (self.hdr.color_map_entries) - for i in range(self.hdr.color_map_entries): - if not 'arr' in self._debug['color_map']: - self._debug['color_map']['arr'] = [] - self._debug['color_map']['arr'].append({'start': self._io.pos()}) - self._raw_color_map[i] = self._io.read_bytes(12) - io = KaitaiStream(BytesIO(self._raw_color_map[i])) - _t_color_map = self._root.ColorMapEntry(io, self, self._root) - _t_color_map._read() - self.color_map[i] = _t_color_map - self._debug['color_map']['arr'][i]['end'] = self._io.pos() - - self._debug['color_map']['end'] = self._io.pos() - - class Header(KaitaiStruct): - SEQ_FIELDS = ["file_version", "pixmap_format", "pixmap_depth", "pixmap_width", "pixmap_height", "x_offset", "byte_order", "bitmap_unit", "bitmap_bit_order", "bitmap_pad", "bits_per_pixel", "bytes_per_line", "visual_class", "red_mask", "green_mask", "blue_mask", "bits_per_rgb", "number_of_colors", "color_map_entries", "window_width", "window_height", "window_x", "window_y", "window_border_width", "creator"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['file_version']['start'] = self._io.pos() - self.file_version = self._io.read_u4be() - self._debug['file_version']['end'] = self._io.pos() - self._debug['pixmap_format']['start'] = self._io.pos() - self.pixmap_format = KaitaiStream.resolve_enum(self._root.PixmapFormat, self._io.read_u4be()) - self._debug['pixmap_format']['end'] = self._io.pos() - self._debug['pixmap_depth']['start'] = self._io.pos() - self.pixmap_depth = self._io.read_u4be() - self._debug['pixmap_depth']['end'] = self._io.pos() - self._debug['pixmap_width']['start'] = self._io.pos() - self.pixmap_width = self._io.read_u4be() - self._debug['pixmap_width']['end'] = self._io.pos() - self._debug['pixmap_height']['start'] = self._io.pos() - self.pixmap_height = self._io.read_u4be() - self._debug['pixmap_height']['end'] = self._io.pos() - self._debug['x_offset']['start'] = self._io.pos() - self.x_offset = self._io.read_u4be() - self._debug['x_offset']['end'] = self._io.pos() - self._debug['byte_order']['start'] = self._io.pos() - self.byte_order = KaitaiStream.resolve_enum(self._root.ByteOrder, self._io.read_u4be()) - self._debug['byte_order']['end'] = self._io.pos() - self._debug['bitmap_unit']['start'] = self._io.pos() - self.bitmap_unit = self._io.read_u4be() - self._debug['bitmap_unit']['end'] = self._io.pos() - self._debug['bitmap_bit_order']['start'] = self._io.pos() - self.bitmap_bit_order = self._io.read_u4be() - self._debug['bitmap_bit_order']['end'] = self._io.pos() - self._debug['bitmap_pad']['start'] = self._io.pos() - self.bitmap_pad = self._io.read_u4be() - self._debug['bitmap_pad']['end'] = self._io.pos() - self._debug['bits_per_pixel']['start'] = self._io.pos() - self.bits_per_pixel = self._io.read_u4be() - self._debug['bits_per_pixel']['end'] = self._io.pos() - self._debug['bytes_per_line']['start'] = self._io.pos() - self.bytes_per_line = self._io.read_u4be() - self._debug['bytes_per_line']['end'] = self._io.pos() - self._debug['visual_class']['start'] = self._io.pos() - self.visual_class = KaitaiStream.resolve_enum(self._root.VisualClass, self._io.read_u4be()) - self._debug['visual_class']['end'] = self._io.pos() - self._debug['red_mask']['start'] = self._io.pos() - self.red_mask = self._io.read_u4be() - self._debug['red_mask']['end'] = self._io.pos() - self._debug['green_mask']['start'] = self._io.pos() - self.green_mask = self._io.read_u4be() - self._debug['green_mask']['end'] = self._io.pos() - self._debug['blue_mask']['start'] = self._io.pos() - self.blue_mask = self._io.read_u4be() - self._debug['blue_mask']['end'] = self._io.pos() - self._debug['bits_per_rgb']['start'] = self._io.pos() - self.bits_per_rgb = self._io.read_u4be() - self._debug['bits_per_rgb']['end'] = self._io.pos() - self._debug['number_of_colors']['start'] = self._io.pos() - self.number_of_colors = self._io.read_u4be() - self._debug['number_of_colors']['end'] = self._io.pos() - self._debug['color_map_entries']['start'] = self._io.pos() - self.color_map_entries = self._io.read_u4be() - self._debug['color_map_entries']['end'] = self._io.pos() - self._debug['window_width']['start'] = self._io.pos() - self.window_width = self._io.read_u4be() - self._debug['window_width']['end'] = self._io.pos() - self._debug['window_height']['start'] = self._io.pos() - self.window_height = self._io.read_u4be() - self._debug['window_height']['end'] = self._io.pos() - self._debug['window_x']['start'] = self._io.pos() - self.window_x = self._io.read_s4be() - self._debug['window_x']['end'] = self._io.pos() - self._debug['window_y']['start'] = self._io.pos() - self.window_y = self._io.read_s4be() - self._debug['window_y']['end'] = self._io.pos() - self._debug['window_border_width']['start'] = self._io.pos() - self.window_border_width = self._io.read_u4be() - self._debug['window_border_width']['end'] = self._io.pos() - self._debug['creator']['start'] = self._io.pos() - self.creator = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8") - self._debug['creator']['end'] = self._io.pos() - - - class ColorMapEntry(KaitaiStruct): - SEQ_FIELDS = ["entry_number", "red", "green", "blue", "flags", "padding"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['entry_number']['start'] = self._io.pos() - self.entry_number = self._io.read_u4be() - self._debug['entry_number']['end'] = self._io.pos() - self._debug['red']['start'] = self._io.pos() - self.red = self._io.read_u2be() - self._debug['red']['end'] = self._io.pos() - self._debug['green']['start'] = self._io.pos() - self.green = self._io.read_u2be() - self._debug['green']['end'] = self._io.pos() - self._debug['blue']['start'] = self._io.pos() - self.blue = self._io.read_u2be() - self._debug['blue']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['padding']['start'] = self._io.pos() - self.padding = self._io.read_u1() - self._debug['padding']['end'] = self._io.pos() - - - diff --git a/python/examples/kaitai/zip.py b/python/examples/kaitai/zip.py deleted file mode 100644 index 9fe85264..00000000 --- a/python/examples/kaitai/zip.py +++ /dev/null @@ -1,502 +0,0 @@ -# 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 -import collections - - -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 Zip(KaitaiStruct): - """ - .. seealso:: - Source - https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT - """ - - class Compression(Enum): - none = 0 - shrunk = 1 - reduced_1 = 2 - reduced_2 = 3 - reduced_3 = 4 - reduced_4 = 5 - imploded = 6 - deflated = 8 - enhanced_deflated = 9 - pkware_dcl_imploded = 10 - bzip2 = 12 - lzma = 14 - ibm_terse = 18 - ibm_lz77_z = 19 - ppmd = 98 - - class ExtraCodes(Enum): - zip64 = 1 - av_info = 7 - os2 = 9 - ntfs = 10 - openvms = 12 - pkware_unix = 13 - file_stream_and_fork_descriptors = 14 - patch_descriptor = 15 - pkcs7 = 20 - x509_cert_id_and_signature_for_file = 21 - x509_cert_id_for_central_dir = 22 - strong_encryption_header = 23 - record_management_controls = 24 - pkcs7_enc_recip_cert_list = 25 - ibm_s390_uncomp = 101 - ibm_s390_comp = 102 - poszip_4690 = 18064 - extended_timestamp = 21589 - infozip_unix = 30805 - infozip_unix_var_size = 30837 - SEQ_FIELDS = ["sections"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['sections']['start'] = self._io.pos() - self.sections = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['sections']: - self._debug['sections']['arr'] = [] - self._debug['sections']['arr'].append({'start': self._io.pos()}) - _t_sections = self._root.PkSection(self._io, self, self._root) - _t_sections._read() - self.sections.append(_t_sections) - self._debug['sections']['arr'][len(self.sections) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['sections']['end'] = self._io.pos() - - class LocalFile(KaitaiStruct): - SEQ_FIELDS = ["header", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['header']['start'] = self._io.pos() - self.header = self._root.LocalFileHeader(self._io, self, self._root) - self.header._read() - self._debug['header']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - self.body = self._io.read_bytes(self.header.compressed_size) - self._debug['body']['end'] = self._io.pos() - - - class ExtraField(KaitaiStruct): - SEQ_FIELDS = ["code", "size", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['code']['start'] = self._io.pos() - self.code = KaitaiStream.resolve_enum(self._root.ExtraCodes, self._io.read_u2le()) - self._debug['code']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u2le() - self._debug['size']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.code - if _on == self._root.ExtraCodes.ntfs: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ExtraField.Ntfs(io, self, self._root) - self.body._read() - elif _on == self._root.ExtraCodes.extended_timestamp: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ExtraField.ExtendedTimestamp(io, self, self._root) - self.body._read() - elif _on == self._root.ExtraCodes.infozip_unix_var_size: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ExtraField.InfozipUnixVarSize(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.size) - self._debug['body']['end'] = self._io.pos() - - class Ntfs(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/LuaDist/zip/blob/master/proginfo/extrafld.txt#L191 - """ - SEQ_FIELDS = ["reserved", "attributes"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['reserved']['start'] = self._io.pos() - self.reserved = self._io.read_u4le() - self._debug['reserved']['end'] = self._io.pos() - self._debug['attributes']['start'] = self._io.pos() - self.attributes = [] - i = 0 - while not self._io.is_eof(): - if not 'arr' in self._debug['attributes']: - self._debug['attributes']['arr'] = [] - self._debug['attributes']['arr'].append({'start': self._io.pos()}) - _t_attributes = self._root.ExtraField.Ntfs.Attribute(self._io, self, self._root) - _t_attributes._read() - self.attributes.append(_t_attributes) - self._debug['attributes']['arr'][len(self.attributes) - 1]['end'] = self._io.pos() - i += 1 - - self._debug['attributes']['end'] = self._io.pos() - - class Attribute(KaitaiStruct): - SEQ_FIELDS = ["tag", "size", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['tag']['start'] = self._io.pos() - self.tag = self._io.read_u2le() - self._debug['tag']['end'] = self._io.pos() - self._debug['size']['start'] = self._io.pos() - self.size = self._io.read_u2le() - self._debug['size']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.tag - if _on == 1: - self._raw_body = self._io.read_bytes(self.size) - io = KaitaiStream(BytesIO(self._raw_body)) - self.body = self._root.ExtraField.Ntfs.Attribute1(io, self, self._root) - self.body._read() - else: - self.body = self._io.read_bytes(self.size) - self._debug['body']['end'] = self._io.pos() - - - class Attribute1(KaitaiStruct): - SEQ_FIELDS = ["last_mod_time", "last_access_time", "creation_time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['last_mod_time']['start'] = self._io.pos() - self.last_mod_time = self._io.read_u8le() - self._debug['last_mod_time']['end'] = self._io.pos() - self._debug['last_access_time']['start'] = self._io.pos() - self.last_access_time = self._io.read_u8le() - self._debug['last_access_time']['end'] = self._io.pos() - self._debug['creation_time']['start'] = self._io.pos() - self.creation_time = self._io.read_u8le() - self._debug['creation_time']['end'] = self._io.pos() - - - - class ExtendedTimestamp(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/LuaDist/zip/blob/master/proginfo/extrafld.txt#L817 - """ - SEQ_FIELDS = ["flags", "mod_time", "access_time", "create_time"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u1() - self._debug['flags']['end'] = self._io.pos() - self._debug['mod_time']['start'] = self._io.pos() - self.mod_time = self._io.read_u4le() - self._debug['mod_time']['end'] = self._io.pos() - if not (self._io.is_eof()): - self._debug['access_time']['start'] = self._io.pos() - self.access_time = self._io.read_u4le() - self._debug['access_time']['end'] = self._io.pos() - - if not (self._io.is_eof()): - self._debug['create_time']['start'] = self._io.pos() - self.create_time = self._io.read_u4le() - self._debug['create_time']['end'] = self._io.pos() - - - - class InfozipUnixVarSize(KaitaiStruct): - """ - .. seealso:: - Source - https://github.com/LuaDist/zip/blob/master/proginfo/extrafld.txt#L1339 - """ - SEQ_FIELDS = ["version", "uid_size", "uid", "gid_size", "gid"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u1() - self._debug['version']['end'] = self._io.pos() - self._debug['uid_size']['start'] = self._io.pos() - self.uid_size = self._io.read_u1() - self._debug['uid_size']['end'] = self._io.pos() - self._debug['uid']['start'] = self._io.pos() - self.uid = self._io.read_bytes(self.uid_size) - self._debug['uid']['end'] = self._io.pos() - self._debug['gid_size']['start'] = self._io.pos() - self.gid_size = self._io.read_u1() - self._debug['gid_size']['end'] = self._io.pos() - self._debug['gid']['start'] = self._io.pos() - self.gid = self._io.read_bytes(self.gid_size) - self._debug['gid']['end'] = self._io.pos() - - - - class CentralDirEntry(KaitaiStruct): - """ - .. seealso:: - - 4.3.12 - https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT - """ - SEQ_FIELDS = ["version_made_by", "version_needed_to_extract", "flags", "compression_method", "last_mod_file_time", "last_mod_file_date", "crc32", "compressed_size", "uncompressed_size", "file_name_len", "extra_len", "comment_len", "disk_number_start", "int_file_attr", "ext_file_attr", "local_header_offset", "file_name", "extra", "comment"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version_made_by']['start'] = self._io.pos() - self.version_made_by = self._io.read_u2le() - self._debug['version_made_by']['end'] = self._io.pos() - self._debug['version_needed_to_extract']['start'] = self._io.pos() - self.version_needed_to_extract = self._io.read_u2le() - self._debug['version_needed_to_extract']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.Compression, self._io.read_u2le()) - self._debug['compression_method']['end'] = self._io.pos() - self._debug['last_mod_file_time']['start'] = self._io.pos() - self.last_mod_file_time = self._io.read_u2le() - self._debug['last_mod_file_time']['end'] = self._io.pos() - self._debug['last_mod_file_date']['start'] = self._io.pos() - self.last_mod_file_date = self._io.read_u2le() - self._debug['last_mod_file_date']['end'] = self._io.pos() - self._debug['crc32']['start'] = self._io.pos() - self.crc32 = self._io.read_u4le() - self._debug['crc32']['end'] = self._io.pos() - self._debug['compressed_size']['start'] = self._io.pos() - self.compressed_size = self._io.read_u4le() - self._debug['compressed_size']['end'] = self._io.pos() - self._debug['uncompressed_size']['start'] = self._io.pos() - self.uncompressed_size = self._io.read_u4le() - self._debug['uncompressed_size']['end'] = self._io.pos() - self._debug['file_name_len']['start'] = self._io.pos() - self.file_name_len = self._io.read_u2le() - self._debug['file_name_len']['end'] = self._io.pos() - self._debug['extra_len']['start'] = self._io.pos() - self.extra_len = self._io.read_u2le() - self._debug['extra_len']['end'] = self._io.pos() - self._debug['comment_len']['start'] = self._io.pos() - self.comment_len = self._io.read_u2le() - self._debug['comment_len']['end'] = self._io.pos() - self._debug['disk_number_start']['start'] = self._io.pos() - self.disk_number_start = self._io.read_u2le() - self._debug['disk_number_start']['end'] = self._io.pos() - self._debug['int_file_attr']['start'] = self._io.pos() - self.int_file_attr = self._io.read_u2le() - self._debug['int_file_attr']['end'] = self._io.pos() - self._debug['ext_file_attr']['start'] = self._io.pos() - self.ext_file_attr = self._io.read_u4le() - self._debug['ext_file_attr']['end'] = self._io.pos() - self._debug['local_header_offset']['start'] = self._io.pos() - self.local_header_offset = self._io.read_s4le() - self._debug['local_header_offset']['end'] = self._io.pos() - self._debug['file_name']['start'] = self._io.pos() - self.file_name = (self._io.read_bytes(self.file_name_len)).decode(u"UTF-8") - self._debug['file_name']['end'] = self._io.pos() - self._debug['extra']['start'] = self._io.pos() - self._raw_extra = self._io.read_bytes(self.extra_len) - io = KaitaiStream(BytesIO(self._raw_extra)) - self.extra = self._root.Extras(io, self, self._root) - self.extra._read() - self._debug['extra']['end'] = self._io.pos() - self._debug['comment']['start'] = self._io.pos() - self.comment = (self._io.read_bytes(self.comment_len)).decode(u"UTF-8") - self._debug['comment']['end'] = self._io.pos() - - @property - def local_header(self): - if hasattr(self, '_m_local_header'): - return self._m_local_header if hasattr(self, '_m_local_header') else None - - _pos = self._io.pos() - self._io.seek(self.local_header_offset) - self._debug['_m_local_header']['start'] = self._io.pos() - self._m_local_header = self._root.PkSection(self._io, self, self._root) - self._m_local_header._read() - self._debug['_m_local_header']['end'] = self._io.pos() - self._io.seek(_pos) - return self._m_local_header if hasattr(self, '_m_local_header') else None - - - class PkSection(KaitaiStruct): - SEQ_FIELDS = ["magic", "section_type", "body"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['magic']['start'] = self._io.pos() - self.magic = self._io.ensure_fixed_contents(b"\x50\x4B") - self._debug['magic']['end'] = self._io.pos() - self._debug['section_type']['start'] = self._io.pos() - self.section_type = self._io.read_u2le() - self._debug['section_type']['end'] = self._io.pos() - self._debug['body']['start'] = self._io.pos() - _on = self.section_type - if _on == 513: - self.body = self._root.CentralDirEntry(self._io, self, self._root) - self.body._read() - elif _on == 1027: - self.body = self._root.LocalFile(self._io, self, self._root) - self.body._read() - elif _on == 1541: - self.body = self._root.EndOfCentralDir(self._io, self, self._root) - self.body._read() - self._debug['body']['end'] = self._io.pos() - - - class Extras(KaitaiStruct): - SEQ_FIELDS = ["entries"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - 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 = self._root.ExtraField(self._io, self, self._root) - _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() - - - class LocalFileHeader(KaitaiStruct): - SEQ_FIELDS = ["version", "flags", "compression_method", "file_mod_time", "file_mod_date", "crc32", "compressed_size", "uncompressed_size", "file_name_len", "extra_len", "file_name", "extra"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['version']['start'] = self._io.pos() - self.version = self._io.read_u2le() - self._debug['version']['end'] = self._io.pos() - self._debug['flags']['start'] = self._io.pos() - self.flags = self._io.read_u2le() - self._debug['flags']['end'] = self._io.pos() - self._debug['compression_method']['start'] = self._io.pos() - self.compression_method = KaitaiStream.resolve_enum(self._root.Compression, self._io.read_u2le()) - self._debug['compression_method']['end'] = self._io.pos() - self._debug['file_mod_time']['start'] = self._io.pos() - self.file_mod_time = self._io.read_u2le() - self._debug['file_mod_time']['end'] = self._io.pos() - self._debug['file_mod_date']['start'] = self._io.pos() - self.file_mod_date = self._io.read_u2le() - self._debug['file_mod_date']['end'] = self._io.pos() - self._debug['crc32']['start'] = self._io.pos() - self.crc32 = self._io.read_u4le() - self._debug['crc32']['end'] = self._io.pos() - self._debug['compressed_size']['start'] = self._io.pos() - self.compressed_size = self._io.read_u4le() - self._debug['compressed_size']['end'] = self._io.pos() - self._debug['uncompressed_size']['start'] = self._io.pos() - self.uncompressed_size = self._io.read_u4le() - self._debug['uncompressed_size']['end'] = self._io.pos() - self._debug['file_name_len']['start'] = self._io.pos() - self.file_name_len = self._io.read_u2le() - self._debug['file_name_len']['end'] = self._io.pos() - self._debug['extra_len']['start'] = self._io.pos() - self.extra_len = self._io.read_u2le() - self._debug['extra_len']['end'] = self._io.pos() - self._debug['file_name']['start'] = self._io.pos() - self.file_name = (self._io.read_bytes(self.file_name_len)).decode(u"UTF-8") - self._debug['file_name']['end'] = self._io.pos() - self._debug['extra']['start'] = self._io.pos() - self._raw_extra = self._io.read_bytes(self.extra_len) - io = KaitaiStream(BytesIO(self._raw_extra)) - self.extra = self._root.Extras(io, self, self._root) - self.extra._read() - self._debug['extra']['end'] = self._io.pos() - - - class EndOfCentralDir(KaitaiStruct): - SEQ_FIELDS = ["disk_of_end_of_central_dir", "disk_of_central_dir", "qty_central_dir_entries_on_disk", "qty_central_dir_entries_total", "central_dir_size", "central_dir_offset", "comment_len", "comment"] - def __init__(self, _io, _parent=None, _root=None): - self._io = _io - self._parent = _parent - self._root = _root if _root else self - self._debug = collections.defaultdict(dict) - - def _read(self): - self._debug['disk_of_end_of_central_dir']['start'] = self._io.pos() - self.disk_of_end_of_central_dir = self._io.read_u2le() - self._debug['disk_of_end_of_central_dir']['end'] = self._io.pos() - self._debug['disk_of_central_dir']['start'] = self._io.pos() - self.disk_of_central_dir = self._io.read_u2le() - self._debug['disk_of_central_dir']['end'] = self._io.pos() - self._debug['qty_central_dir_entries_on_disk']['start'] = self._io.pos() - self.qty_central_dir_entries_on_disk = self._io.read_u2le() - self._debug['qty_central_dir_entries_on_disk']['end'] = self._io.pos() - self._debug['qty_central_dir_entries_total']['start'] = self._io.pos() - self.qty_central_dir_entries_total = self._io.read_u2le() - self._debug['qty_central_dir_entries_total']['end'] = self._io.pos() - self._debug['central_dir_size']['start'] = self._io.pos() - self.central_dir_size = self._io.read_u4le() - self._debug['central_dir_size']['end'] = self._io.pos() - self._debug['central_dir_offset']['start'] = self._io.pos() - self.central_dir_offset = self._io.read_u4le() - self._debug['central_dir_offset']['end'] = self._io.pos() - self._debug['comment_len']['start'] = self._io.pos() - self.comment_len = self._io.read_u2le() - self._debug['comment_len']['end'] = self._io.pos() - self._debug['comment']['start'] = self._io.pos() - self.comment = (self._io.read_bytes(self.comment_len)).decode(u"UTF-8") - self._debug['comment']['end'] = self._io.pos() - - - -- cgit v1.3.1