docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
Retrieves a file entry for a path specification.
Args:
path_spec (PathSpec): path specification.
Returns:
FVDEFileEntry: file entry or None. | def GetFileEntryByPathSpec(self, path_spec):
return fvde_file_entry.FVDEFileEntry(
self._resolver_context, self, path_spec, is_root=True, is_virtual=True) | 391,646 |
Decompresses the compressed data.
Args:
compressed_data (bytes): compressed data.
Returns:
tuple(bytes, bytes): uncompressed data and remaining compressed data.
Raises:
BackEndError: if the XZ compressed stream cannot be decompressed. | def Decompress(self, compressed_data):
try:
if hasattr(lzma, 'LZMA_VERSION'):
# Note that we cannot use max_length=0 here due to different
# versions of the lzma code.
uncompressed_data = self._lzma_decompressor.decompress(
compressed_data, 0)
else:
uncom... | 391,649 |
Initializes a path specification.
Note that the encrypted stream path specification must have a parent.
Args:
cipher_mode (Optional[str]): cipher mode.
encryption_method (Optional[str]): method used to the encrypt the data.
initialization_vector (Optional[bytes]): initialization vector.
... | def __init__(
self, cipher_mode=None, encryption_method=None,
initialization_vector=None, key=None, parent=None, **kwargs):
if not encryption_method or not parent:
raise ValueError('Missing encryption method or parent value.')
super(EncryptedStreamPathSpec, self).__init__(parent=parent, ... | 391,650 |
Initializes a path specification.
Note that an APFS path specification must have a parent.
Args:
identifier (Optional[int]): identifier.
location (Optional[str]): location.
parent (Optional[PathSpec]): parent path specification.
Raises:
ValueError: when parent or both identifier a... | def __init__(
self, identifier=None, location=None, parent=None, **kwargs):
if (not identifier and not location) or not parent:
raise ValueError('Missing identifier and location, or parent value.')
super(APFSPathSpec, self).__init__(parent=parent, **kwargs)
self.identifier = identifier
... | 391,652 |
Initializes an image object.
Args:
file_object (FileIO): file-like object.
Raises:
ValueError: if the file-like object is invalid. | def __init__(self, file_object):
if not file_object:
raise ValueError('Missing file-like object.')
# pytsk3.Img_Info does not let you set attributes after initialization.
self._file_object = file_object
# Using the old parent class invocation style otherwise some versions
# of pylint com... | 391,653 |
Reads a byte string from the image object at the specified offset.
Args:
offset (int): offset where to start reading.
size (int): number of bytes to read.
Returns:
bytes: data read. | def read(self, offset, size):
self._file_object.seek(offset, os.SEEK_SET)
return self._file_object.read(size) | 391,654 |
Initializes a SleuthKit timestamp.
Args:
fraction_of_second (Optional[int]): fraction of second, which is
an integer that contains the number 100 nano seconds before
Sleuthkit 4.2.0 or number of nano seconds in Sleuthkit 4.2.0
and later.
timestamp (Optional[int]): POSIX ti... | def __init__(self, fraction_of_second=None, timestamp=None):
# Sleuthkit 4.2.0 switched from 100 nano seconds precision to
# 1 nano second precision.
if pytsk3.TSK_VERSION_NUM >= 0x040200ff:
precision = dfdatetime_definitions.PRECISION_1_NANOSECOND
else:
precision = dfdatetime_definitio... | 391,655 |
Copies a SleuthKit timestamp from a date and time string.
Args:
time_string (str): date and time value formatted as:
YYYY-MM-DD hh:mm:ss.######[+-]##:##
Where # are numeric digits ranging from 0 to 9 and the seconds
fraction can be either 3 or 6 digits. The time of day, seconds... | def CopyFromDateTimeString(self, time_string):
date_time_values = self._CopyDateTimeFromString(time_string)
year = date_time_values.get('year', 0)
month = date_time_values.get('month', 0)
day_of_month = date_time_values.get('day_of_month', 0)
hours = date_time_values.get('hours', 0)
minute... | 391,657 |
Initializes an attribute.
Args:
tsk_attribute (pytsk3.Attribute): TSK attribute. | def __init__(self, tsk_attribute):
super(TSKAttribute, self).__init__()
self._tsk_attribute = tsk_attribute | 391,661 |
Initializes a data stream.
Args:
file_system (TSKFileSystem): file system.
tsk_attribute (pytsk3.Attribute): TSK attribute. | def __init__(self, file_system, tsk_attribute):
super(TSKDataStream, self).__init__()
self._file_system = file_system
self._tsk_attribute = tsk_attribute | 391,662 |
Retrieves a date and time value.
Args:
name (str): name of the date and time value, for example "atime" or
"mtime".
Returns:
dfdatetime.DateTimeValues: date and time value or None if not available. | def _GetTimeValue(self, name):
timestamp = getattr(self._tsk_file.info.meta, name, None)
if self._file_system_type in self._TSK_HAS_NANO_FS_TYPES:
name_fragment = '{0:s}_nano'.format(name)
fraction_of_second = getattr(
self._tsk_file.info.meta, name_fragment, None)
else:
fr... | 391,673 |
Retrieves the file-like object.
Args:
data_stream_name (Optional[str]): data stream name, where an empty
string represents the default data stream.
Returns:
TSKFileIO: file-like object or None. | def GetFileObject(self, data_stream_name=''):
data_stream_names = [
data_stream.name for data_stream in self._GetDataStreams()]
if data_stream_name and data_stream_name not in data_stream_names:
return None
path_spec = copy.deepcopy(self.path_spec)
if data_stream_name:
# For HF... | 391,676 |
Opens the FVDE volume using the path specification.
Args:
fvde_volume (pyfvde.volume): FVDE volume.
path_spec (PathSpec): path specification.
file_object (FileIO): file-like object.
key_chain (KeyChain): key chain. | def FVDEVolumeOpen(fvde_volume, path_spec, file_object, key_chain):
encrypted_root_plist = key_chain.GetCredential(
path_spec, 'encrypted_root_plist')
if encrypted_root_plist:
fvde_volume.read_encrypted_root_plist(encrypted_root_plist)
password = key_chain.GetCredential(path_spec, 'password')
if p... | 391,679 |
Retrieves the store index from the path specification.
Args:
path_spec (PathSpec): path specification.
Returns:
int: store index or None if not available. | def VShadowPathSpecGetStoreIndex(path_spec):
store_index = getattr(path_spec, 'store_index', None)
if store_index is None:
location = getattr(path_spec, 'location', None)
if location is None or not location.startswith('/vss'):
return None
store_index = None
try:
store_index = int(l... | 391,680 |
Initializes a file-like object.
Args:
resolver_context (Context): resolver context.
Raises:
ValueError: when file_object is set. | def __init__(self, resolver_context):
super(GzipFile, self).__init__(resolver_context)
self._compressed_data_size = -1
self._current_offset = 0
self._gzip_file_object = None
self._members_by_end_offset = collections.OrderedDict()
self.uncompressed_data_size = 0 | 391,681 |
Finds the member whose data includes the provided offset.
Args:
offset (int): offset in the uncompressed data to find the
containing member for.
Returns:
gzipfile.GzipMember: gzip file member or None if not available.
Raises:
ValueError: if the provided offset is outside of th... | def _GetMemberForOffset(self, offset):
if offset < 0 or offset >= self.uncompressed_data_size:
raise ValueError('Offset {0:d} is larger than file size {1:d}.'.format(
offset, self.uncompressed_data_size))
for end_offset, member in iter(self._members_by_end_offset.items()):
if offset ... | 391,682 |
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 or the file has not been opened.
OSError... | def seek(self, offset, whence=os.SEEK_SET):
if not self._gzip_file_object:
raise IOError('Not opened.')
if whence == os.SEEK_CUR:
offset += self._current_offset
elif whence == os.SEEK_END:
offset += self.uncompressed_data_size
elif whence != os.SEEK_SET:
raise IOError('Unsu... | 391,683 |
Reads a byte string from the gzip file at the current offset.
The function will read a byte string up to 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:
byte... | def read(self, size=None):
data = b''
while ((size and len(data) < size) and
self._current_offset < self.uncompressed_data_size):
member = self._GetMemberForOffset(self._current_offset)
member_offset = self._current_offset - member.uncompressed_data_offset
data_read = member.Re... | 391,684 |
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.')
if not path_spec.HasParent():
raise errors.PathSpecError(
'Unsupported path specification without parent.')
self._gzip_file_object = resolver.Resolver.OpenFileObject(
... | 391,685 |
Initializes a path specification.
Args:
parent (Optional[PathSpec]): parent path specification.
kwargs (dict[str, object]): keyword arguments depending on the path
specification.
Raises:
ValueError: if a derived path specification class does not define a type
indicator or... | def __init__(self, parent=None, **kwargs):
if kwargs:
raise ValueError('Unused keyword arguments: {0:s}.'.format(
', '.join(kwargs)))
super(PathSpec, self).__init__()
self.parent = parent
if not getattr(self, 'TYPE_INDICATOR', None):
raise ValueError('Missing type indicator.... | 391,687 |
Retrieves the comparable representation.
This is a convenience function for constructing comparables.
Args:
sub_comparable_string (str): sub comparable string.
Returns:
str: comparable representation of the path specification. | def _GetComparable(self, sub_comparable_string=''):
string_parts = []
string_parts.append(getattr(self.parent, 'comparable', ''))
string_parts.append('type: {0:s}'.format(self.type_indicator))
if sub_comparable_string:
string_parts.append(', {0:s}'.format(sub_comparable_string))
string_... | 391,689 |
Initializes a path specification.
Note that the FVDE path specification must have a parent.
Args:
encrypted_root_plist (Optional[str]): path to the
EncryptedRoot.plist.wipekey file.
password (Optional[str]): password.
parent (Optional[PathSpec]): parent path specification.
re... | def __init__(
self, encrypted_root_plist=None, password=None, parent=None,
recovery_password=None, **kwargs):
if not parent:
raise ValueError('Missing parent value.')
super(FVDEPathSpec, self).__init__(parent=parent, **kwargs)
self.encrypted_root_plist = encrypted_root_plist
self... | 391,691 |
Deregisters a path specification mount point.
Args:
mount_point (str): mount point identifier.
Raises:
KeyError: if the corresponding mount point is not set. | def DeregisterMountPoint(cls, mount_point):
if mount_point not in cls._mount_points:
raise KeyError('Mount point: {0:s} not set.'.format(mount_point))
del cls._mount_points[mount_point] | 391,693 |
Registers a path specification mount point.
Args:
mount_point (str): mount point identifier.
path_spec (PathSpec): path specification of the mount point.
Raises:
KeyError: if the corresponding mount point is already set. | def RegisterMountPoint(cls, mount_point, path_spec):
if mount_point in cls._mount_points:
raise KeyError('Mount point: {0:s} already set.'.format(mount_point))
cls._mount_points[mount_point] = path_spec | 391,694 |
Deregisters a path specification resolver helper.
Args:
resolver_helper (ResolverHelper): resolver helper.
Raises:
KeyError: if resolver helper object is not set for the corresponding
type indicator. | def DeregisterHelper(cls, resolver_helper):
if resolver_helper.type_indicator not in cls._resolver_helpers:
raise KeyError(
'Resolver helper object not set for type indicator: {0:s}.'.format(
resolver_helper.type_indicator))
del cls._resolver_helpers[resolver_helper.type_indi... | 391,695 |
Retrieves the path specification resolver helper for the specified type.
Args:
type_indicator (str): type indicator.
Returns:
ResolverHelper: a resolver helper.
Raises:
KeyError: if resolver helper is not set for the corresponding type
indicator. | def GetHelper(cls, type_indicator):
if type_indicator not in cls._resolver_helpers:
raise KeyError(
'Resolver helper not set for type indicator: {0:s}.'.format(
type_indicator))
return cls._resolver_helpers[type_indicator] | 391,696 |
Registers a path specification resolver helper.
Args:
resolver_helper (ResolverHelper): resolver helper.
Raises:
KeyError: if resolver helper object is already set for the corresponding
type indicator. | def RegisterHelper(cls, resolver_helper):
if resolver_helper.type_indicator in cls._resolver_helpers:
raise KeyError((
'Resolver helper object already set for type indicator: '
'{0!s}.').format(resolver_helper.type_indicator))
cls._resolver_helpers[resolver_helper.type_indicator]... | 391,697 |
Initializes a path specification.
Note that the compressed stream path specification must have a parent.
Args:
compression_method (Optional[str]): method used to the compress the data.
parent (Optional[PathSpec]): parent path specification.
Raises:
ValueError: when compression method or... | def __init__(self, compression_method=None, parent=None, **kwargs):
if not compression_method or not parent:
raise ValueError('Missing compression method or parent value.')
super(CompressedStreamPathSpec, self).__init__(parent=parent, **kwargs)
self.compression_method = compression_method | 391,698 |
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.
file_object (Optional[file]): parent file-like object. | def __init__(self, resolver_context, file_object=None):
super(DataRange, self).__init__(resolver_context)
self._current_offset = 0
self._file_object = file_object
if file_object:
self._file_object_set_in_init = True
self._range_offset = 0
self._range_size = file_object.get_size()... | 391,700 |
Sets the data range (offset and size).
The data range is used to map a range of data within one file
(e.g. a single partition within a full disk image) as a file-like object.
Args:
range_offset (int): start offset of the data range.
range_size (int): size of the data range.
Raises:
... | def SetRange(self, range_offset, range_size):
if self._is_open:
raise IOError('Already open.')
if range_offset < 0:
raise ValueError(
'Invalid range offset: {0:d} value out of bounds.'.format(
range_offset))
if range_size < 0:
raise ValueError(
'Inv... | 391,702 |
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._range_offset < 0 or self._range_size < 0:
raise IOError('Invalid data range.')
if self._current_offset < 0:
raise IOError(
'Invalid current offset: {0:d} value less than zero.'.format(
... | 391,703 |
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,704 |
Initializes a path specification.
Note that the EWF file path specification must have a parent.
Args:
parent (Optional[PathSpec]): parent path specification.
Raises:
ValueError: when parent is not set. | def __init__(self, parent=None, **kwargs):
if not parent:
raise ValueError('Missing parent value.')
super(EWFPathSpec, self).__init__(parent=parent, **kwargs) | 391,705 |
Initializes a compressed stream file system.
Args:
resolver_context (Context): a resolver context. | def __init__(self, resolver_context):
super(CompressedStreamFileSystem, self).__init__(resolver_context)
self._compression_method = None | 391,706 |
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 th... | def _Open(self, path_spec, mode='rb'):
if not path_spec.HasParent():
raise errors.PathSpecError(
'Unsupported path specification without parent.')
compression_method = getattr(path_spec, 'compression_method', None)
if not compression_method:
raise errors.PathSpecError(
... | 391,707 |
Retrieves a file entry for a path specification.
Args:
path_spec (PathSpec): a path specification.
Returns:
CompressedStreamFileEntry: a file entry or None if not available. | def GetFileEntryByPathSpec(self, path_spec):
return compressed_stream_file_entry.CompressedStreamFileEntry(
self._resolver_context, self, path_spec, is_root=True, is_virtual=True) | 391,708 |
Initializes a directory.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification. | def __init__(self, file_system, path_spec):
super(Directory, self).__init__()
self._entries = None
self._file_system = file_system
self.path_spec = path_spec | 391,710 |
Retrieves a data stream by name.
Args:
name (str): name of the data stream.
case_sensitive (Optional[bool]): True if the name is case sensitive.
Returns:
DataStream: a data stream or None if not available.
Raises:
ValueError: if the name is not string. | def GetDataStream(self, name, case_sensitive=True):
if not isinstance(name, py2to3.STRING_TYPES):
raise ValueError('Name is not a string.')
name_lower = name.lower()
matching_data_stream = None
for data_stream in self._GetDataStreams():
if data_stream.name == name:
return data... | 391,716 |
Retrieves the file-like object.
Args:
data_stream_name (Optional[str]): name of the data stream, where an empty
string represents the default data stream.
Returns:
FileIO: a file-like object or None if not available. | def GetFileObject(self, data_stream_name=''):
if data_stream_name:
return None
return resolver.Resolver.OpenFileObject(
self.path_spec, resolver_context=self._resolver_context) | 391,717 |
Retrieves a sub file entry by name.
Args:
name (str): name of the file entry.
case_sensitive (Optional[bool]): True if the name is case sensitive.
Returns:
FileEntry: a file entry or None if not available. | def GetSubFileEntryByName(self, name, case_sensitive=True):
name_lower = name.lower()
matching_sub_file_entry = None
for sub_file_entry in self.sub_file_entries:
if sub_file_entry.name == name:
return sub_file_entry
if not case_sensitive and sub_file_entry.name.lower() == name_low... | 391,718 |
Determines if the file entry has specific data stream.
Args:
name (str): name of the data stream.
case_sensitive (Optional[bool]): True if the name is case sensitive.
Returns:
bool: True if the file entry has the data stream.
Raises:
ValueError: if the name is not string. | def HasDataStream(self, name, case_sensitive=True):
if not isinstance(name, py2to3.STRING_TYPES):
raise ValueError('Name is not a string.')
name_lower = name.lower()
for data_stream in self._GetDataStreams():
if data_stream.name == name:
return True
if not case_sensitive an... | 391,720 |
Initializes a path specification.
Note that the data range path specification must have a parent.
Args:
parent (Optional[PathSpec]): parent path specification.
range_offset (Optional[int]): start offset of the data range.
range_size (Optional[int]): size of the data range.
Raises:
... | def __init__(self, parent=None, range_offset=None, range_size=None, **kwargs):
if not range_offset or not range_size or not parent:
raise ValueError('Missing range offset, range size or parent value.')
super(DataRangePathSpec, self).__init__(parent=parent, **kwargs)
self.range_offset = range_off... | 391,728 |
Initializes a volume.
Args:
file_entry (TSKPartitionFileEntry): a TSK partition file entry.
bytes_per_sector (int): number of bytes per sector. | def __init__(self, file_entry, bytes_per_sector):
super(TSKVolume, self).__init__(file_entry.name)
self._file_entry = file_entry
self._bytes_per_sector = bytes_per_sector | 391,730 |
Opens a volume defined by path specification.
Args:
path_spec (PathSpec): a path specification.
Raises:
VolumeSystemError: if the TSK partition virtual file system could not
be resolved. | def Open(self, path_spec):
self._file_system = resolver.Resolver.OpenFileSystem(path_spec)
if self._file_system is None:
raise errors.VolumeSystemError('Unable to resolve path specification.')
type_indicator = self._file_system.type_indicator
if type_indicator != definitions.TYPE_INDICATOR_T... | 391,734 |
Initializes a path specification.
Note that the encoded stream path specification must have a parent.
Args:
encoding_method (Optional[str]): method used to the encode the data.
parent (Optional[PathSpec]): parent path specification.
Raises:
ValueError: when encoding method or parent are... | def __init__(self, encoding_method=None, parent=None, **kwargs):
if not encoding_method or not parent:
raise ValueError('Missing encoding method or parent value.')
super(EncodedStreamPathSpec, self).__init__(parent=parent, **kwargs)
self.encoding_method = encoding_method | 391,735 |
Initializes a file system.
Args:
resolver_context (Context): resolver context. | def __init__(self, resolver_context):
super(LVMFileSystem, self).__init__(resolver_context)
self._file_object = None
self._vslvm_volume_group = None
self._vslvm_handle = None | 391,737 |
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:
vslvm_handle... | 391,739 |
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):
volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)
# The virtual root file has not corresponding volume index but
# should have a location.
if volume_index is None:
location = getattr(path_spec, 'location', None)
return location is n... | 391,740 |
Retrieves a file entry for a path specification.
Args:
path_spec (PathSpec): path specification.
Returns:
LVMFileEntry: a file entry or None if not available. | def GetFileEntryByPathSpec(self, path_spec):
volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)
# The virtual root file has not corresponding volume index but
# should have a location.
if volume_index is None:
location = getattr(path_spec, 'location', None)
if location is None or ... | 391,741 |
Retrieves a LVM logical volume for a path specification.
Args:
path_spec (PathSpec): path specification.
Returns:
pyvslvm.logical_volume: a LVM logical volume or None if not available. | def GetLVMLogicalVolumeByPathSpec(self, path_spec):
volume_index = lvm.LVMPathSpecGetVolumeIndex(path_spec)
if volume_index is None:
return None
return self._vslvm_volume_group.get_logical_volume(volume_index) | 391,742 |
Initializes a file-like object.
Args:
resolver_context (Context): resolver context. | def __init__(self, resolver_context):
super(TARFile, self).__init__(resolver_context)
self._current_offset = 0
self._file_system = None
self._size = 0
self._tar_ext_file = None | 391,744 |
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,746 |
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.')
if self._current_offset > self._size:
return b''
if size is None or self._current_offset + size > self._size:... | 391,747 |
Extracts credentials from a path specification.
Args:
path_spec (PathSpec): path specification to extract credentials from. | def ExtractCredentialsFromPathSpec(self, path_spec):
credentials = manager.CredentialsManager.GetCredentials(path_spec)
for identifier in credentials.CREDENTIALS:
value = getattr(path_spec, identifier, None)
if value is None:
continue
self.SetCredential(path_spec, identifier, val... | 391,748 |
Retrieves a specific credential from the key chain.
Args:
path_spec (PathSpec): path specification.
identifier (str): credential identifier.
Returns:
object: credential or None if the credential for the path specification
is not set. | def GetCredential(self, path_spec, identifier):
credentials = self._credentials_per_path_spec.get(path_spec.comparable, {})
return credentials.get(identifier, None) | 391,749 |
Sets a specific credential for the path specification.
Args:
path_spec (PathSpec): path specification.
identifier (str): credential identifier.
data (object): credential data.
Raises:
KeyError: if the credential is not supported by the path specification
type. | def SetCredential(self, path_spec, identifier, data):
supported_credentials = manager.CredentialsManager.GetCredentials(path_spec)
if identifier not in supported_credentials.CREDENTIALS:
raise KeyError((
'Unsuppored credential: {0:s} for path specification type: '
'{1:s}').format... | 391,750 |
Initializes the file entry object.
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.
i... | def __init__(
self, resolver_context, file_system, path_spec, is_root=False,
is_virtual=False):
bde_volume = file_system.GetBDEVolume()
if bde_volume is None:
raise errors.BackEndError('Missing BDE volume.')
super(BDEFileEntry, self).__init__(
resolver_context, file_system, p... | 391,751 |
Globs for path specifications according to the EWF naming schema.
Args:
file_system (FileSystem): file system.
path_spec (PathSpec): path specification.
Returns:
list[PathSpec]: path specifications that match the glob.
Raises:
PathSpecError: if the path specification is invalid.
RuntimeErro... | def EWFGlobPathSpec(file_system, path_spec):
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.Pat... | 391,754 |
Initializes a path specification.
Note that the TAR file path specification must have a parent.
Args:
location (str): TAR file internal location string prefixed with a path
separator character.
parent (Optional[PathSpec]): parent path specification.
Raises:
ValueError: when pa... | def __init__(self, location=None, parent=None, **kwargs):
if not parent:
raise ValueError('Missing parent value.')
super(TARPathSpec, self).__init__(
location=location, parent=parent, **kwargs) | 391,755 |
Adds the parent directories of a path to the fake file system.
Args:
path (str): path of the file within the fake file system.
Raises:
ValueError: if a parent directory is already set and is not a directory. | def _AddParentDirectories(self, path):
path_segments = self.file_system.SplitPath(path)
for segment_index in range(len(path_segments)):
parent_path = self.file_system.JoinPath(path_segments[:segment_index])
file_entry = self.file_system.GetFileEntryByPath(parent_path)
if file_entry and no... | 391,757 |
Adds a directory to the fake file system.
Note that this function will create parent directories if needed.
Args:
path (str): path of the directory within the fake file system.
Raises:
ValueError: if the path is already set. | def AddDirectory(self, path):
if self.file_system.FileEntryExistsByPath(path):
raise ValueError('Path: {0:s} already set.'.format(path))
self._AddParentDirectories(path)
self.file_system.AddFileEntry(
path, file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY) | 391,758 |
Adds a "regular" file to the fake file system.
Note that this function will create parent directories if needed.
Args:
path (str): path of the file within the fake file system.
file_data (bytes): data of the file.
Raises:
ValueError: if the path is already set. | def AddFile(self, path, file_data):
if self.file_system.FileEntryExistsByPath(path):
raise ValueError('Path: {0:s} already set.'.format(path))
self._AddParentDirectories(path)
self.file_system.AddFileEntry(path, file_data=file_data) | 391,759 |
Adds a "regular" file to the fake file system.
Args:
path (str): path of the file within the fake file system.
file_data_path (str): path of the file to read the file data from.
Raises:
ValueError: if the path is already set. | def AddFileReadData(self, path, file_data_path):
if self.file_system.FileEntryExistsByPath(path):
raise ValueError('Path: {0:s} already set.'.format(path))
with open(file_data_path, 'rb') as file_object:
file_data = file_object.read()
self._AddParentDirectories(path)
self.file_system.... | 391,760 |
Adds a symbolic link to the fake file system.
Args:
path (str): path of the symbolic link within the fake file system.
linked_path (str): path that is linked.
Raises:
ValueError: if the path is already set. | def AddSymbolicLink(self, path, linked_path):
if self.file_system.FileEntryExistsByPath(path):
raise ValueError('Path: {0:s} already set.'.format(path))
self._AddParentDirectories(path)
self.file_system.AddFileEntry(
path, file_entry_type=definitions.FILE_ENTRY_TYPE_LINK,
link_da... | 391,761 |
Deregisters a path specification credentials.
Args:
credentials (Credentials): credentials.
Raises:
KeyError: if credential object is not set for the corresponding
type indicator. | def DeregisterCredentials(cls, credentials):
if credentials.type_indicator not in cls._credentials:
raise KeyError(
'Credential object not set for type indicator: {0:s}.'.format(
credentials.type_indicator))
del cls._credentials[credentials.type_indicator] | 391,762 |
Registers a path specification credentials.
Args:
credentials (Credentials): credentials.
Raises:
KeyError: if credentials object is already set for the corresponding
type indicator. | def RegisterCredentials(cls, credentials):
if credentials.type_indicator in cls._credentials:
raise KeyError(
'Credentials object already set for type indicator: {0:s}.'.format(
credentials.type_indicator))
cls._credentials[credentials.type_indicator] = credentials | 391,763 |
Initializes a gzip member decompressor wrapper.
Args:
stream_start (int): offset to the compressed stream within the containing
file object. | def __init__(self, stream_start):
self._decompressor = zlib_decompressor.DeflateDecompressor()
self.last_read = stream_start
self.uncompressed_offset = 0
self._compressed_data = b'' | 391,764 |
Reads the next uncompressed data from the gzip stream.
Args:
file_object (FileIO): file object that contains the compressed stream.
Returns:
bytes: next uncompressed data from the compressed stream. | def Read(self, file_object):
file_object.seek(self.last_read, os.SEEK_SET)
read_data = file_object.read(self._MAXIMUM_READ_SIZE)
self.last_read = file_object.get_offset()
compressed_data = b''.join([self._compressed_data, read_data])
decompressed, extra_compressed = self._decompressor.Decompres... | 391,765 |
Initializes a gzip member.
Args:
file_object (FileIO): file-like object, containing the gzip member.
member_start_offset (int): offset to the beginning of the gzip member
in the containing file.
uncompressed_data_offset (int): current offset into the uncompressed data
in the c... | def __init__(
self, file_object, member_start_offset, uncompressed_data_offset):
self.comment = None
self.modification_time = None
self.operating_system = None
self.original_filename = None
# Offset into this member's uncompressed data of the first item in
# the cache.
self._cach... | 391,766 |
Reads a member header.
Args:
file_object (FileIO): file-like object to read from.
Raises:
FileFormatError: if the member header cannot be read. | def _ReadMemberHeader(self, file_object):
file_offset = file_object.get_offset()
member_header = self._ReadStructure(
file_object, file_offset, self._MEMBER_HEADER_SIZE,
self._MEMBER_HEADER, 'member header')
if member_header.signature != self._GZIP_SIGNATURE:
raise errors.FileFor... | 391,767 |
Reads a member footer.
Args:
file_object (FileIO): file-like object to read from.
Raises:
FileFormatError: if the member footer cannot be read. | def _ReadMemberFooter(self, file_object):
file_offset = file_object.get_offset()
member_footer = self._ReadStructure(
file_object, file_offset, self._MEMBER_FOOTER_SIZE,
self._MEMBER_FOOTER, 'member footer')
self.uncompressed_data_size = member_footer.uncompressed_data_size | 391,768 |
Reads and decompresses the data in the member.
This function already loads as much data as possible in the cache, up to
UNCOMPRESSED_DATA_CACHE_SIZE bytes.
Args:
file_object (FileIO): file-like object.
minimum_offset (int): offset into this member's uncompressed data at
which the cac... | def _LoadDataIntoCache(
self, file_object, minimum_offset, read_all_data=False):
# Decompression can only be performed from beginning to end of the stream.
# So, if data before the current position of the decompressor in the stream
# is required, it's necessary to throw away the current decompres... | 391,772 |
Initializes a file entry lister.
Args:
mediator (VolumeScannerMediator): a volume scanner mediator. | def __init__(self, mediator=None):
super(FileEntryLister, self).__init__(mediator=mediator)
self._list_only_files = False | 391,773 |
Lists a file entry.
Args:
file_system (dfvfs.FileSystem): file system that contains the file entry.
file_entry (dfvfs.FileEntry): file entry to list.
parent_full_path (str): full path of the parent file entry.
output_writer (StdoutWriter): output writer. | def _ListFileEntry(
self, file_system, file_entry, parent_full_path, output_writer):
# Since every file system implementation can have their own path
# segment separator we are using JoinPath to be platform and file system
# type independent.
full_path = file_system.JoinPath([parent_full_path... | 391,774 |
Lists file entries in the base path specification.
Args:
base_path_specs (list[dfvfs.PathSpec]): source path specification.
output_writer (StdoutWriter): output writer. | def ListFileEntries(self, base_path_specs, output_writer):
for base_path_spec in base_path_specs:
file_system = resolver.Resolver.OpenFileSystem(base_path_spec)
file_entry = resolver.Resolver.OpenFileEntry(base_path_spec)
if file_entry is None:
logging.warning(
'Unable to ... | 391,775 |
Writes the file path to file.
Args:
path (str): path of the file. | def WriteFileEntry(self, path):
string = '{0:s}\n'.format(path)
encoded_string = self._EncodeString(string)
self._file_object.write(encoded_string) | 391,776 |
Initializes a file system.
Args:
resolver_context (Context): a resolver context. | def __init__(self, resolver_context):
super(FakeFileSystem, self).__init__(resolver_context)
self._paths = {}
self.AddFileEntry(
self.LOCATION_ROOT,
file_entry_type=definitions.FILE_ENTRY_TYPE_DIRECTORY) | 391,777 |
Retrieves the data associated to a path.
Args:
path (str): path of the file entry.
Returns:
bytes: data or None if not available. | def GetDataByPath(self, path):
_, path_data = self._paths.get(path, (None, None))
return path_data | 391,779 |
Retrieves a file entry for a path.
Args:
path (str): path of the file entry.
Returns:
FakeFileEntry: a file entry or None if not available. | def GetFileEntryByPath(self, path):
if path is None:
return None
file_entry_type, _ = self._paths.get(path, (None, None))
if not file_entry_type:
return None
path_spec = fake_path_spec.FakePathSpec(location=path)
return fake_file_entry.FakeFileEntry(
self._resolver_context... | 391,780 |
Initializes a file system.
Args:
resolver_context (Context): resolver context.
Raises:
ValueError: if a derived file system class does not define a type
indicator. | def __init__(self, resolver_context):
super(FileSystem, self).__init__()
self._is_cached = False
self._is_open = False
self._path_spec = None
self._resolver_context = resolver_context
if not getattr(self, 'TYPE_INDICATOR', None):
raise ValueError('Missing type indicator.') | 391,782 |
Determines the basename of the path.
Args:
path (str): path.
Returns:
str: basename of the path. | def BasenamePath(self, path):
if path.endswith(self.PATH_SEPARATOR):
path = path[:-1]
_, _, basename = path.rpartition(self.PATH_SEPARATOR)
return basename | 391,783 |
Determines the directory name of the path.
The file system root is represented by an empty string.
Args:
path (str): path.
Returns:
str: directory name of the path or None. | def DirnamePath(self, path):
if path.endswith(self.PATH_SEPARATOR):
path = path[:-1]
if not path:
return None
dirname, _, _ = path.rpartition(self.PATH_SEPARATOR)
return dirname | 391,785 |
Retrieves a data stream for a path specification.
Args:
path_spec (PathSpec): a path specification.
Returns:
DataStream: a data stream or None if not available. | def GetDataStreamByPathSpec(self, path_spec):
file_entry = self.GetFileEntryByPathSpec(path_spec)
if not file_entry:
return None
data_stream_name = getattr(path_spec, 'data_stream', None)
return file_entry.GetDataStream(data_stream_name) | 391,786 |
Retrieves a file-like object for a path specification.
Args:
path_spec (PathSpec): a path specification.
Returns:
FileIO: a file-like object or None if not available. | def GetFileObjectByPathSpec(self, path_spec):
file_entry = self.GetFileEntryByPathSpec(path_spec)
if not file_entry:
return None
return file_entry.GetFileObject() | 391,787 |
Determines the path segment and suffix of the path.
None is returned if the path does not start with the base path and
an empty string if the path exactly matches the base path.
Args:
base_path (str): base path.
path (str): path.
Returns:
tuple[str, str]: path segment and suffix str... | def GetPathSegmentAndSuffix(self, base_path, path):
if path is None or base_path is None or not path.startswith(base_path):
return None, None
path_index = len(base_path)
if base_path and not base_path.endswith(self.PATH_SEPARATOR):
path_index += 1
if path_index == len(path):
ret... | 391,788 |
Joins the path segments into a path.
Args:
path_segments (list[str]): path segments.
Returns:
str: joined path segments prefixed with the path separator. | def JoinPath(self, path_segments):
# This is an optimized way to combine the path segments into a single path
# and combine multiple successive path separators to one.
# Split all the path segments based on the path (segment) separator.
path_segments = [
segment.split(self.PATH_SEPARATOR) ... | 391,789 |
Retrieves the volume index from the path specification.
Args:
path_spec (PathSpec): path specification.
Returns:
int: volume index or None if not available. | def LVMPathSpecGetVolumeIndex(path_spec):
volume_index = getattr(path_spec, 'volume_index', None)
if volume_index is None:
location = getattr(path_spec, 'location', None)
if location is None or not location.startswith('/lvm'):
return None
volume_index = None
try:
volume_index = int... | 391,799 |
Retrieves the path specification resolver helper for the specified type.
Args:
type_indicator (str): type indicator.
Returns:
ResolverHelper: a resolver helper. | def _GetResolverHelper(cls, type_indicator):
if not cls._resolver_helpers_manager:
# Delay the import of the resolver helpers manager to prevent circular
# imports.
from dfvfs.resolver_helpers import manager
cls._resolver_helpers_manager = manager.ResolverHelperManager
return cls.... | 391,800 |
Opens a file entry 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:
FileEntry: file entry or None... | def OpenFileEntry(cls, path_spec_object, resolver_context=None):
file_system = cls.OpenFileSystem(
path_spec_object, resolver_context=resolver_context)
if resolver_context is None:
resolver_context = cls._resolver_context
file_entry = file_system.GetFileEntryByPathSpec(path_spec_object)... | 391,801 |
Decode the encoded data.
Args:
encoded_data (byte): encoded data.
Returns:
tuple(bytes, bytes): decoded data and remaining encoded data.
Raises:
BackEndError: if the base32 stream cannot be decoded. | def Decode(self, encoded_data):
try:
decoded_data = base64.b32decode(encoded_data, casefold=False)
except (TypeError, binascii.Error) as exception:
raise errors.BackEndError(
'Unable to decode base32 stream with error: {0!s}.'.format(
exception))
return decoded_data... | 391,804 |
Opens the BDE volume using the path specification.
Args:
bde_volume (pybde.volume): BDE volume.
path_spec (PathSpec): path specification.
file_object (FileIO): file-like object.
key_chain (KeyChain): key chain. | def BDEVolumeOpen(bde_volume, path_spec, file_object, key_chain):
password = key_chain.GetCredential(path_spec, 'password')
if password:
bde_volume.set_password(password)
recovery_password = key_chain.GetCredential(path_spec, 'recovery_password')
if recovery_password:
bde_volume.set_recovery_passwor... | 391,805 |
Retrieves the decompressor object for a specific compression method.
Args:
compression_method (str): compression method identifier.
Returns:
Decompressor: decompressor or None if the compression method does
not exists. | def GetDecompressor(cls, compression_method):
compression_method = compression_method.lower()
decompressor = cls._decompressors.get(compression_method, None)
if not decompressor:
return None
return decompressor() | 391,806 |
Registers a decompressor for a specific compression method.
Args:
decompressor (type): decompressor class.
Raises:
KeyError: if the corresponding decompressor is already set. | def RegisterDecompressor(cls, decompressor):
compression_method = decompressor.COMPRESSION_METHOD.lower()
if compression_method in cls._decompressors:
raise KeyError(
'Decompressor for compression method: {0:s} already set.'.format(
decompressor.COMPRESSION_METHOD))
cls._... | 391,807 |
Initializes a file-like object.
Args:
resolver_context (Context): resolver context. | def __init__(self, resolver_context):
super(FileIO, self).__init__()
self._is_cached = False
self._is_open = False
self._resolver_context = resolver_context | 391,808 |
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.
encryption_method (Optional[str]): method used to the encrypt the data.
file_object (Optional[FileIO]): parent file-li... | def __init__(
self, resolver_context, encryption_method=None, file_object=None):
if file_object is not None and encryption_method is None:
raise ValueError(
'File-like object provided without corresponding encryption method.')
super(EncryptedStream, self).__init__(resolver_context)
... | 391,811 |
Opens the file-like object.
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.
OSError: if the file-like object cou... | def _Open(self, path_spec=None, mode='rb'):
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 specificatio... | 391,815 |
Aligns the encrypted file with the decrypted data offset.
Args:
decrypted_data_offset (int): decrypted data offset. | def _AlignDecryptedDataOffset(self, decrypted_data_offset):
self._file_object.seek(0, os.SEEK_SET)
self._decrypter = self._GetDecrypter()
self._decrypted_data = b''
encrypted_data_offset = 0
encrypted_data_size = self._file_object.get_size()
while encrypted_data_offset < encrypted_data_s... | 391,816 |
Reads encrypted data from the file-like object.
Args:
read_size (int): number of bytes of encrypted data to read.
Returns:
int: number of bytes of encrypted data read. | def _ReadEncryptedData(self, read_size):
encrypted_data = self._file_object.read(read_size)
read_count = len(encrypted_data)
self._encrypted_data = b''.join([self._encrypted_data, encrypted_data])
self._decrypted_data, self._encrypted_data = (
self._decrypter.Decrypt(self._encrypted_data... | 391,817 |
Sets the decrypted stream size.
This function is used to set the decrypted stream size if it can be
determined separately.
Args:
decrypted_stream_size (int): size of the decrypted stream in bytes.
Raises:
IOError: if the file-like object is already open.
OSError: if the file-like ob... | def SetDecryptedStreamSize(self, decrypted_stream_size):
if self._is_open:
raise IOError('Already open.')
if decrypted_stream_size < 0:
raise ValueError((
'Invalid decrypted stream size: {0:d} value out of '
'bounds.').format(decrypted_stream_size))
self._decrypted_str... | 391,818 |
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._decrypted_stream_size is None:
self._decryp... | 391,819 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.