docstring
stringlengths
52
499
function
stringlengths
67
35.2k
__index_level_0__
int64
52.6k
1.16M
Scans a file system scan node for file systems. Args: scan_node (SourceScanNode): file system scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the scan node is invalid.
def _ScanFileSystem(self, scan_node, base_path_specs): if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing file system scan node.') base_path_specs.append(scan_node.path_spec)
391,161
Scans a volume scan node for volume and file systems. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): volume scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the format of or withi...
def _ScanVolume(self, scan_context, scan_node, base_path_specs): if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing scan node.') if scan_context.IsLockedScanNode(scan_node.path_spec): # The source scanner found a locked volume and we need a credential to...
391,162
Scans a volume system root scan node for volume and file systems. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): volume system root scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: i...
def _ScanVolumeSystemRoot(self, scan_context, scan_node, base_path_specs): if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid scan node.') if scan_node.type_indicator == definitions.TYPE_INDICATOR_APFS_CONTAINER: volume_identifiers = self._GetAPFSVolumeIdentifiers(...
391,163
Determines the base path specifications. Args: source_path (str): source path. Returns: list[PathSpec]: path specifications. Raises: ScannerError: if the source path does not exists, or if the source path is not a file or directory, or if the format of or within the source ...
def GetBasePathSpecs(self, source_path): if not source_path: raise errors.ScannerError('Invalid source path.') # Note that os.path.exists() does not support Windows device paths. if (not source_path.startswith('\\\\.\\') and not os.path.exists(source_path)): raise errors.ScannerErr...
391,164
Initializes a Windows volume scanner. Args: mediator (VolumeScannerMediator): a volume scanner mediator.
def __init__(self, mediator=None): super(WindowsVolumeScanner, self).__init__(mediator=mediator) self._file_system = None self._path_resolver = None self._windows_directory = None
391,165
Scans a file system scan node for file systems. This method checks if the file system contains a known Windows directory. Args: scan_node (SourceScanNode): file system scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the scan no...
def _ScanFileSystem(self, scan_node, base_path_specs): if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing file system scan node.') file_system = resolver.Resolver.OpenFileSystem(scan_node.path_spec) if not file_system: return try: path_res...
391,166
Scans a file system for a known Windows directory. Args: path_resolver (WindowsPathResolver): Windows path resolver. Returns: bool: True if a known Windows directory was found.
def _ScanFileSystemForWindowsDirectory(self, path_resolver): result = False for windows_path in self._WINDOWS_DIRECTORIES: windows_path_spec = path_resolver.ResolvePath(windows_path) result = windows_path_spec is not None if result: self._windows_directory = windows_path ...
391,167
Opens the file specificed by the Windows path. Args: windows_path (str): Windows path to the file. Returns: FileIO: file-like object or None if the file does not exist.
def OpenFile(self, windows_path): path_spec = self._path_resolver.ResolvePath(windows_path) if path_spec is None: return None return self._file_system.GetFileObjectByPathSpec(path_spec)
391,168
Scans for a Windows volume. Args: source_path (str): source path. Returns: bool: True if a Windows volume was found. Raises: ScannerError: if the source path does not exists, or if the source path is not a file or directory, or if the format of or within the source f...
def ScanForWindowsVolume(self, source_path): windows_path_specs = self.GetBasePathSpecs(source_path) if (not windows_path_specs or self._source_type == definitions.SOURCE_TYPE_FILE): return False file_system_path_spec = windows_path_specs[0] self._file_system = resolver.Resolver.Open...
391,169
Flushes the cached objects for the specified format categories. Args: format_categories (set[str]): format categories.
def _FlushCache(cls, format_categories): if definitions.FORMAT_CATEGORY_ARCHIVE in format_categories: cls._archive_remainder_list = None cls._archive_scanner = None cls._archive_store = None if definitions.FORMAT_CATEGORY_COMPRESSED_STREAM in format_categories: cls._compressed_stre...
391,170
Initializes a signature scanner based on a specification store. Args: specification_store (FormatSpecificationStore): specification store. Returns: pysigscan.scanner: signature scanner.
def _GetSignatureScanner(cls, specification_store): signature_scanner = pysigscan.scanner() signature_scanner.set_scan_buffer_size(cls._SCAN_BUFFER_SIZE) for format_specification in specification_store.specifications: for signature in format_specification.signatures: pattern_offset = sig...
391,171
Retrieves the specification store for specified format category. Args: format_category (str): format category. Returns: tuple[FormatSpecificationStore, list[AnalyzerHelper]]: a format specification store and remaining analyzer helpers that do not have a format specification.
def _GetSpecificationStore(cls, format_category): specification_store = specification.FormatSpecificationStore() remainder_list = [] for analyzer_helper in iter(cls._analyzer_helpers.values()): if not analyzer_helper.IsEnabled(): continue if format_category in analyzer_helper.form...
391,172
Deregisters a format analyzer helper. Args: analyzer_helper (AnalyzerHelper): analyzer helper. Raises: KeyError: if analyzer helper object is not set for the corresponding type indicator.
def DeregisterHelper(cls, analyzer_helper): if analyzer_helper.type_indicator not in cls._analyzer_helpers: raise KeyError( 'Analyzer helper object not set for type indicator: {0:s}.'.format( analyzer_helper.type_indicator)) analyzer_helper = cls._analyzer_helpers[analyzer_he...
391,174
Determines if a file contains a supported archive types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported format type ind...
def GetArchiveTypeIndicators(cls, path_spec, resolver_context=None): if (cls._archive_remainder_list is None or cls._archive_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_ARCHIVE) cls._archive_remainder_list = remaind...
391,175
Determines if a file contains a supported compressed stream types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported forma...
def GetCompressedStreamTypeIndicators(cls, path_spec, resolver_context=None): if (cls._compressed_stream_remainder_list is None or cls._compressed_stream_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_COMPRESSED_STREAM) ...
391,176
Determines if a file contains a supported file system types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported format type...
def GetFileSystemTypeIndicators(cls, path_spec, resolver_context=None): if (cls._file_system_remainder_list is None or cls._file_system_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_FILE_SYSTEM) cls._file_system_remai...
391,177
Determines if a file contains a supported storage media image types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported for...
def GetStorageMediaImageTypeIndicators(cls, path_spec, resolver_context=None): if (cls._storage_media_image_remainder_list is None or cls._storage_media_image_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_STORAGE_MEDIA_IMAG...
391,178
Determines if a file contains a supported volume system types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported format ty...
def GetVolumeSystemTypeIndicators(cls, path_spec, resolver_context=None): if (cls._volume_system_remainder_list is None or cls._volume_system_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_VOLUME_SYSTEM) cls._volume_sy...
391,179
Initializes a decompressor. Args: window_size (Optional[int]): base two logarithm of the size of the compression history buffer (aka window size). When the value is negative, the standard zlib data header is suppressed.
def __init__(self, window_size=zlib.MAX_WBITS): super(ZlibDecompressor, self).__init__() self._zlib_decompressor = zlib.decompressobj(window_size)
391,180
Decompresses the compressed data. Args: compressed_data (bytes): compressed data. Returns: tuple(bytes, bytes): uncompressed data and remaining compressed data. Raises: BackEndError: if the zlib compressed stream cannot be decompressed.
def Decompress(self, compressed_data): try: uncompressed_data = self._zlib_decompressor.decompress(compressed_data) remaining_compressed_data = getattr( self._zlib_decompressor, 'unused_data', b'') except zlib.error as exception: raise errors.BackEndError(( 'Unable to...
391,181
Initializes a file system. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(TSKFileSystem, self).__init__(resolver_context) self._file_object = None self._tsk_file_system = None self._tsk_fs_type = None
391,182
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. PathSpecErro...
def _Open(self, path_spec, mode='rb'): 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_ob...
391,183
Determines if a file entry for a path specification exists. Args: path_spec (PathSpec): path specification. Returns: bool: True if the file entry exists.
def FileEntryExistsByPathSpec(self, path_spec): # Opening a file by inode number is faster than opening a file by location. tsk_file = None inode = getattr(path_spec, 'inode', None) location = getattr(path_spec, 'location', None) try: if inode is not None: tsk_file = self._tsk_fi...
391,184
Retrieves a file entry for a path specification. Args: path_spec (PathSpec): path specification. Returns: TSKFileEntry: a file entry or None if not available.
def GetFileEntryByPathSpec(self, path_spec): # Opening a file by inode number is faster than opening a file by location. tsk_file = None inode = getattr(path_spec, 'inode', None) location = getattr(path_spec, 'location', None) root_inode = self.GetRootInode() if (location == self.LOCATION_...
391,185
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.
def GetTSKFileByPathSpec(self, path_spec): # 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)...
391,188
Initializes a file-like object. Args: resolver_context (Context): resolver context. file_object (Optional[FileIO]): file-like object. Raises: ValueError: when file_object is set.
def __init__(self, resolver_context, file_object=None): if file_object: raise ValueError('File object value set.') super(EWFFile, self).__init__(resolver_context) self._file_objects = []
391,191
Opens the file-like object defined by path specification. Args: path_spec (PathSpec): path specification. Returns: pyewf.handle: a file-like object or None. Raises: PathSpecError: if the path specification is invalid.
def _OpenFileObject(self, path_spec): if not path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') parent_path_spec = path_spec.parent file_system = resolver.Resolver.OpenFileSystem( parent_path_spec, resolver_context=self._resolv...
391,193
Initializes a file-like object. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(OSFile, self).__init__(resolver_context) self._file_object = None self._size = 0
391,194
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 ...
def _Open(self, path_spec=None, mode='rb'): 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: ...
391,195
Reads a byte string from the file-like object at the current offset. The function will read a byte string of the specified size or all of the remaining data if no size was specified. Args: size (Optional[int]): number of bytes to read, where None is all remaining data. Returns: ...
def read(self, size=None): if not self._is_open: raise IOError('Not opened.') if size is None: size = self._size - self._file_object.tell() return self._file_object.read(size)
391,196
Seeks to an offset within the file-like object. Args: offset (int): offset to seek to. whence (Optional(int)): value that indicates whether offset is an absolute or relative position within the file. Raises: IOError: if the seek failed. OSError: if the seek failed.
def seek(self, offset, whence=os.SEEK_SET): if not self._is_open: raise IOError('Not opened.') # For a yet unknown reason a Python file-like object on Windows allows for # invalid whence values to be passed to the seek function. This check # makes sure the behavior of the function is the sam...
391,197
Decompresses the compressed data. Args: compressed_data (bytes): compressed data. Returns: tuple(bytes, bytes): uncompressed data and remaining compressed data. Raises: BackEndError: if the BZIP2 compressed stream cannot be decompressed.
def Decompress(self, compressed_data): try: uncompressed_data = self._bz2_decompressor.decompress(compressed_data) remaining_compressed_data = getattr( self._bz2_decompressor, 'unused_data', b'') except (EOFError, IOError) as exception: raise errors.BackEndError(( 'Un...
391,199
Initializes a decrypter. Args: key (Optional[bytes]): key. kwargs (dict): keyword arguments depending on the decrypter. Raises: ValueError: when key is not set.
def __init__(self, key=None, **kwargs): if not key: raise ValueError('Missing key.') super(RC4Decrypter, self).__init__() self._rc4_cipher = ARC4.new(key)
391,200
Decrypts the encrypted data. Args: encrypted_data (bytes): encrypted data. Returns: tuple[bytes,bytes]: decrypted data and remaining encrypted data.
def Decrypt(self, encrypted_data): decrypted_data = self._rc4_cipher.decrypt(encrypted_data) return decrypted_data, b''
391,201
Initializes a path specification. Note that the zip file path specification must have a parent. Args: location (Optional[str]): ZIP file internal location string prefixed with a path separator character. parent (Optional[PathSpec]): parent path specification. Raises: ValueErro...
def __init__(self, location=None, parent=None, **kwargs): if not parent: raise ValueError('Missing parent value.') super(ZipPathSpec, self).__init__( location=location, parent=parent, **kwargs)
391,202
Retrieves the number of rows in the table. Args: table_name (str): name of the table. Returns: int: number of rows. Raises: IOError: if the file-like object has not been opened. OSError: if the file-like object has not been opened.
def GetNumberOfRows(self, table_name): if not self._connection: raise IOError('Not opened.') self._cursor.execute(self._NUMBER_OF_ROWS_QUERY.format(table_name)) row = self._cursor.fetchone() if not row: raise IOError( 'Unable to retrieve number of rows of table: {0:s}'.format...
391,205
Determines if a specific column exists. Args: table_name (str): name of the table. column_name (str): name of the column. Returns: bool: True if the column exists. Raises: IOError: if the database file is not opened. OSError: if the database file is not opened.
def HasColumn(self, table_name, column_name): if not self._connection: raise IOError('Not opened.') if not column_name: return False table_name = table_name.lower() column_names = self._column_names_per_table.get(table_name, None) if column_names is None: column_names = [] ...
391,206
Determines if a specific table exists. Args: table_name (str): name of the table. Returns: bool: True if the column exists. Raises: IOError: if the database file is not opened. OSError: if the database file is not opened.
def HasTable(self, table_name): if not self._connection: raise IOError('Not opened.') if not table_name: return False if self._table_names is None: self._table_names = [] self._cursor.execute(self._HAS_TABLE_QUERY) for row in self._cursor.fetchall(): if not row[...
391,207
Opens the database file object. Args: file_object (FileIO): file-like object. Raises: IOError: if the SQLite database signature does not match. OSError: if the SQLite database signature does not match. ValueError: if the file-like object is invalid.
def Open(self, file_object): if not file_object: raise ValueError('Missing file-like object.') # Since pysqlite3 does not provide an exclusive read-only mode and # cannot interact with a file-like object directly we make a temporary # copy. Before making a copy we check the header signature....
391,208
Queries the database file. Args: query (str): SQL query. parameters (Optional[dict|tuple]): query parameters. Returns: list[sqlite3.Row]: rows resulting from the query.
def Query(self, query, parameters=None): # TODO: catch Warning and return None. # Note that we cannot pass parameters as a keyword argument here. # A parameters value of None is not supported. if parameters: self._cursor.execute(query, parameters) else: self._cursor.execute(query) ...
391,209
Initializes the resolver context object. Args: maximum_number_of_file_objects (Optional[int]): maximum number of file-like objects cached in the context. maximum_number_of_file_systems (Optional[int]): maximum number of file system objects cached in the context.
def __init__( self, maximum_number_of_file_objects=128, maximum_number_of_file_systems=16): super(Context, self).__init__() self._file_object_cache = cache.ObjectsCache( maximum_number_of_file_objects) self._file_system_cache = cache.ObjectsCache( maximum_number_of_file_syst...
391,210
Determines the file system cache identifier for the path specification. Args: path_spec (PathSpec): path specification. Returns: str: identifier of the VFS object.
def _GetFileSystemCacheIdentifier(self, path_spec): string_parts = [] string_parts.append(getattr(path_spec.parent, 'comparable', '')) string_parts.append('type: {0:s}'.format(path_spec.type_indicator)) return ''.join(string_parts)
391,211
Caches a file-like object based on a path specification. Args: path_spec (PathSpec): path specification. file_object (FileIO): file-like object.
def CacheFileObject(self, path_spec, file_object): self._file_object_cache.CacheObject(path_spec.comparable, file_object)
391,212
Caches a file system object based on a path specification. Args: path_spec (PathSpec): path specification. file_system (FileSystem): file system object.
def CacheFileSystem(self, path_spec, file_system): identifier = self._GetFileSystemCacheIdentifier(path_spec) self._file_system_cache.CacheObject(identifier, file_system)
391,213
Forces the removal of a file-like object based on a path specification. Args: path_spec (PathSpec): path specification. Returns: bool: True if the file-like object was cached.
def ForceRemoveFileObject(self, path_spec): cache_value = self._file_object_cache.GetCacheValue(path_spec.comparable) if not cache_value: return False while not cache_value.IsDereferenced(): cache_value.vfs_object.close() return True
391,214
Retrieves the reference count of a cached file-like object. Args: path_spec (PathSpec): path specification. Returns: int: reference count or None if there is no file-like object for the corresponding path specification cached.
def GetFileObjectReferenceCount(self, path_spec): cache_value = self._file_object_cache.GetCacheValue(path_spec.comparable) if not cache_value: return None return cache_value.reference_count
391,215
Retrieves a file system object defined by path specification. Args: path_spec (PathSpec): path specification. Returns: FileSystem: a file system object or None if not cached.
def GetFileSystem(self, path_spec): identifier = self._GetFileSystemCacheIdentifier(path_spec) return self._file_system_cache.GetObject(identifier)
391,216
Retrieves the reference count of a cached file system object. Args: path_spec (PathSpec): path specification. Returns: int: reference count or None if there is no file system object for the corresponding path specification cached.
def GetFileSystemReferenceCount(self, path_spec): identifier = self._GetFileSystemCacheIdentifier(path_spec) cache_value = self._file_system_cache.GetCacheValue(identifier) if not cache_value: return None return cache_value.reference_count
391,217
Grabs a cached file system object defined by path specification. Args: path_spec (PathSpec): path specification.
def GrabFileSystem(self, path_spec): identifier = self._GetFileSystemCacheIdentifier(path_spec) self._file_system_cache.GrabObject(identifier)
391,218
Releases a cached file-like object. Args: file_object (FileIO): file-like object. Returns: bool: True if the file-like object can be closed. Raises: PathSpecError: if the path specification is incorrect. RuntimeError: if the file-like object is not cached or an inconsistency ...
def ReleaseFileObject(self, file_object): identifier, cache_value = self._file_object_cache.GetCacheValueByObject( file_object) if not identifier: raise RuntimeError('Object not cached.') if not cache_value: raise RuntimeError('Invalid cache value.') self._file_object_cache.R...
391,219
Releases a cached file system object. Args: file_system (FileSystem): file system object. Returns: bool: True if the file system object can be closed. Raises: PathSpecError: if the path specification is incorrect. RuntimeError: if the file system object is not cached or an inconsi...
def ReleaseFileSystem(self, file_system): identifier, cache_value = self._file_system_cache.GetCacheValueByObject( file_system) if not identifier: raise RuntimeError('Object not cached.') if not cache_value: raise RuntimeError('Invalid cache value.') self._file_system_cache.R...
391,220
Initializes a file-like object. Args: resolver_context (Context): resolver context. file_object (Optional[FileIO]): file-like object. Raises: ValueError: when file_object is set.
def __init__(self, resolver_context, file_object=None): if file_object: raise ValueError('File object value set.') super(RawFile, self).__init__(resolver_context) self._file_objects = []
391,221
Opens the file-like object defined by path specification. Args: path_spec (PathSpec): path specification. Returns: pysmraw.handle: a file-like object or None. Raises: PathSpecError: if the path specification is invalid.
def _OpenFileObject(self, path_spec): if not path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') parent_path_spec = path_spec.parent file_system = resolver.Resolver.OpenFileSystem( parent_path_spec, resolver_context=self._resolv...
391,223
Initializes a file-like object. If the file-like object is chained do not separately use the parent file-like object. Args: resolver_context (Context): resolver context. encoding_method (Optional[str]): method used to the encode the data. file_object (Optional[file]): parent file-like ob...
def __init__( self, resolver_context, encoding_method=None, file_object=None): if file_object is not None and encoding_method is None: raise ValueError( 'File-like object provided without corresponding encoding method.') super(EncodedStream, self).__init__(resolver_context) self....
391,224
Aligns the encoded file with the decoded data offset. Args: decoded_data_offset (int): decoded data offset.
def _AlignDecodedDataOffset(self, decoded_data_offset): self._file_object.seek(0, os.SEEK_SET) self._decoder = self._GetDecoder() self._decoded_data = b'' encoded_data_offset = 0 encoded_data_size = self._file_object.get_size() while encoded_data_offset < encoded_data_size: read_co...
391,227
Reads encoded data from the file-like object. Args: read_size (int): number of bytes of encoded data to read. Returns: int: number of bytes of encoded data read.
def _ReadEncodedData(self, read_size): encoded_data = self._file_object.read(read_size) read_count = len(encoded_data) self._encoded_data = b''.join([self._encoded_data, encoded_data]) self._decoded_data, self._encoded_data = ( self._decoder.Decode(self._encoded_data)) self._decoded...
391,228
Sets the decoded stream size. This function is used to set the decoded stream size if it can be determined separately. Args: decoded_stream_size (int): size of the decoded stream in bytes. Raises: IOError: if the file-like object is already open. OSError: if the file-like object is ...
def SetDecodedStreamSize(self, decoded_stream_size): if self._is_open: raise IOError('Already open.') if decoded_stream_size < 0: raise ValueError(( 'Invalid decoded stream size: {0:d} value out of ' 'bounds.').format(decoded_stream_size)) self._decoded_stream_size = d...
391,229
Reads a byte string from the file-like object at the current offset. The function will read a byte string of the specified size or all of the remaining data if no size was specified. Args: size (Optional[int]): number of bytes to read, where None is all remaining data. Returns: ...
def read(self, size=None): if not self._is_open: raise IOError('Not opened.') if self._current_offset < 0: raise IOError( 'Invalid current offset: {0:d} value less than zero.'.format( self._current_offset)) if self._decoded_stream_size is None: self._decoded_...
391,230
Seeks to an offset within the file-like object. Args: offset (int): offset to seek to. whence (Optional(int)): value that indicates whether offset is an absolute or relative position within the file. Raises: IOError: if the seek failed. OSError: if the seek failed.
def seek(self, offset, whence=os.SEEK_SET): if not self._is_open: raise IOError('Not opened.') if self._current_offset < 0: raise IOError( 'Invalid current offset: {0:d} value less than zero.'.format( self._current_offset)) if whence == os.SEEK_CUR: offset +=...
391,231
Initializes the volume attribute object. Args: identifier (str): identifier of the attribute within the volume. value (object): value of the attribute.
def __init__(self, identifier, value): super(VolumeAttribute, self).__init__() self.identifier = identifier self.value = value
391,233
Initializes a volume extent. Args: offset (int): start offset of the extent, in bytes. size (int): size of the extent, in bytes. extent_type (Optional[str]): type of extent.
def __init__(self, offset, size, extent_type=EXTENT_TYPE_DATA): super(VolumeExtent, self).__init__() self.offset = offset self.size = size self.extent_type = extent_type
391,234
Initializes a volume. Args: identifier (str): identifier of the attribute within the volume.
def __init__(self, identifier): super(Volume, self).__init__() self.identifier = identifier self._attributes = {} self._extents = [] self._is_parsed = False
391,235
Adds an attribute. Args: attribute (VolumeAttribute): a volume attribute. Raises: KeyError: if volume attribute is already set for the corresponding volume attribute identifier.
def _AddAttribute(self, attribute): if attribute.identifier in self._attributes: raise KeyError(( 'Volume attribute object already set for volume attribute ' 'identifier: {0:s}.').format(attribute.identifier)) self._attributes[attribute.identifier] = attribute
391,236
Retrieves a specific attribute. Args: identifier (str): identifier of the attribute within the volume. Returns: VolumeAttribute: volume attribute or None if not available.
def GetAttribute(self, identifier): if not self._is_parsed: self._Parse() self._is_parsed = True if identifier not in self._attributes: return None return self._attributes[identifier]
391,241
Adds a volume. Args: volume (Volume): a volume. Raises: KeyError: if volume is already set for the corresponding volume identifier.
def _AddVolume(self, volume): if volume.identifier in self._volumes: raise KeyError( 'Volume object already set for volume identifier: {0:s}'.format( volume.identifier)) self._volumes[volume.identifier] = volume self._volume_identifiers.append(volume.identifier)
391,243
Retrieves a specific section based on the index. Args: section_index (int): index of the section. Returns: VolumeExtent: a volume extent or None if not available.
def GetSectionByIndex(self, section_index): if not self._is_parsed: self._Parse() self._is_parsed = True if section_index < 0 or section_index >= len(self._sections): return None return self._sections[section_index]
391,248
Retrieves a specific volume based on the identifier. Args: volume_identifier (str): identifier of the volume within the volume system. Returns: Volume: a volume.
def GetVolumeByIdentifier(self, volume_identifier): if not self._is_parsed: self._Parse() self._is_parsed = True return self._volumes[volume_identifier]
391,249
Retrieves a specific volume based on the index. Args: volume_index (int): index of the volume. Returns: Volume: a volume or None if not available.
def GetVolumeByIndex(self, volume_index): if not self._is_parsed: self._Parse() self._is_parsed = True if volume_index < 0 or volume_index >= len(self._volume_identifiers): return None volume_identifier = self._volume_identifiers[volume_index] return self._volumes[volume_identif...
391,250
Initializes a file-like object. If the file-like object is chained do not separately use the parent file-like object. Args: resolver_context (Context): resolver context. compression_method (Optional[str]): method used to the compress the data. file_object (Optional[file]): parent file-li...
def __init__( self, resolver_context, compression_method=None, file_object=None): if file_object is not None and compression_method is None: raise ValueError( 'File-like object provided without corresponding compression ' 'method.') super(CompressedStream, self).__init__(re...
391,251
Aligns the compressed file with the uncompressed data offset. Args: uncompressed_data_offset (int): uncompressed data offset.
def _AlignUncompressedDataOffset(self, uncompressed_data_offset): self._file_object.seek(0, os.SEEK_SET) self._decompressor = self._GetDecompressor() self._uncompressed_data = b'' compressed_data_offset = 0 compressed_data_size = self._file_object.get_size() while compressed_data_offset ...
391,254
Reads compressed data from the file-like object. Args: read_size (int): number of bytes of compressed data to read. Returns: int: number of bytes of compressed data read.
def _ReadCompressedData(self, read_size): compressed_data = self._file_object.read(read_size) read_count = len(compressed_data) self._compressed_data = b''.join([self._compressed_data, compressed_data]) self._uncompressed_data, self._compressed_data = ( self._decompressor.Decompress(self...
391,255
Reads a byte string from the file-like object at the current offset. The function will read a byte string of the specified size or all of the remaining data if no size was specified. Args: size (Optional[int]): number of bytes to read, where None is all remaining data. Returns: ...
def read(self, size=None): if not self._is_open: raise IOError('Not opened.') if self._current_offset < 0: raise IOError( 'Invalid current offset: {0:d} value less than zero.'.format( self._current_offset)) if self._uncompressed_stream_size is None: self._unc...
391,256
Seeks to an offset within the file-like object. Args: offset (int): offset to seek to. whence (Optional(int)): value that indicates whether offset is an absolute or relative position within the file. Raises: IOError: if the seek failed. OSError: if the seek failed.
def seek(self, offset, whence=os.SEEK_SET): if not self._is_open: raise IOError('Not opened.') if self._current_offset < 0: raise IOError( 'Invalid current offset: {0:d} value less than zero.'.format( self._current_offset)) if whence == os.SEEK_CUR: offset +=...
391,257
Initializes a file-like object. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(TSKPartitionFile, self).__init__(resolver_context) self._file_system = None
391,259
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 ...
def _Open(self, path_spec=None, mode='rb'): if not path_spec: raise ValueError('Missing path specification.') if not path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') self._file_system = resolver.Resolver.OpenFileSystem( ...
391,260
Initializes a file entry. 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...
def __init__( self, resolver_context, file_system, path_spec, is_root=False, is_virtual=False): compressed_stream = resolver.Resolver.OpenFileObject( path_spec, resolver_context=resolver_context) if not compressed_stream: raise errors.BackEndError( 'Unable to open compre...
391,261
Initializes a file system. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(VShadowFileSystem, self).__init__(resolver_context) self._file_object = None self._vshadow_volume = None
391,264
Opens the file system object 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: ...
def _Open(self, path_spec, mode='rb'): 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_volu...
391,266
Determines if a file entry for a path specification exists. Args: path_spec (PathSpec): path specification. Returns: bool: True if the file entry exists.
def FileEntryExistsByPathSpec(self, path_spec): store_index = vshadow.VShadowPathSpecGetStoreIndex(path_spec) # The virtual root file has not corresponding store index but # should have a location. if store_index is None: location = getattr(path_spec, 'location', None) return location ...
391,267
Retrieves a file entry for a path specification. Args: path_spec (PathSpec): path specification. Returns: VShadowFileEntry: file entry or None if not available.
def GetFileEntryByPathSpec(self, path_spec): store_index = vshadow.VShadowPathSpecGetStoreIndex(path_spec) # The virtual root file has not corresponding store index but # should have a location. if store_index is None: location = getattr(path_spec, 'location', None) if location is None...
391,268
Retrieves a VSS store for a path specification. Args: path_spec (PathSpec): path specification. Returns: pyvshadow.store: a VSS store or None if not available.
def GetVShadowStoreByPathSpec(self, path_spec): store_index = vshadow.VShadowPathSpecGetStoreIndex(path_spec) if store_index is None: return None return self._vshadow_volume.get_store(store_index)
391,270
Initializes a file-like object. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(TSKFile, self).__init__(resolver_context) self._current_offset = 0 self._file_system = None self._size = 0 self._tsk_attribute = None self._tsk_file = None
391,271
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 ...
def _Open(self, path_spec=None, mode='rb'): if not path_spec: raise ValueError('Missing path specification.') data_stream = getattr(path_spec, 'data_stream', None) file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) file_entry = file_...
391,273
Reads a byte string from the file-like object at the current offset. The function will read a byte string of the specified size or all of the remaining data if no size was specified. Args: size (Optional[int]): number of bytes to read, where None is all remaining data. Returns: ...
def read(self, size=None): if not self._is_open: raise IOError('Not opened.') if self._current_offset < 0: raise IOError('Invalid current offset value less than zero.') # The SleuthKit is not POSIX compliant in its read behavior. Therefore # pytsk3 will raise an IOError if the read of...
391,274
Initializes a LVM volume. Args: file_entry (LVMFileEntry): a LVM file entry.
def __init__(self, file_entry): super(LVMVolume, self).__init__(file_entry.name) self._file_entry = file_entry
391,275
Initializes a file-like object. Args: resolver_context (Context): resolver context.
def __init__(self, resolver_context): super(ZipFile, self).__init__(resolver_context) self._compressed_data = b'' self._current_offset = 0 self._file_system = None self._realign_offset = True self._uncompressed_data = b'' self._uncompressed_data_offset = 0 self._uncompressed_data_si...
391,278
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. OSErro...
def _Open(self, path_spec=None, mode='rb'): if not path_spec: raise ValueError('Missing path specification.') file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) file_entry = file_system.GetFileEntryByPathSpec(path_spec) if not file_en...
391,280
Aligns the compressed file with the uncompressed data offset. Args: uncompressed_data_offset (int): uncompressed data offset. Raises: IOError: if the ZIP file could not be opened. OSError: if the ZIP file could not be opened.
def _AlignUncompressedDataOffset(self, uncompressed_data_offset): if self._zip_ext_file: self._zip_ext_file.close() self._zip_ext_file = None try: # The open can fail if the file path in the local file header # does not use the same path segment separator as the corresponding ...
391,281
Reads compressed data from the file-like object. Args: read_size (int): number of bytes of compressed data to read.
def _ReadCompressedData(self, read_size): self._uncompressed_data = self._zip_ext_file.read(read_size) self._uncompressed_data_size = len(self._uncompressed_data)
391,282
Initializes a decrypter. Args: kwargs (dict): keyword arguments depending on the decrypter. Raises: ValueError: when there are unused keyword arguments.
def __init__(self, **kwargs): if kwargs: raise ValueError('Unused keyword arguments: {0:s}.'.format( ', '.join(kwargs))) super(Decrypter, self).__init__()
391,283
Retrieves the format specification. Args: file_object (FileIO): file-like object. Returns: str: type indicator if the file-like object contains a supported format or None otherwise.
def AnalyzeFileObject(self, file_object): tsk_image_object = tsk_image.TSKFileSystemImage(file_object) try: pytsk3.Volume_Info(tsk_image_object) except IOError: return None return self.type_indicator
391,284
Checks the file entry type find specifications. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not or None if no file entry type specification is defined.
def _CheckFileEntryType(self, file_entry): if not self._file_entry_types: return None return ( self._CheckIsDevice(file_entry) or self._CheckIsDirectory(file_entry) or self._CheckIsFile(file_entry) or self._CheckIsLink(file_entry) or self._CheckIsPipe(file_entry) or self._Che...
391,286
Checks the is_device find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsDevice(self, file_entry): if definitions.FILE_ENTRY_TYPE_DEVICE not in self._file_entry_types: return False return file_entry.IsDevice()
391,287
Checks the is_directory find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsDirectory(self, file_entry): if definitions.FILE_ENTRY_TYPE_DIRECTORY not in self._file_entry_types: return False return file_entry.IsDirectory()
391,288
Checks the is_file find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsFile(self, file_entry): if definitions.FILE_ENTRY_TYPE_FILE not in self._file_entry_types: return False return file_entry.IsFile()
391,289
Checks the is_link find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsLink(self, file_entry): if definitions.FILE_ENTRY_TYPE_LINK not in self._file_entry_types: return False return file_entry.IsLink()
391,290
Checks the is_pipe find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsPipe(self, file_entry): if definitions.FILE_ENTRY_TYPE_PIPE not in self._file_entry_types: return False return file_entry.IsPipe()
391,291
Checks the is_socket find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckIsSocket(self, file_entry): if definitions.FILE_ENTRY_TYPE_SOCKET not in self._file_entry_types: return False return file_entry.IsSocket()
391,292
Checks the location find specification. Args: file_entry (FileEntry): file entry. search_depth (int): number of location path segments to compare. Returns: bool: True if the file entry matches the find specification, False if not.
def _CheckLocation(self, file_entry, search_depth): if self._location_segments is None: return False if search_depth < 0 or search_depth > self._number_of_location_segments: return False # Note that the root has no entry in the location segments and # no name to match. if search_d...
391,293
Determines if the find specification is at maximum depth. Args: search_depth (int): number of location path segments to compare. Returns: bool: True if at maximum depth, False if not.
def AtMaximumDepth(self, search_depth): if self._location_segments is not None: if search_depth >= self._number_of_location_segments: return True return False
391,294