def OpenFileSystem(cls, path_spec, resolver_context=None): """Opens a file system object defined by path specification. Args: path_spec: the VFS path specification (instance of path.PathSpec). resolver_context: the optional resolver context (instance of resolver.Context). The default is None which will use the built in context which is not multi process safe. Returns: The file system object (instance of vfs.FileSystem) or None if the path specification could not be resolved or has no file system object. Raises: AccessError: if the access to open the file system was denied. BackEndError: if the file system cannot be opened. KeyError: if resolver helper object is not set for the corresponding type indicator. PathSpecError: if the path specification is incorrect. """ if resolver_context is None: resolver_context = cls._resolver_context if path_spec.type_indicator == definitions.TYPE_INDICATOR_MOUNT: if path_spec.HasParent(): raise errors.PathSpecError( u'Unsupported mount path specification with parent.') mount_point = getattr(path_spec, u'identifier', None) if not mount_point: raise errors.PathSpecError( u'Unsupported path specification without mount point identifier.' ) path_spec = mount_manager.MountPointManager.GetMountPoint( mount_point) if not path_spec: raise errors.MountPointError( u'No such mount point: {0:s}'.format(mount_point)) file_system = resolver_context.GetFileSystem(path_spec) if not file_system: if path_spec.type_indicator not in cls._resolver_helpers: raise KeyError( (u'Resolver helper object not set for type indicator: ' u'{0:s}.').format(path_spec.type_indicator)) resolver_helper = cls._resolver_helpers[path_spec.type_indicator] file_system = resolver_helper.NewFileSystem(resolver_context) try: file_system.Open(path_spec=path_spec) except (errors.AccessError, errors.PathSpecError): raise except (IOError, ValueError) as exception: raise errors.BackEndError( u'Unable to open file system with error: {0:s}'.format( exception)) return file_system
def _Open(self, mode='rb'): """Opens the file-like object defined by path specification. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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. """ store_index = vshadow.VShadowPathSpecGetStoreIndex(self._path_spec) if store_index is None: raise errors.PathSpecError( 'Unable to retrieve store index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( self._path_spec, resolver_context=self._resolver_context) vshadow_volume = self._file_system.GetVShadowVolume() if (store_index < 0 or store_index >= vshadow_volume.number_of_stores): raise errors.PathSpecError( ('Unable to retrieve VSS store: {0:d} from path ' 'specification.').format(store_index)) vshadow_store = vshadow_volume.get_store(store_index) if not vshadow_store.has_in_volume_data(): raise IOError( ('Unable to open VSS store: {0:d} without in-volume stored ' 'data.').format(store_index)) self._vshadow_store = vshadow_store
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object. Args: path_spec: optional path specification (instance of path.PathSpec). The default is None. mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: 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(u'Missing path specfication.') if not self._file_object_set_in_init: if not path_spec.HasParent(): raise errors.PathSpecError( u'Unsupported path specification without parent.') range_offset = getattr(path_spec, u'range_offset', None) range_size = getattr(path_spec, u'range_size', None) if range_offset is None or range_size is None: raise errors.PathSpecError( u'Path specification missing range offset and range size.') self.SetRange(range_offset, range_size) self._file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context)
def _Open(self, mode='rb'): """Opens the file system defined by path specification. Args: 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 self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec( self._path_spec) encryption_method = getattr(self._path_spec, 'encryption_method', None) if not encryption_method: raise errors.PathSpecError( 'Unsupported path specification without encryption method.') self._encryption_method = encryption_method
def _Open(self, path_spec, mode='rb'): """Opens the file system object defined by path specification. Args: path_spec: a path specification (instance of PathSpec). mode: optional file access mode. The default is 'rb' read-only binary. 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( u'Unsupported path specification without parent.') resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec(path_spec) encryption_method = getattr(path_spec, u'encryption_method', None) if not encryption_method: raise errors.PathSpecError( u'Unsupported path specification without encryption method.') self._encryption_method = encryption_method
def _Open(self, mode='rb'): """Opens the file-like object defined by path specification. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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. """ volume_index = lvm.LVMPathSpecGetVolumeIndex(self._path_spec) if volume_index is None: raise errors.PathSpecError( 'Unable to retrieve volume index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( self._path_spec, resolver_context=self._resolver_context) vslvm_volume_group = self._file_system.GetLVMVolumeGroup() if (volume_index < 0 or volume_index >= vslvm_volume_group.number_of_logical_volumes): raise errors.PathSpecError(( 'Unable to retrieve LVM logical volume index: {0:d} from path ' 'specification.').format(volume_index)) self._vslvm_logical_volume = vslvm_volume_group.get_logical_volume( volume_index)
def _Open(self, mode='rb'): """Opens the file system defined by path specification. Args: 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 self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') range_offset = getattr(self._path_spec, 'range_offset', None) if range_offset is None: raise errors.PathSpecError( 'Unsupported path specification without encoding method.') range_size = getattr(self._path_spec, 'range_size', None) if range_size is None: raise errors.PathSpecError( 'Unsupported path specification without encoding method.') self._range_offset = range_offset self._range_size = range_size
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like 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-like object could not be opened. 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 path_spec: raise ValueError('Missing path specification.') if path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification with parent.') location = getattr(path_spec, 'location', None) if location is None: raise errors.PathSpecError('Path specification missing location.') self._current_offset = 0 self._size = len(self._file_data)
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec: optional path specification (instance of path.PathSpec). The default is None. mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: 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 path_spec: raise ValueError(u'Missing path specfication.') store_index = vshadow.VShadowPathSpecGetStoreIndex(path_spec) if store_index is None: raise errors.PathSpecError( u'Unable to retrieve store index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) vshadow_volume = self._file_system.GetVShadowVolume() if (store_index < 0 or store_index >= vshadow_volume.number_of_stores): raise errors.PathSpecError( (u'Unable to retrieve VSS store: {0:d} from path ' u'specification.').format(store_index)) self._vshadow_store = vshadow_volume.get_store(store_index)
def _Open(self, mode='rb'): """Opens the file-like object. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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 self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') range_offset = getattr(self._path_spec, 'range_offset', None) range_size = getattr(self._path_spec, 'range_size', None) if range_offset is None or range_size is None: raise errors.PathSpecError( 'Path specification missing range offset and range size.') self._SetRange(range_offset, range_size) self._file_object = resolver.Resolver.OpenFileObject( self._path_spec.parent, resolver_context=self._resolver_context)
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec: optional path specification (instance of path.PathSpec). The default is None. mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: 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 path_spec: raise ValueError(u'Missing path specfication.') if path_spec.HasParent(): raise errors.PathSpecError( u'Unsupported path specification with parent.') location = getattr(path_spec, u'location', None) if location is None: raise errors.PathSpecError(u'Path specification missing location.') self._current_offset = 0 self._size = len(self._file_data)
def GetZipInfo(self): """Retrieves the ZIP info object. Returns: zipfile.ZipInfo: a ZIP info object or None if not available. Raises: PathSpecError: if the path specification is incorrect. """ if not self._zip_info: location = getattr(self.path_spec, 'location', None) if location is None: raise errors.PathSpecError('Path specification missing location.') if not location.startswith(self._file_system.LOCATION_ROOT): raise errors.PathSpecError('Invalid location in path specification.') if len(location) == 1: return None zip_file = self._file_system.GetZipFile() try: self._zip_info = zip_file.getinfo(location[1:]) except KeyError: pass return self._zip_info
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec: optional path specification (instance of PathSpec). mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: 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 path_spec: raise ValueError(u'Missing path specfication.') volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec) if volume_index is None: raise errors.PathSpecError( u'Unable to retrieve volume index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) vslvm_volume_group = self._file_system.GetLVMVolumeGroup() if (volume_index < 0 or volume_index >= vslvm_volume_group.number_of_logical_volumes): raise errors.PathSpecError(( u'Unable to retrieve LVM logical volume index: {0:d} from path ' u'specification.').format(volume_index)) self._vslvm_logical_volume = vslvm_volume_group.get_logical_volume( volume_index)
def GetTARInfoByPathSpec(self, path_spec): """Retrieves the TAR info for a path specification. Args: path_spec (PathSpec): a path specification. Returns: tarfile.TARInfo: TAR info or None if it does not exist. Raises: PathSpecError: if the path specification is incorrect. """ location = getattr(path_spec, 'location', None) if location is None: raise errors.PathSpecError('Path specification missing location.') if not location.startswith(self.LOCATION_ROOT): raise errors.PathSpecError( 'Invalid location in path specification.') if len(location) == 1: return None try: return self._tar_file.getmember(location[1:]) except KeyError: pass
def _Open(self, mode='rb'): """Opens the file-like object. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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 self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') self._compression_method = getattr(self._path_spec, 'compression_method', None) if self._compression_method is None: raise errors.PathSpecError( 'Path specification missing compression method.') self._file_object = resolver.Resolver.OpenFileObject( self._path_spec.parent, resolver_context=self._resolver_context)
def _Open(self, mode='rb'): """Opens the file-like object defined by path specification. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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. """ entry_index = gpt.GPTPathSpecGetEntryIndex(self._path_spec) if entry_index is None: raise errors.PathSpecError( 'Unable to retrieve entry index from path specification.') self._file_system = resolver.Resolver.OpenFileSystem( self._path_spec, resolver_context=self._resolver_context) vsgpt_volume = self._file_system.GetGPTVolume() if not vsgpt_volume.has_partition_with_identifier(entry_index): raise errors.PathSpecError( 'Missing GPT partition with entry index: {0:d}'.format( entry_index)) self._vsgpt_partition = vsgpt_volume.get_partition_by_identifier( entry_index)
def _Open(self, path_spec, mode='rb'): """Opens the file system object defined by path specification. Args: path_spec: a path specification (instance of PathSpec). mode: optional file access mode. The default is 'rb' read-only binary. 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( u'Unsupported path specification without parent.') range_offset = getattr(path_spec, u'range_offset', None) if range_offset is None: raise errors.PathSpecError( u'Unsupported path specification without encoding method.') range_size = getattr(path_spec, u'range_size', None) if range_size is None: raise errors.PathSpecError( u'Unsupported path specification without encoding method.') self._range_offset = range_offset self._range_size = range_size
def GetTARInfo(self): """Retrieves the TAR info. Returns: tarfile.TARInfo: TAR info or None if it does not exist. Raises: PathSpecError: if the path specification is incorrect. """ if not self._tar_info: location = getattr(self.path_spec, 'location', None) if location is None: raise errors.PathSpecError( 'Path specification missing location.') if not location.startswith(self._file_system.LOCATION_ROOT): raise errors.PathSpecError( 'Invalid location in path specification.') if len(location) == 1: return None tar_file = self._file_system.GetTARFile() try: self._tar_info = tar_file.getmember(location[1:]) except KeyError: pass return self._tar_info
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object. 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-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._encoding_method = getattr(path_spec, 'encoding_method', None) if self._encoding_method is None: raise errors.PathSpecError( 'Path specification missing encoding method.') self._file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context)
def _Open(self, mode='rb'): """Opens the file-like object defined by path specification. Args: mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. 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 self._path_spec.HasParent(): raise errors.PathSpecError('Unsupported path specification with parent.') location = getattr(self._path_spec, 'location', None) if location is None: raise errors.PathSpecError('Path specification missing location.') # Windows does not support running os.stat on device files so we use # libsmdev to do an initial check. try: is_device = pysmdev.check_device(location) except IOError as exception: # Since os.stat() will not recognize Windows device file names and # will return '[Error 87] The parameter is incorrect' we check here # if pysmdev exception message contains ' access denied ' and raise # AccessError instead. if ' access denied ' in str(exception): raise errors.AccessError( 'Access denied to file: {0:s} with error: {1!s}'.format( location, exception)) is_device = False if not is_device: try: stat_info = os.stat(location) except OSError as exception: raise IOError('Unable to open file with error: {0!s}.'.format( exception)) # In case the libsmdev check is not able to detect the device also use # the stat information. if stat.S_ISCHR(stat_info.st_mode) or stat.S_ISBLK(stat_info.st_mode): is_device = True if is_device: smdev_handle = pysmdev.handle() smdev_handle.open(location, mode=mode) self._file_object = smdev_handle self._size = smdev_handle.media_size else: self._file_object = open(location, mode=mode) self._size = stat_info.st_size
def OpenFileSystem(cls, path_spec_object, resolver_context=None): """Opens a file system object defined by path specification. Args: path_spec_object (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built in context which is not multi process safe. Returns: FileSystem: file system or None if the path specification could not be resolved or has no file system object. Raises: AccessError: if the access to open the file system was denied. BackEndError: if the file system cannot be opened. MountPointError: if the mount point specified in the path specification does not exist. PathSpecError: if the path specification is incorrect. TypeError: if the path specification type is unsupported. """ if not isinstance(path_spec_object, path_spec.PathSpec): raise TypeError('Unsupported path specification type.') if resolver_context is None: resolver_context = cls._resolver_context if path_spec_object.type_indicator == definitions.TYPE_INDICATOR_MOUNT: if path_spec_object.HasParent(): raise errors.PathSpecError( 'Unsupported mount path specification with parent.') mount_point = getattr(path_spec_object, 'identifier', None) if not mount_point: raise errors.PathSpecError( 'Unsupported path specification without mount point identifier.' ) path_spec_object = mount_manager.MountPointManager.GetMountPoint( mount_point) if not path_spec_object: raise errors.MountPointError( 'No such mount point: {0:s}'.format(mount_point)) file_system = resolver_context.GetFileSystem(path_spec_object) if not file_system: resolver_helper = cls._GetResolverHelper( path_spec_object.type_indicator) file_system = resolver_helper.NewFileSystem(resolver_context) try: file_system.Open(path_spec_object) except (IOError, ValueError) as exception: raise errors.BackEndError( 'Unable to open file system with error: {0!s}'.format( exception)) return file_system
def OpenFileObject(cls, path_spec_object, resolver_context=None): """Opens a file-like object defined by path specification. Args: path_spec_object: the path specification (instance of PathSpec). resolver_context: the optional resolver context (instance of resolver.Context). The default is None which will use the built in context which is not multi process safe. Returns: The file-like object (instance of file.FileIO) or None if the path specification could not be resolved. Raises: KeyError: if resolver helper object is not set for the corresponding type indicator. PathSpecError: if the path specification is incorrect. TypeError: if the path specification type is unsupported. """ if not isinstance(path_spec_object, path_spec.PathSpec): raise TypeError(u'Unsupported path specification type.') if resolver_context is None: resolver_context = cls._resolver_context if path_spec_object.type_indicator == definitions.TYPE_INDICATOR_MOUNT: if path_spec_object.HasParent(): raise errors.PathSpecError( u'Unsupported mount path specification with parent.') mount_point = getattr(path_spec_object, u'identifier', None) if not mount_point: raise errors.PathSpecError( u'Unsupported path specification without mount point identifier.' ) path_spec_object = mount_manager.MountPointManager.GetMountPoint( mount_point) if not path_spec_object: raise errors.MountPointError( u'No such mount point: {0:s}'.format(mount_point)) file_object = resolver_context.GetFileObject(path_spec_object) if not file_object: if path_spec_object.type_indicator not in cls._resolver_helpers: raise KeyError( (u'Resolver helper object not set for type indicator: ' u'{0:s}.').format(path_spec_object.type_indicator)) resolver_helper = cls._resolver_helpers[ path_spec_object.type_indicator] file_object = resolver_helper.NewFileObject(resolver_context) file_object.open(path_spec=path_spec_object) return file_object
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec: optional path specification (instance of path.PathSpec). The default is None. mode: optional file access mode. The default is 'rb' read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: 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 path_spec: raise ValueError(u'Missing path specfication.') if not path_spec.HasParent(): raise errors.PathSpecError( u'Unsupported path specification without parent.') self._file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) tsk_volume = self._file_system.GetTSKVolume() tsk_vs, _ = tsk_partition.GetTSKVsPartByPathSpec(tsk_volume, path_spec) if tsk_vs is None: raise errors.PathSpecError( u'Unable to retrieve TSK volume system part from path ' u'specification.') range_offset = tsk_partition.TSKVsPartGetStartSector(tsk_vs) range_size = tsk_partition.TSKVsPartGetNumberOfSectors(tsk_vs) if range_offset is None or range_size is None: raise errors.PathSpecError( u'Unable to retrieve TSK volume system part data range from path ' u'specification.') bytes_per_sector = tsk_partition.TSKVolumeGetBytesPerSector(tsk_volume) range_offset *= bytes_per_sector range_size *= bytes_per_sector self.SetRange(range_offset, range_size) self._file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context) self._file_object_set_in_init = True # pylint: disable=protected-access super(TSKPartitionFile, self)._Open(path_spec=path_spec, mode=mode)
def OpenFileObject(cls, path_spec_object, resolver_context=None): """Opens a file-like object defined by path specification. Args: path_spec_object (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built in context which is not multi process safe. Returns: FileIO: file-like object or None if the path specification could not be resolved. Raises: MountPointError: if the mount point specified in the path specification does not exist. PathSpecError: if the path specification is incorrect. TypeError: if the path specification type is unsupported. """ if not isinstance(path_spec_object, path_spec.PathSpec): raise TypeError('Unsupported path specification type.') if resolver_context is None: resolver_context = cls._resolver_context if path_spec_object.type_indicator == definitions.TYPE_INDICATOR_MOUNT: if path_spec_object.HasParent(): raise errors.PathSpecError( 'Unsupported mount path specification with parent.') mount_point = getattr(path_spec_object, 'identifier', None) if not mount_point: raise errors.PathSpecError( 'Unsupported path specification without mount point identifier.' ) path_spec_object = mount_manager.MountPointManager.GetMountPoint( mount_point) if not path_spec_object: raise errors.MountPointError( 'No such mount point: {0:s}'.format(mount_point)) file_object = resolver_context.GetFileObject(path_spec_object) if not file_object: resolver_helper = cls._GetResolverHelper( path_spec_object.type_indicator) file_object = resolver_helper.NewFileObject(resolver_context) file_object.open(path_spec=path_spec_object) return file_object
def _Open(self, path_spec=None, mode='rb'): """Opens the file-like object defined by path specification. Args: path_spec (Optional[PathSpec]): path specification. mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. IOError: 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 path_spec: raise ValueError('Missing path specification.') if not path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') self._gzip_file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context) self._gzip_file_object.seek(0, os.SEEK_SET) uncompressed_data_offset = 0 next_member_offset = 0 while next_member_offset < self._gzip_file_object.get_size(): member = gzip.GzipMember( self._gzip_file_object, next_member_offset, uncompressed_data_offset) uncompressed_data_offset = ( uncompressed_data_offset + member.uncompressed_data_size) self._members_by_end_offset[uncompressed_data_offset] = member self.uncompressed_data_size += member.uncompressed_data_size next_member_offset = member.member_end_offset
def _Open(self, mode='rb'): """Opens the file system defined by path specification. Args: mode (Optional[str]): file access mode. The default is 'rb' 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 self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') resolver.Resolver.key_chain.ExtractCredentialsFromPathSpec( self._path_spec) fvde_volume = pyfvde.volume() file_object = resolver.Resolver.OpenFileObject( self._path_spec.parent, resolver_context=self._resolver_context) fvde.FVDEVolumeOpen(fvde_volume, self._path_spec, file_object, resolver.Resolver.key_chain) self._fvde_volume = fvde_volume self._file_object = file_object
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: vshadow_volume = pyvshadow.volume() vshadow_volume.open_file_object(file_object) except: file_object.close() raise self._file_object = file_object self._vshadow_volume = vshadow_volume
def GetTSKFileByPathSpec(self, path_spec): """Retrieves the SleuthKit file object for a path specification. Args: path_spec (PathSpec): path specification. Returns: pytsk3.File: TSK file. Raises: PathSpecError: if the path specification is missing inode and location. """ # Opening a file by inode number is faster than opening a file # by location. inode = getattr(path_spec, 'inode', None) location = getattr(path_spec, 'location', None) if inode is not None: tsk_file = self._tsk_file_system.open_meta(inode=inode) elif location is not None: tsk_file = self._tsk_file_system.open(location) else: raise errors.PathSpecError( 'Path specification missing inode and location.') return tsk_file
def _Open(self, mode='rb'): """Opens the file system object defined by path specification. Args: 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 object could not be opened. PathSpecError: if the path specification is incorrect. ValueError: if the path specification is invalid. """ if not self._path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') file_object = resolver.Resolver.OpenFileObject( self._path_spec.parent, resolver_context=self._resolver_context) vslvm_handle = pyvslvm.handle() vslvm_handle.open_file_object(file_object) # TODO: implement multi physical volume support. vslvm_handle.open_physical_volume_files_as_file_objects([file_object]) vslvm_volume_group = vslvm_handle.get_volume_group() self._file_object = file_object self._vslvm_handle = vslvm_handle self._vslvm_volume_group = vslvm_volume_group
def _Open(self, path_spec, mode='rb'): """Opens the file system defined by path specification. Args: path_spec (PathSpec): 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.') file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context) cpio_archive_file = cpio.CPIOArchiveFile() try: cpio_archive_file.Open(file_object) except: file_object.close() raise self._file_object = file_object self._cpio_archive_file = cpio_archive_file