Exemple #1
0
    def _OpenPathSpec(self, path_spec, ascii_codepage=u'cp1252'):
        """Opens the Windows Registry file specificed by the path specification.

    Args:
      path_spec: a path specfication (instance of dfvfs.PathSpec).
      ascii_codepage: optional ASCII string codepage. The default is cp1252
                      (or windows-1252).

    Returns:
      The Windows Registry file (instance of WinRegistryFile) or None.
    """
        if not path_spec:
            return

        file_entry = self._searcher.GetFileEntryByPathSpec(path_spec)
        if file_entry is None:
            return

        file_object = file_entry.GetFileObject()
        if file_object is None:
            return

        registry_file = regf.REGFWinRegistryFile(ascii_codepage=ascii_codepage)
        try:
            registry_file.Open(file_object)
        except IOError as exception:
            logging.warning(
                u'Unable to open Windows Registry file with error: {0:s}'.
                format(exception))
            file_object.close()
            return

        return registry_file
Exemple #2
0
    def _OpenREGFRegistryFile(self, filename):
        """Opens a REGF Windows Registry file.

    Args:
      filename: the name of the file relative to the test file path.

    Returns:
      The Windows Registry file object (instance of REGFWinRegistryFileTest) or
      None.
    """
        test_file = self._GetTestFilePath([filename])
        file_entry = self._GetTestFileEntry(test_file)
        file_object = file_entry.GetFileObject()

        registry_file = regf.REGFWinRegistryFile()
        registry_file.Open(file_object)

        return registry_file
Exemple #3
0
    def Open(self, file_object, ascii_codepage=u'cp1252'):
        """Opens a Windows Registry file-like object.

    Args:
      file_object: the Windows Registry file-like object.
      ascii_codepage: optional ASCII string codepage.

    Returns:
      The Windows Registry file (instance of WinRegistryFile) or None.
    """
        registry_file = dfwinreg_regf.REGFWinRegistryFile(
            ascii_codepage=ascii_codepage)

        # We don't catch any IOErrors here since we want to produce a parse error
        # from the parser if this happens.
        registry_file.Open(file_object)

        return registry_file
Exemple #4
0
    def OpenFileEntry(self, file_entry):
        """Opens a Windows Registry file entry.

    Args:
      file_entry: the file entry (instance of dfvfs.FileEntry).

    Returns:
      A corresponding Windows Registry file object (instance of
      WinRegistryFile) or None if not available.
    """
        registry_file = regf.REGFWinRegistryFile()
        file_object = file_entry.GetFileObject()

        try:
            registry_file.Open(file_object)
        except IOError:
            file_object.close()
            registry_file = None

        return registry_file
Exemple #5
0
  def Open(self, path, ascii_codepage=u'cp1252'):
    """Opens the Windows Registry file specified by the path.

    Args:
      path: the path of the Windows Registry file.
      ascii_codepage: optional ASCII string codepage.

    Returns:
      The Windows Registry file (instance of WinRegistryFile) or None.
    """
    registry_file = regf.REGFWinRegistryFile(ascii_codepage=ascii_codepage)
    file_object = open(path, 'rb')
    try:
      # If open is successful Registry file will manage the file object.
      registry_file.Open(file_object)
    except IOError:
      file_object.close()
      registry_file = None

    return registry_file
Exemple #6
0
    def Open(self, file_object, ascii_codepage=u'cp1252'):
        """Opens a Windows Registry file-like object.

    Args:
      file_object: the Windows Registry file-like object.
      ascii_codepage: optional ASCII string codepage. The default is cp1252
                      (or windows-1252).

    Returns:
      The Windows Registry file (instance of WinRegistryFile) or None.
    """
        registry_file = regf.REGFWinRegistryFile(ascii_codepage=ascii_codepage)
        try:
            registry_file.Open(file_object)
        except IOError as exception:
            logging.warning(
                u'Unable to open Windows Registry file with error: {0:s}'.
                format(exception))
            return

        return registry_file