コード例 #1
0
    def test_params_def(self):
        io = KaitaiStream(open("src/term_strz.bin", "rb"))
        r = ParamsDef(5, True, io, None, None)

        self.assertEqual(r.buf, "foo|b")
        self.assertEqual(r.trailer, 0x61)

        io.close()
コード例 #2
0
def read_entries(data, start_offset=0):
    # Inspired by: https://stackoverflow.com/questions/49699820/parsing-binary-messages-with-kaitai-struct-python
    stream = KaitaiStream(BytesIO(data))
    stream.seek(start_offset)
    last = stream.pos()
    start = ModelSxLog(stream)
    log_entry = start.log_entry
    yield log_entry
    n_entries = 1
    with tqdm(total=stream.size() - start_offset,
              unit='B',
              unit_scale=True,
              desc='Processing log') as pbar:
        while not stream.is_eof():
            if n_entries % 1000 == 0:
                consumed = stream.pos() - last
                pbar.update(consumed)
                last = stream.pos()
            try:
                log_entry = ModelSxLog.Entry(stream, _root=start._root)
                if sum(log_entry.raw_bytes) % 256 != 0:
                    print(
                        f'Checksum error at {stream.pos()}, seeking to the next entry...'
                    )
                    stream.read_bytes_term(0xaa,
                                           include_term=False,
                                           consume_term=False,
                                           eos_error=True)
                else:
                    yield log_entry
            except ValidationNotEqualError:
                print(
                    f'Encountered an error at {stream.pos()}, probably a corrupt entry, seeking to next one...'
                )
                stream.read_bytes_term(0xaa,
                                       include_term=False,
                                       consume_term=False,
                                       eos_error=True)
                pass
            n_entries += 1
        pbar.update(stream.pos() - last)
        stream.close()
コード例 #3
0
 def _read(self):
     self._debug['draw_mode']['start'] = self._io.pos()
     self.draw_mode = KaitaiStream.resolve_enum(Wmf.BinRasterOp, self._io.read_u2le())
     self._debug['draw_mode']['end'] = self._io.pos()
コード例 #4
0
        raise Exception("Database doesn't exist")

    env = lmdb.open(filename, subdir=False, max_dbs=100)

    # Accounts table
    # Print details about the first N accounts with balance
    if args.table == 'all' or args.table == 'accounts':
        print_header('accounts')
        accounts_db = env.open_db('accounts'.encode())

        count = 0
        with env.begin() as txn:
            cursor = txn.cursor(accounts_db)
            for key, value in cursor:

                keystream = KaitaiStream(io.BytesIO(key))
                valstream = KaitaiStream(io.BytesIO(value))

                account_key = Nanodb.AccountsKey(keystream)
                account_info = Nanodb.AccountsValue(valstream)

                balance = nanolib.blocks.parse_hex_balance(
                    account_info.balance.hex().upper())

                if balance > 0:
                    print('account          : {}'.format(
                        nanolib.accounts.get_account_id(
                            prefix=nanolib.AccountIDPrefix.NANO,
                            public_key=account_key.account.hex())))
                    print('  head block     : {}'.format(
                        account_info.head.hex().upper()))
コード例 #5
0
 def _read(self):
     self.len_all = self._io.read_u4le()
     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)
コード例 #6
0
 def _read(self):
     self.len_all = self._io.read_u4le()
     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)
コード例 #7
0
    Gbr1.Gbr1Object.Type.map_property_data: parse_object_map_property_data,
    Gbr1.Gbr1Object.Type.map_default_property_value:
    parse_object_map_default_property_value,
    Gbr1.Gbr1Object.Type.map_settings: parse_object_map_settings,
    Gbr1.Gbr1Object.Type.map_property_colors: parse_object_map_property_colors,
    Gbr1.Gbr1Object.Type.map_export_settings: parse_object_map_export_settings,
    Gbr1.Gbr1Object.Type.map_export_properties:
    parse_object_map_export_properties,
}


