Skip to content

Commit

Permalink
Changes to replace stat with attributes log2timeline#52
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Jun 25, 2017
1 parent 741b7e3 commit 6409faa
Showing 1 changed file with 47 additions and 26 deletions.
73 changes: 47 additions & 26 deletions dfvfs/vfs/ntfs_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@
from dfvfs.path import ntfs_path_spec
from dfvfs.resolver import resolver
from dfvfs.vfs import file_entry
from dfvfs.vfs import vfs_stat


_FILE_REFERENCE_MFT_ENTRY_BITMASK = 0xffffffffffff


class NTFSAttribute(file_entry.Attribute):
"""Class that implements an attribute object using pyfsntfs."""
"""File system attribute that uses pyfsntfs."""

def __init__(self, fsntfs_attribute):
"""Initializes the attribute object.
Args:
fsntfs_attribute (pyfsntfs.attribute): NTFS attribute.
Raises:
BackEndError: if the pyfsntfs attribute is missing.
"""
if not fsntfs_attribute:
raise errors.BackEndError(u'Missing pyfsntfs attribute.')

super(NTFSAttribute, self).__init__()
self._fsntfs_attribute = fsntfs_attribute

Expand All @@ -38,27 +43,30 @@ def attribute_type(self):


class FileNameNTFSAttribute(NTFSAttribute):
"""Class that implements a $FILE_NAME attribute object."""
"""NTFS $FILE_NAME file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_FILE_NAME

@property
def access_time(self):
"""dfdatetime.Filetime: access time."""
"""dfdatetime.Filetime: access time or None if not set."""
timestamp = self._fsntfs_attribute.get_access_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def creation_time(self):
"""dfdatetime.Filetime: creation time."""
"""dfdatetime.Filetime: creation time or None if not set."""
timestamp = self._fsntfs_attribute.get_creation_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def entry_modification_time(self):
"""dfdatetime.Filetime: entry modification time."""
"""dfdatetime.Filetime: entry modification time or None if not set."""
timestamp = self._fsntfs_attribute.get_entry_modification_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def file_attribute_flags(self):
Expand All @@ -69,7 +77,8 @@ def file_attribute_flags(self):
def modification_time(self):
"""dfdatetime.Filetime: modification time."""
timestamp = self._fsntfs_attribute.get_modification_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def name(self):
Expand All @@ -83,7 +92,7 @@ def parent_file_reference(self):


class ObjectIdentifierNTFSAttribute(NTFSAttribute):
"""Class that implements a $OBJECT_ID attribute object."""
"""NTFS $OBJECT_ID file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_OBJECT_ID

Expand All @@ -94,7 +103,7 @@ def droid_file_identifier(self):


class SecurityDescriptorNTFSAttribute(NTFSAttribute):
"""Class that implements a $SECURITY_DESCRIPTOR attribute object."""
"""NTFS $SECURITY_DESCRIPTOR file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_SECURITY_DESCRIPTOR

Expand All @@ -107,27 +116,30 @@ def security_descriptor(self):


class StandardInformationNTFSAttribute(NTFSAttribute):
"""Class that implements a $STANDARD_INFORMATION attribute object."""
"""NTFS $STANDARD_INFORMATION file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_STANDARD_INFORMATION

@property
def access_time(self):
"""dfdatetime.Filetime: access time."""
"""dfdatetime.Filetime: access time or None if not set."""
timestamp = self._fsntfs_attribute.get_access_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def creation_time(self):
"""dfdatetime.Filetime: creation time."""
"""dfdatetime.Filetime: creation time or None if not set."""
timestamp = self._fsntfs_attribute.get_creation_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def entry_modification_time(self):
"""dfdatetime.Filetime: entry modification time."""
"""dfdatetime.Filetime: entry modification time or None if not set."""
timestamp = self._fsntfs_attribute.get_entry_modification_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def file_attribute_flags(self):
Expand All @@ -136,9 +148,10 @@ def file_attribute_flags(self):

@property
def modification_time(self):
"""dfdatetime.Filetime: modification time."""
"""dfdatetime.Filetime: modification time or None if not set."""
timestamp = self._fsntfs_attribute.get_modification_time_as_integer()
return dfdatetime_filetime.Filetime(timestamp=timestamp)
if timestamp:
return dfdatetime_filetime.Filetime(timestamp=timestamp)

@property
def owner_identifier(self):
Expand All @@ -157,7 +170,7 @@ def update_sequence_number(self):


class NTFSDataStream(file_entry.DataStream):
"""Class that implements a data stream object using pyfsntfs."""
"""File system data stream that uses pyfsntfs."""

def __init__(self, fsntfs_data_stream):
"""Initializes the data stream object.
Expand All @@ -177,7 +190,7 @@ def name(self):


class NTFSDirectory(file_entry.Directory):
"""Class that implements a directory object using pyfsntfs."""
"""File system directory that uses pyfsntfs."""

def _EntriesGenerator(self):
"""Retrieves directory entries.
Expand Down Expand Up @@ -224,7 +237,7 @@ def _EntriesGenerator(self):


class NTFSFileEntry(file_entry.FileEntry):
"""Class that implements a file entry object using pyfsntfs."""
"""File system file entry that uses pyfsntfs."""

TYPE_INDICATOR = definitions.TYPE_INDICATOR_NTFS

Expand Down Expand Up @@ -255,6 +268,14 @@ def __init__(
is_virtual=is_virtual)
self._fsntfs_file_entry = fsntfs_file_entry

if fsntfs_file_entry:
if self._IsLink(fsntfs_file_entry.file_attribute_flags):
self._type = definitions.FILE_ENTRY_TYPE_LINK
elif fsntfs_file_entry.has_directory_entries_index():
self._type = definitions.FILE_ENTRY_TYPE_DIRECTORY
else:
self._type = definitions.FILE_ENTRY_TYPE_FILE

def _GetAttributes(self):
"""Retrieves the attributes.
Expand Down Expand Up @@ -358,7 +379,7 @@ def _GetStat(self):
if not fsntfs_file_entry:
raise errors.BackEndError(u'Missing pyfsntfs file entry.')

stat_object = super(ZipFileEntry, self)._GetStat()
stat_object = super(NTFSFileEntry, self)._GetStat()

# File data stat information.
if fsntfs_file_entry.has_default_data_stream():
Expand Down Expand Up @@ -549,7 +570,7 @@ def GetNTFSFileEntry(self):
Raises:
PathSpecError: if the path specification is missing location and
MFT entry.
MFT entry.
"""
if not self._fsntfs_file_entry:
# Opening a file by MFT entry is faster than opening a file by location.
Expand Down

0 comments on commit 6409faa

Please sign in to comment.