Ejemplo n.º 1
0
  def __init__(self, key_path=''):
    """Initializes a Windows Registry key.

    Args:
      key_path (Optional[str]): Windows Registry key path.
    """
    super(WinRegistryKey, self).__init__()
    self._key_path = key_paths.JoinKeyPath([key_path])
Ejemplo n.º 2
0
    def GetSubkeys(self):
        """Retrieves all subkeys within the key.

    Yields:
      WinRegistryKey: Windows Registry subkey.
    """
        for pyregf_key in self._pyregf_key.sub_keys:
            key_path = key_paths.JoinKeyPath([self._key_path, pyregf_key.name])
            yield REGFWinRegistryKey(pyregf_key, key_path=key_path)
Ejemplo n.º 3
0
    def GetSubkeyByPath(self, key_path):
        """Retrieves a subkey by path.

    Args:
      key_path (str): path of the subkey.

    Returns:
      WinRegistryKey: Windows Registry subkey or None if not found.
    """
        pyregf_key = self._pyregf_key.get_sub_key_by_path(key_path)
        if not pyregf_key:
            return None

        key_path = key_paths.JoinKeyPath([self._key_path, key_path])
        return REGFWinRegistryKey(pyregf_key, key_path=key_path)
Ejemplo n.º 4
0
    def GetSubkeyByName(self, name):
        """Retrieves a subkey by name.

    Args:
      name (str): name of the subkey.

    Returns:
      WinRegistryKey: Windows Registry subkey or None if not found.
    """
        pyregf_key = self._pyregf_key.get_sub_key_by_name(name)
        if not pyregf_key:
            return None

        key_path = key_paths.JoinKeyPath([self._key_path, pyregf_key.name])
        return REGFWinRegistryKey(pyregf_key, key_path=key_path)
Ejemplo n.º 5
0
  def AddSubkey(self, registry_key):
    """Adds a subkey.

    Args:
      registry_key (WinRegistryKey): Windows Registry subkey.

    Raises:
      KeyError: if the subkey already exists.
    """
    name = registry_key.name.upper()
    if name in self._subkeys:
      raise KeyError(
          'Subkey: {0:s} already exists.'.format(registry_key.name))

    self._subkeys[name] = registry_key

    key_path = key_paths.JoinKeyPath([self._key_path, registry_key.name])
    registry_key._key_path = key_path  # pylint: disable=protected-access
Ejemplo n.º 6
0
    def GetSubkeyByIndex(self, index):
        """Retrieves a subkey by index.

    Args:
      index (int): index of the subkey.

    Returns:
      WinRegistryKey: Windows Registry subkey or None if not found.

    Raises:
      IndexError: if the index is out of bounds.
    """
        if index < 0 or index >= self._pyregf_key.number_of_sub_keys:
            raise IndexError('Index out of bounds.')

        pyregf_key = self._pyregf_key.get_sub_key(index)
        if not pyregf_key:
            return None

        key_path = key_paths.JoinKeyPath([self._key_path, pyregf_key.name])
        return REGFWinRegistryKey(pyregf_key, key_path=key_path)
Ejemplo n.º 7
0
  def _BuildKeyHierarchy(self, subkeys, values):
    """Builds the Windows Registry key hierarchy.

    Args:
      subkeys (list[FakeWinRegistryKey]): list of subkeys.
      values (list[FakeWinRegistryValue]): list of values.
    """
    if subkeys:
      for registry_key in subkeys:
        name = registry_key.name.upper()
        if name in self._subkeys:
          continue
        self._subkeys[name] = registry_key

        # pylint: disable=protected-access
        registry_key._key_path = key_paths.JoinKeyPath([
            self._key_path, registry_key.name])

    if values:
      for registry_value in values:
        name = registry_value.name.upper()
        if name in self._values:
          continue
        self._values[name] = registry_value