How to use the dfvfs.lib.errors function in dfvfs

To help you get started, we’ve selected a few dfvfs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github log2timeline / dfvfs / tests / resolver_helpers / test_lib.py View on Github external
def _TestNewFileSystemRaisesNotSupported(self, resolver_helper_object):
    """Tests the NewFileSystem function raises NotSupported.

    Args:
      resolver_helper_object (ResolverHelper): resolver helper.
    """
    with self.assertRaises(errors.NotSupported):
      resolver_helper_object.NewFileSystem(self._resolver_context)
github log2timeline / dfvfs / dfvfs / vfs / tar_file_entry.py View on Github external
resolver_context (Context): resolver context.
      file_system (FileSystem): file system.
      path_spec (PathSpec): path specification.
      is_root (Optional[bool]): True if the file entry is the root file entry
          of the corresponding file system.
      is_virtual (Optional[bool]): True if the file entry is a virtual file
          entry emulated by the corresponding file system.
      tar_info (Optional[tarfile.TARInfo]): TAR info.

    Raises:
      BackEndError: when the TAR info is missing in a non-virtual file entry.
    """
    if not is_virtual and tar_info is None:
      tar_info = file_system.GetTARInfoByPathSpec(path_spec)
    if not is_virtual and tar_info is None:
      raise errors.BackEndError('Missing TAR info in non-virtual file entry.')

    super(TARFileEntry, self).__init__(
        resolver_context, file_system, path_spec, is_root=is_root,
        is_virtual=is_virtual)
    self._tar_info = tar_info

    if self._is_virtual or self._tar_info.isdir():
      self.entry_type = definitions.FILE_ENTRY_TYPE_DIRECTORY
    elif self._tar_info.isfile():
      self.entry_type = definitions.FILE_ENTRY_TYPE_FILE
    elif self._tar_info.issym() or self._tar_info.islnk():
      self.entry_type = definitions.FILE_ENTRY_TYPE_LINK
    elif self._tar_info.ischr() or self._tar_info.isblk():
      self.entry_type = definitions.FILE_ENTRY_TYPE_DEVICE
    elif self._tar_info.isfifo():
      self.entry_type = definitions.FILE_ENTRY_TYPE_PIPE
github log2timeline / dfvfs / dfvfs / file_io / encrypted_stream_io.py View on Github external
OSError: if the file-like object could not be opened.
      PathSpecError: if the path specification is incorrect.
      ValueError: if the path specification is invalid.
    """
    if not self._file_object_set_in_init and not path_spec:
      raise ValueError('Missing path specification.')

    if not self._file_object_set_in_init:
      if not path_spec.HasParent():
        raise errors.PathSpecError(
            'Unsupported path specification without parent.')

      self._encryption_method = getattr(path_spec, 'encryption_method', None)

      if self._encryption_method is None:
        raise errors.PathSpecError(
            'Path specification missing encryption method.')

      self._file_object = resolver.Resolver.OpenFileObject(
          path_spec.parent, resolver_context=self._resolver_context)

    self._path_spec = path_spec
github log2timeline / dfvfs / examples / recursive_hasher.py View on Github external
print('No supported file system found in source.')
      print('')
      return False

    recursive_hasher.CalculateHashes(base_path_specs, output_writer)

    print('')
    print('Completed.')

  except errors.ScannerError as exception:
    return_value = False

    print('')
    print('[ERROR] {0!s}'.format(exception))

  except errors.UserAbort as exception:
    return_value = False

    print('')
    print('Aborted.')

  output_writer.Close()

  return return_value
github log2timeline / dfvfs / dfvfs / vfs / tsk_file_system.py View on Github external
def _Open(self, path_spec, mode='rb'):
    """Opens the file system object defined by path specification.

    Args:
      path_spec (PathSpec): path specification.
      mode (Optional[str]): file access mode.

    Raises:
      AccessError: if the access to open the file was denied.
      IOError: if the file system object could not be opened.
      PathSpecError: if the path specification is incorrect.
      ValueError: if the path specification is invalid.
    """
    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)

    try:
      tsk_image_object = tsk_image.TSKFileSystemImage(file_object)
      tsk_file_system = pytsk3.FS_Info(tsk_image_object)
    except:
      file_object.close()
      raise

    self._file_object = file_object
    self._tsk_file_system = tsk_file_system
