Exemple #1
0
    def get_key(self, key_path):
        if self.partial_hive_path:
            if key_path.startswith(self.partial_hive_path):
                key_path = key_path.partition(self.partial_hive_path)[-1]
            else:
                raise RegistryKeyNotFoundException(
                    f'Did not find subkey at {key_path}, because this is a partial hive'
                )

        logger.debug('Getting key: {}'.format(key_path))

        if key_path == '\\':
            return self.root

        key_path_parts = key_path.split('\\')[1:]
        previous_key_name = []

        subkey = self.root.get_key(key_path_parts.pop(0))

        if not subkey:
            raise RegistryKeyNotFoundException(
                'Did not find subkey at {}'.format(key_path))

        if not key_path_parts:
            return subkey

        for path_part in key_path_parts:
            new_path = '\\'.join(previous_key_name)
            previous_key_name.append(subkey.name)
            subkey = subkey.get_key(path_part)

            if not subkey:
                raise RegistryKeyNotFoundException(
                    'Did not find {} at {}'.format(path_part, new_path))
        return subkey
Exemple #2
0
    def get_key(self, key_path):
        logger.debug('Getting key: {}'.format(key_path))

        if key_path == '\\':
            return self.root

        key_path_parts = key_path.split('\\')[1:]
        previous_key_name = ['root']

        subkey = self.root.get_key(key_path_parts.pop(0))

        if not subkey:
            raise RegistryKeyNotFoundException(
                'Did not find subkey at {}'.format(key_path))

        if not key_path_parts:
            return subkey

        for path_part in key_path_parts:
            new_path = '\\'.join(previous_key_name)
            previous_key_name.append(subkey.name)
            subkey = subkey.get_key(path_part)

            if not subkey:
                raise RegistryKeyNotFoundException(
                    'Did not find {} at {}'.format(path_part, new_path))
        return subkey