Skip to content

Commit

Permalink
Moved VFS attribute out of file entry log2timeline#504 (log2timeline#584
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joachimmetz authored Jul 18, 2021
1 parent 5e3c089 commit ddeabfe
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 388 deletions.
11 changes: 11 additions & 0 deletions dfvfs/vfs/attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""The Virtual File System (VFS) attribute interface."""


class Attribute(object):
"""Attribute interface."""

@property
def type_indicator(self):
"""str: type indicator or None if not known."""
return getattr(self, 'TYPE_INDICATOR', None)
2 changes: 1 addition & 1 deletion dfvfs/vfs/encoded_stream_file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class EncodedStreamFileEntry(root_only_file_entry.RootOnlyFileEntry):
"""Class that implements an encoded stream file entry object."""
"""Class that implements an encoded stream file entry."""

TYPE_INDICATOR = definitions.TYPE_INDICATOR_ENCODED_STREAM

Expand Down
15 changes: 3 additions & 12 deletions dfvfs/vfs/file_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@
from dfvfs.vfs import vfs_stat


class Attribute(object):
"""VFS attribute interface."""

@property
def type_indicator(self):
"""str: type indicator or None if not known."""
return getattr(self, 'TYPE_INDICATOR', None)


class DataStream(object):
"""VFS data stream interface."""
"""Data stream interface."""

# The data stream object should not have a reference to its
# file entry since that will create a cyclic reference.
Expand All @@ -42,7 +33,7 @@ def IsDefault(self):


class Directory(object):
"""VFS directory interface.
"""Directory interface.
Attributes:
path_spec (PathSpec): path specification of the directory.
Expand Down Expand Up @@ -78,7 +69,7 @@ def entries(self):


class FileEntry(object):
"""Virtual file entry interface.
"""File entry interface.
Attributes:
entry_type (str): file entry type, such as device, directory, file, link,
Expand Down
2 changes: 1 addition & 1 deletion dfvfs/vfs/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class FileSystem(object):
"""Virtual file system interface."""
"""File system interface."""

# Note that redundant-returns-doc is broken for pylint 1.7.x for abstract
# methods
Expand Down
153 changes: 153 additions & 0 deletions dfvfs/vfs/ntfs_attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# -*- coding: utf-8 -*-
"""The NTFS attribute implementation."""

import pyfwnt

from dfdatetime import filetime as dfdatetime_filetime

from dfvfs.lib import definitions
from dfvfs.lib import errors
from dfvfs.vfs import attribute


class NTFSAttribute(attribute.Attribute):
"""File system attribute that uses pyfsntfs."""

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

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

@property
def attribute_type(self):
"""The attribute type."""
return self._fsntfs_attribute.attribute_type


class FileNameNTFSAttribute(NTFSAttribute):
"""NTFS $FILE_NAME file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_FILE_NAME

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

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

@property
def entry_modification_time(self):
"""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)

@property
def file_attribute_flags(self):
"""int: file attribute flags or None if not available."""
return self._fsntfs_attribute.file_attribute_flags

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

@property
def name(self):
"""str: name."""
return self._fsntfs_attribute.name

@property
def parent_file_reference(self):
"""int: parent file reference."""
return self._fsntfs_attribute.parent_file_reference


class ObjectIdentifierNTFSAttribute(NTFSAttribute):
"""NTFS $OBJECT_ID file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_OBJECT_ID

@property
def droid_file_identifier(self):
"""str: droid file identifier, formatted as an UUID."""
return self._fsntfs_attribute.droid_file_identifier


class SecurityDescriptorNTFSAttribute(NTFSAttribute):
"""NTFS $SECURITY_DESCRIPTOR file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_SECURITY_DESCRIPTOR

@property
def security_descriptor(self):
"""pyfwnt.security_descriptor: security descriptor."""
fwnt_security_descriptor = pyfwnt.security_descriptor()
fwnt_security_descriptor.copy_from_byte_stream(self._fsntfs_attribute.data)
return fwnt_security_descriptor


class StandardInformationNTFSAttribute(NTFSAttribute):
"""NTFS $STANDARD_INFORMATION file system attribute."""

TYPE_INDICATOR = definitions.ATTRIBUTE_TYPE_NTFS_STANDARD_INFORMATION

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

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

@property
def entry_modification_time(self):
"""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)

@property
def file_attribute_flags(self):
"""int: file attribute flags or None if not available."""
return self._fsntfs_attribute.file_attribute_flags

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

@property
def owner_identifier(self):
"""int: owner identifier."""
return self._fsntfs_attribute.owner_identifier

@property
def security_descriptor_identifier(self):
"""int: security descriptor identifier."""
return self._fsntfs_attribute.security_descriptor_identifier

@property
def update_sequence_number(self):
"""int: update sequence number."""
return self._fsntfs_attribute.update_sequence_number
Loading

0 comments on commit ddeabfe

Please sign in to comment.