Exemple #1
0
    def read_object(self, debug_string: str = '') -> Optional[Object]:
        """
        Creates and reads a new object from the stream
        """
        guid = self.read_guid(debug_string)
        res = REGISTRY.create_object(guid)
        if res is not None:
            self.log('** {} **'.format(res.__class__.__name__), 16)
        else:
            self.log('{} not found'.format(debug_string), 16)

        if res is not None:
            self.debug_depth += 1

            version = 1
            compatible_versions = res.compatible_versions()
            if compatible_versions is not None:
                version = self.read_ushort('version')
                if version not in res.compatible_versions():
                    supported_versions = ','.join(
                        [str(v) for v in res.compatible_versions()])
                    raise UnsupportedVersionException(
                        'Cannot read {} version {}, only support version(s): {}'
                        .format(res.__class__.__name__, version,
                                supported_versions))

            res.read(self, version)
            self.log('ended {}'.format(res.__class__.__name__))
            if self.debug:
                print('')
            self.debug_depth -= 1

        return res
Exemple #2
0
    def check_handle(self, file_handle):
        try:
            guid_bin = binascii.hexlify(file_handle.read(16))
            guid = REGISTRY.hex_to_guid(guid_bin)

            # check first in unimplemented types
            if guid in REGISTRY.NOT_IMPLEMENTED_GUIDS:
                return GuidCodeMatch(file_handle.tell() - 16, 16, REGISTRY.NOT_IMPLEMENTED_GUIDS[guid])

            obj = REGISTRY.create_object(guid)
            if obj is None:
                return None
            return GuidCodeMatch(file_handle.tell() - 16, 16, str(obj.__class__.__name__))
        except:  # nopep8, pylint: disable=bare-except
            pass
        return None