def dump_gbr_file(file):
    print(gbr1.magic)
    for gbr_object in gbr1.objects:
        print('Type: %s, ID: %d' %
              (gbr_object.object_type, gbr_object.object_id))
        print('Size: %d' % gbr_object.object_length)
        if gbr_object.object_type in body_parsers:
            body_parsers[gbr_object.object_type](gbr_object.body)
        print('')


if __name__ == '__main__':
    files = ['buttons_unpressed.gbm', 'bg.gbm']
    #files = ['bg.gbm']
    for filename in files:
        with open('test/%s' % filename, 'rb') as fin:
            gbr1 = Gbr1(KaitaiStream(fin))
            dump_gbr_file(gbr1)
        print('---' * 10)
コード例 #8
0
 def _read(self):
     self.reference_kind = KaitaiStream.resolve_enum(
         JavaClass.MethodHandleCpInfo.ReferenceKindEnum,
         self._io.read_u1())
     self.reference_index = self._io.read_u2be()
コード例 #9
0
 def _read(self):
     self._debug['type']['start'] = self._io.pos()
     self.type = KaitaiStream.resolve_enum(BtrfsStream.Attribute,
                                           self._io.read_u2le())
     self._debug['type']['end'] = self._io.pos()
     self._debug['length']['start'] = self._io.pos()
     self.length = self._io.read_u2le()
     self._debug['length']['end'] = self._io.pos()
     self._debug['value']['start'] = self._io.pos()
     _on = self.type
     if _on == BtrfsStream.Attribute.ctransid:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.size:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.clone_uuid:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Uuid(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.file_offset:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.otime:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Timespec(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.uid:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.atime:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Timespec(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.ctime:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Timespec(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.uuid:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Uuid(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.clone_len:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.xattr_name:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.String(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.clone_ctransid:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.mode:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.mtime:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.Timespec(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.path_link:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.String(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.rdev:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.path_to:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.String(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.path:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.String(
             _io__raw_value, self, self._root)
         self.value._read()
     elif _on == BtrfsStream.Attribute.clone_offset:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.gid:
         self.value = self._io.read_u8le()
     elif _on == BtrfsStream.Attribute.clone_path:
         self._raw_value = self._io.read_bytes(self.length)
         _io__raw_value = KaitaiStream(BytesIO(self._raw_value))
         self.value = BtrfsStream.SendCommand.String(
             _io__raw_value, self, self._root)
         self.value._read()
     else:
         self.value = self._io.read_bytes(self.length)
     self._debug['value']['end'] = self._io.pos()
コード例 #10
0
 def _read(self):
     self.name = (KaitaiStream.bytes_terminate(self._io.read_bytes(72),
                                               0,
                                               False)).decode(u"ASCII")
     self.ofs_body = self._io.read_u4le()
     self.len_body = self._io.read_u4le()
コード例 #11
0
        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.read_bytes(2)
            self._debug['magic']['end'] = self._io.pos()
            if not self.magic == b"\x53\xEF":
                raise kaitaistruct.ValidationNotEqualError(b"\x53\xEF", self.magic, self._io, u"/types/super_block_struct/seq/15")
            self._debug['state']['start'] = self._io.pos()
            self.state = KaitaiStream.resolve_enum(Ext2.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(Ext2.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()
コード例 #12
0
 def _read(self):
     self.string_magic = self._io.ensure_fixed_contents(b"\x73")
     self.length = self._io.read_u4le()
     self._raw_items = self._io.read_bytes(self.length)
     io = KaitaiStream(BytesIO(self._raw_items))
     self.items = self._root.OpArgs(io, self, self._root)
コード例 #13
0
 def _read(self):
     self._raw_dir = self._io.read_bytes(self.dir_size)
     _io__raw_dir = KaitaiStream(BytesIO(self._raw_dir))
     self.dir = Dune2Pak.Files(_io__raw_dir, self, self._root)
コード例 #14
0
def parse(hcdBin):
    if isinstance(hcdBin, (bytes, bytearray)):
        iO = BytesIO(hcdBin)
    return BluetoothHcd(BluetoothVendorsIds.Vendor.cypress_semiconductor,
                        KaitaiStream(iO))
コード例 #15
0
        def _read(self):
            self._debug['code']['start'] = self._io.pos()
            self.code = self._io.read_bytes(4)
            self._debug['code']['end'] = self._io.pos()
            if not self.code == b"\x01\x00\x00\x00":
                raise kaitaistruct.ValidationNotEqualError(
                    b"\x01\x00\x00\x00", self.code, self._io,
                    u"/types/list_with_header/seq/0")
            self._debug['header_size']['start'] = self._io.pos()
            self.header_size = self._io.read_u4le()
            self._debug['header_size']['end'] = self._io.pos()
            self._debug['library_id_stamp']['start'] = self._io.pos()
            self.library_id_stamp = self._io.read_u4le()
            self._debug['library_id_stamp']['end'] = self._io.pos()
            self._debug['header']['start'] = self._io.pos()
            _on = self._parent.code
            if _on == RenderwareBinaryStream.Sections.geometry:
                self._raw_header = self._io.read_bytes(self.header_size)
                _io__raw_header = KaitaiStream(BytesIO(self._raw_header))
                self.header = RenderwareBinaryStream.StructGeometry(
                    _io__raw_header, self, self._root)
                self.header._read()
            elif _on == RenderwareBinaryStream.Sections.texture_dictionary:
                self._raw_header = self._io.read_bytes(self.header_size)
                _io__raw_header = KaitaiStream(BytesIO(self._raw_header))
                self.header = RenderwareBinaryStream.StructTextureDictionary(
                    _io__raw_header, self, self._root)
                self.header._read()
            elif _on == RenderwareBinaryStream.Sections.geometry_list:
                self._raw_header = self._io.read_bytes(self.header_size)
                _io__raw_header = KaitaiStream(BytesIO(self._raw_header))
                self.header = RenderwareBinaryStream.StructGeometryList(
                    _io__raw_header, self, self._root)
                self.header._read()
            elif _on == RenderwareBinaryStream.Sections.clump:
                self._raw_header = self._io.read_bytes(self.header_size)
                _io__raw_header = KaitaiStream(BytesIO(self._raw_header))
                self.header = RenderwareBinaryStream.StructClump(
                    _io__raw_header, self, self._root)
                self.header._read()
            elif _on == RenderwareBinaryStream.Sections.frame_list:
                self._raw_header = self._io.read_bytes(self.header_size)
                _io__raw_header = KaitaiStream(BytesIO(self._raw_header))
                self.header = RenderwareBinaryStream.StructFrameList(
                    _io__raw_header, self, self._root)
                self.header._read()
            else:
                self.header = self._io.read_bytes(self.header_size)
            self._debug['header']['end'] = self._io.pos()
            self._debug['entries']['start'] = self._io.pos()
            self.entries = []
            i = 0
            while not self._io.is_eof():
                if not 'arr' in self._debug['entries']:
                    self._debug['entries']['arr'] = []
                self._debug['entries']['arr'].append({'start': self._io.pos()})
                _t_entries = RenderwareBinaryStream(self._io)
                _t_entries._read()
                self.entries.append(_t_entries)
                self._debug['entries']['arr'][len(self.entries) -
                                              1]['end'] = self._io.pos()
                i += 1

            self._debug['entries']['end'] = self._io.pos()
コード例 #16
0
 def _read(self):
     self.size = self._io.read_u2le()
     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)
コード例 #17
0
ファイル: usbmon.py プロジェクト: vaginessa/USBPcapOdinDumper
 def _read(self):
     self._raw_header = self._io.read_bytes(self.header_size)
     io = KaitaiStream(BytesIO(self._raw_header))
     self.header = self._root.Header(io, self, self._root)
     self.data = self._io.read_bytes(self.header.data_size)
コード例 #18
0
 def __init__(self, raw_client_hello):
     self._client_hello = tls_client_hello.TlsClientHello(
         KaitaiStream(io.BytesIO(raw_client_hello)))
コード例 #19
0
    def _read(self):
        self._debug['magic']['start'] = self._io.pos()
        self.magic = self._io.read_bytes(8)
        self._debug['magic']['end'] = self._io.pos()
        if not self.magic == b"\x41\x4E\x44\x52\x4F\x49\x44\x21":
            raise kaitaistruct.ValidationNotEqualError(
                b"\x41\x4E\x44\x52\x4F\x49\x44\x21", self.magic, self._io,
                u"/seq/0")
        self._debug['kernel']['start'] = self._io.pos()
        self.kernel = AndroidImg.Load(self._io, self, self._root)
        self.kernel._read()
        self._debug['kernel']['end'] = self._io.pos()
        self._debug['ramdisk']['start'] = self._io.pos()
        self.ramdisk = AndroidImg.Load(self._io, self, self._root)
        self.ramdisk._read()
        self._debug['ramdisk']['end'] = self._io.pos()
        self._debug['second']['start'] = self._io.pos()
        self.second = AndroidImg.Load(self._io, self, self._root)
        self.second._read()
        self._debug['second']['end'] = self._io.pos()
        self._debug['tags_load']['start'] = self._io.pos()
        self.tags_load = self._io.read_u4le()
        self._debug['tags_load']['end'] = self._io.pos()
        self._debug['page_size']['start'] = self._io.pos()
        self.page_size = self._io.read_u4le()
        self._debug['page_size']['end'] = self._io.pos()
        self._debug['header_version']['start'] = self._io.pos()
        self.header_version = self._io.read_u4le()
        self._debug['header_version']['end'] = self._io.pos()
        self._debug['os_version']['start'] = self._io.pos()
        self.os_version = AndroidImg.OsVersion(self._io, self, self._root)
        self.os_version._read()
        self._debug['os_version']['end'] = self._io.pos()
        self._debug['name']['start'] = self._io.pos()
        self.name = (KaitaiStream.bytes_terminate(self._io.read_bytes(16), 0,
                                                  False)).decode(u"ASCII")
        self._debug['name']['end'] = self._io.pos()
        self._debug['cmdline']['start'] = self._io.pos()
        self.cmdline = (KaitaiStream.bytes_terminate(self._io.read_bytes(512),
                                                     0,
                                                     False)).decode(u"ASCII")
        self._debug['cmdline']['end'] = self._io.pos()
        self._debug['sha']['start'] = self._io.pos()
        self.sha = self._io.read_bytes(32)
        self._debug['sha']['end'] = self._io.pos()
        self._debug['extra_cmdline']['start'] = self._io.pos()
        self.extra_cmdline = (KaitaiStream.bytes_terminate(
            self._io.read_bytes(1024), 0, False)).decode(u"ASCII")
        self._debug['extra_cmdline']['end'] = self._io.pos()
        if self.header_version > 0:
            self._debug['recovery_dtbo']['start'] = self._io.pos()
            self.recovery_dtbo = AndroidImg.SizeOffset(self._io, self,
                                                       self._root)
            self.recovery_dtbo._read()
            self._debug['recovery_dtbo']['end'] = self._io.pos()

        if self.header_version > 0:
            self._debug['boot_header_size']['start'] = self._io.pos()
            self.boot_header_size = self._io.read_u4le()
            self._debug['boot_header_size']['end'] = self._io.pos()

        if self.header_version > 1:
            self._debug['dtb']['start'] = self._io.pos()
            self.dtb = AndroidImg.LoadLong(self._io, self, self._root)
            self.dtb._read()
            self._debug['dtb']['end'] = self._io.pos()
コード例 #20
0
 def _read(self):
     self.len_subfields = self._io.read_u2le()
     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)
コード例 #21
0
 def _read(self):
     self._debug['file_code']['start'] = self._io.pos()
     self.file_code = self._io.read_bytes(4)
     self._debug['file_code']['end'] = self._io.pos()
     if not self.file_code == b"\x00\x00\x27\x0A":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x27\x0A", self.file_code, self._io,
             u"/types/file_header/seq/0")
     self._debug['unused_field_1']['start'] = self._io.pos()
     self.unused_field_1 = self._io.read_bytes(4)
     self._debug['unused_field_1']['end'] = self._io.pos()
     if not self.unused_field_1 == b"\x00\x00\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x00\x00", self.unused_field_1, self._io,
             u"/types/file_header/seq/1")
     self._debug['unused_field_2']['start'] = self._io.pos()
     self.unused_field_2 = self._io.read_bytes(4)
     self._debug['unused_field_2']['end'] = self._io.pos()
     if not self.unused_field_2 == b"\x00\x00\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x00\x00", self.unused_field_2, self._io,
             u"/types/file_header/seq/2")
     self._debug['unused_field_3']['start'] = self._io.pos()
     self.unused_field_3 = self._io.read_bytes(4)
     self._debug['unused_field_3']['end'] = self._io.pos()
     if not self.unused_field_3 == b"\x00\x00\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x00\x00", self.unused_field_3, self._io,
             u"/types/file_header/seq/3")
     self._debug['unused_field_4']['start'] = self._io.pos()
     self.unused_field_4 = self._io.read_bytes(4)
     self._debug['unused_field_4']['end'] = self._io.pos()
     if not self.unused_field_4 == b"\x00\x00\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x00\x00", self.unused_field_4, self._io,
             u"/types/file_header/seq/4")
     self._debug['unused_field_5']['start'] = self._io.pos()
     self.unused_field_5 = self._io.read_bytes(4)
     self._debug['unused_field_5']['end'] = self._io.pos()
     if not self.unused_field_5 == b"\x00\x00\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\x00\x00\x00\x00", self.unused_field_5, self._io,
             u"/types/file_header/seq/5")
     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.read_bytes(4)
     self._debug['version']['end'] = self._io.pos()
     if not self.version == b"\xE8\x03\x00\x00":
         raise kaitaistruct.ValidationNotEqualError(
             b"\xE8\x03\x00\x00", self.version, self._io,
             u"/types/file_header/seq/7")
     self._debug['shape_type']['start'] = self._io.pos()
     self.shape_type = KaitaiStream.resolve_enum(
         ShapefileMain.ShapeType, self._io.read_s4le())
     self._debug['shape_type']['end'] = self._io.pos()
     self._debug['bounding_box']['start'] = self._io.pos()
     self.bounding_box = ShapefileMain.BoundingBoxXYZM(
         self._io, self, self._root)
     self.bounding_box._read()
     self._debug['bounding_box']['end'] = self._io.pos()
コード例 #22
0
 def _read(self):
     self.len_header = self._io.read_u4le()
     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)
コード例 #23
0
 def _read(self):
     self._debug['shape_type']['start'] = self._io.pos()
     self.shape_type = KaitaiStream.resolve_enum(
         ShapefileMain.ShapeType, self._io.read_s4le())
     self._debug['shape_type']['end'] = self._io.pos()
     if self.shape_type != ShapefileMain.ShapeType.null_shape:
         self._debug['shape_parameters']['start'] = self._io.pos()
         _on = self.shape_type
         if _on == ShapefileMain.ShapeType.poly_line_z:
             self.shape_parameters = ShapefileMain.PolyLineZ(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.multi_patch:
             self.shape_parameters = ShapefileMain.MultiPatch(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.poly_line_m:
             self.shape_parameters = ShapefileMain.PolyLineM(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.polygon:
             self.shape_parameters = ShapefileMain.Polygon(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.polygon_z:
             self.shape_parameters = ShapefileMain.PolygonZ(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.point_z:
             self.shape_parameters = ShapefileMain.PointZ(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.poly_line:
             self.shape_parameters = ShapefileMain.PolyLine(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.point_m:
             self.shape_parameters = ShapefileMain.PointM(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.polygon_m:
             self.shape_parameters = ShapefileMain.PolygonM(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.multi_point:
             self.shape_parameters = ShapefileMain.MultiPoint(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.point:
             self.shape_parameters = ShapefileMain.Point(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.multi_point_m:
             self.shape_parameters = ShapefileMain.MultiPointM(
                 self._io, self, self._root)
             self.shape_parameters._read()
         elif _on == ShapefileMain.ShapeType.multi_point_z:
             self.shape_parameters = ShapefileMain.MultiPointZ(
                 self._io, self, self._root)
             self.shape_parameters._read()
         self._debug['shape_parameters']['end'] = self._io.pos()
コード例 #24
0
 def _read(self):
     self.len_id_list = self._io.read_u2le()
     self._raw_id_list = self._io.read_bytes(self.len_id_list)
     io = KaitaiStream(BytesIO(self._raw_id_list))
     self.id_list = WindowsShellItems(io)
コード例 #25
0
        def _read(self):
            self._debug['bounding_box']['start'] = self._io.pos()
            self.bounding_box = ShapefileMain.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(
                    ShapefileMain.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 = ShapefileMain.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 = ShapefileMain.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 = ShapefileMain.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()
コード例 #26
0
 def _read(self):
     self._debug['bk_mode']['start'] = self._io.pos()
     self.bk_mode = KaitaiStream.resolve_enum(Wmf.MixMode, self._io.read_u2le())
     self._debug['bk_mode']['end'] = self._io.pos()
コード例 #27
0
 def _read(self):
     self.entries_count = self._io.read_u4le()
     self.entries_size = self._io.read_u4le()
     self._raw_entries = self._io.read_bytes(self.entries_size)
     io = KaitaiStream(BytesIO(self._raw_entries))
     self.entries = self._root.FileEntries(io, self, self._root)
コード例 #28
0
 def _read(self):
     self._debug['poly_fill_mode']['start'] = self._io.pos()
     self.poly_fill_mode = KaitaiStream.resolve_enum(Wmf.PolyFillMode, self._io.read_u2le())
     self._debug['poly_fill_mode']['end'] = self._io.pos()
コード例 #29
0
    Gbr0.Gbr0Object.Type.producer: parse_object_producer,
    Gbr0.Gbr0Object.Type.tile_data: parse_object_tile_data,
    Gbr0.Gbr0Object.Type.tile_settings: parse_object_tile_settings,
    Gbr0.Gbr0Object.Type.tile_export: parse_object_tile_export,
    Gbr0.Gbr0Object.Type.tile_import: parse_object_tile_import,
    Gbr0.Gbr0Object.Type.palettes: parse_object_palettes,
    Gbr0.Gbr0Object.Type.tile_pal: parse_object_tile_pal,
    Gbr0.Gbr0Object.Type.deleted: parse_object_deleted,
}


def dump_gbr_file(file):
    print(gbr0.magic)
    for gbr_object in gbr0.objects:
        print('Type: %s, ID: %d' %
              (gbr_object.object_type, gbr_object.object_id))
        print('Size: %d' % gbr_object.record_length)
        body_parsers[gbr_object.object_type](gbr_object.body)
        print('')


if __name__ == '__main__':
    files = [
        '8x8.gbr', 'alpha.gbr', 'digits.gbr', 'shaded_alpha.gbr', 'shadow.gbr'
    ]
    for filename in files:
        with open('test/%s' % filename, 'rb') as fin:
            gbr0 = Gbr0(KaitaiStream(fin))
            dump_gbr_file(gbr0)
        print('---' * 10)
コード例 #30
0
 def _read(self):
     self.len_data = self._io.read_u2le()
     if self.len_data >= 2:
         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)
コード例 #31
0
ファイル: pure_gse.py プロジェクト: ssloxford/gsextract
 def _read(self):
     self.gse_header = self._root.GseHeader(self._io, self, self._root)
     if not (self.gse_header.is_padding_packet):
         self._raw_gse_payload = self._io.read_bytes(((self.gse_header.payload_size - 2) if self.gse_header.payload_size > 2 else self.gse_header.payload_size))
         io = KaitaiStream(BytesIO(self._raw_gse_payload))
         self.gse_payload = self._root.GsePayload(io, self, self._root)