github log2timeline / dfvfs / examples / recursive_hasher2.py View on Github external
Args:
      volume_system: The volume system (instance of dfvfs.VShadowVolumeSystem).
      volume_identifiers: List of allowed volume identifiers.

    Returns:
      The list of selected VSS store identifiers or None.

    Raises:
      SourceScannerError: if the source cannot be processed.
    """
    normalized_volume_identifiers = []
    for volume_identifier in volume_identifiers:
      volume = volume_system.GetVolumeByIdentifier(volume_identifier)
      if not volume:
        raise errors.SourceScannerError(
            u'Volume missing for identifier: {0:s}.'.format(volume_identifier))

      try:
        volume_identifier = int(volume.identifier[3:], 10)
        normalized_volume_identifiers.append(volume_identifier)
      except ValueError:
        pass

    print_header = True
    while True:
      if print_header:
        print(u'The following Volume Shadow Snapshots (VSS) were found:')
        print(u'Identifier\tVSS store identifier')

        for volume_identifier in volume_identifiers:
          volume = volume_system.GetVolumeByIdentifier(volume_identifier)
github log2timeline / dfvfs / dfvfs / vfs / vshadow_file_entry.py View on Github external
Args:
      resolver_context (Context): resolver context.
      file_system (FileSystem): file system.
      path_spec (PathSpec): path specification.
      is_root (Optional[bool]): True if the file entry is the root file entry
          of the corresponding file system.
      is_virtual (Optional[bool]): True if the file entry is a virtual file
          entry emulated by the corresponding file system.

    Raises:
      BackEndError: when the vshadow store is missing in a non-virtual
          file entry.
    """
    vshadow_store = file_system.GetVShadowStoreByPathSpec(path_spec)
    if not is_virtual and vshadow_store is None:
      raise errors.BackEndError(
          'Missing vshadow store in non-virtual file entry.')

    super(VShadowFileEntry, self).__init__(
        resolver_context, file_system, path_spec, is_root=is_root,
        is_virtual=is_virtual)
    self._name = None
    self._vshadow_store = vshadow_store

    if self._is_virtual:
      self.entry_type = definitions.FILE_ENTRY_TYPE_DIRECTORY
    else:
      self.entry_type = definitions.FILE_ENTRY_TYPE_FILE
github log2timeline / dfvfs / dfvfs / vfs / encrypted_stream_file_system.py View on Github external
def _Open(self, path_spec, mode='rb'):
    """Opens the file system defined by path specification.

    Args:
      path_spec (PathSpec): a path specification.
      mode (Optional[str]): file access mode. The default is 'rb' which
          represents read-only binary.

    Raises:
      AccessError: if the access to open the file was denied.
      IOError: if the file system could not be opened.
      PathSpecError: if the path specification is incorrect.
      ValueError: if the path specification is invalid.
    """
    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(path_spec)

    encryption_method = getattr(path_spec, 'encryption_method', None)
    if not encryption_method:
      raise errors.PathSpecError(
          'Unsupported path specification without encryption method.')

    self._encryption_method = encryption_method
github pcbje / gransk / gransk / plugins / unpackers / diskimage_reader.py View on Github external
def _GetBasePathSpecs(self, source_path):
    if (not source_path.startswith('\\\\.\\') and
            not os.path.exists(source_path)):
      raise RuntimeError(
          'No such device, file or directory: {0:s}.'.format(source_path))

    scan_context = source_scanner.SourceScannerContext()
    scan_context.OpenSourcePath(source_path)

    try:
      self._source_scanner.Scan(scan_context)
    except (errors.BackEndError, ValueError) as exception:
      raise RuntimeError(
          'Unable to scan source with error: {0:s}.'.format(exception))

    if scan_context.source_type not in [
            definitions.SOURCE_TYPE_STORAGE_MEDIA_DEVICE,
            definitions.SOURCE_TYPE_STORAGE_MEDIA_IMAGE]:
      scan_node = scan_context.GetRootScanNode()
      return [scan_node.path_spec]

    scan_node = scan_context.GetRootScanNode()

    while len(scan_node.sub_nodes) == 1:
      scan_node = scan_node.sub_nodes[0]

    if scan_node.type_indicator != definitions.TYPE_INDICATOR_TSK_PARTITION:
      partition_identifiers = None
github log2timeline / dfvfs / dfvfs / file_io / vmdk_file_io.py View on Github external
def _OpenFileObject(self, path_spec):
    """Opens the file-like object defined by path specification.

    Args:
      path_spec (PathSpec): path specification.

    Returns:
      pyvmdk.handle: a file-like object.

    Raises:
      IOError: if the file-like object could not be opened.
      OSError: if the file-like object could not be opened.
      PathSpecError: if the path specification is incorrect.
    """
    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    parent_path_spec = path_spec.parent

    parent_location = getattr(parent_path_spec, 'location', None)
    if not parent_location:
      raise errors.PathSpecError(
          'Unsupported parent path specification without location.')

    # Note that we cannot use pyvmdk's open_extent_data_files function
    # since it does not handle the file system abstraction dfvfs provides.

    file_system = resolver.Resolver.OpenFileSystem(
        parent_path_spec, resolver_context=self._resolver_context)

    file_object = resolver.Resolver.OpenFileObject(