dissect.target.target
#
Module Contents#
Classes#
Sortable and serializible string-based enum |
|
An adapter for loggers which makes it easier to specify contextual |
|
The class that represents the target that you are talking to. |
|
Abstract base class for generic types. |
|
Abstract base class for generic types. |
|
Abstract base class for generic types. |
|
Abstract base class for generic types. |
Functions#
Attributes#
- dissect.target.target.log#
- dissect.target.target.FunctionTuple#
- class dissect.target.target.Event#
Bases:
dissect.target.helpers.utils.StrEnum
Sortable and serializible string-based enum
- INCOMPATIBLE_PLUGIN = 'incompatible-plugin'#
- REGISTERED_PLUGIN = 'registered-plugin'#
- FUNC_EXEC = 'function-execution'#
- FUNC_EXEC_ERROR = 'function-execution-error'#
- dissect.target.target.getlogger(target)#
- class dissect.target.target.TargetLogAdapter(logger, extra)#
Bases:
logging.LoggerAdapter
An adapter for loggers which makes it easier to specify contextual information in logging output.
- process(msg, kwargs)#
Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.
Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.
- class dissect.target.target.Target(path: str | pathlib.Path = None)#
The class that represents the target that you are talking to.
Targets are the glue that connects the different
Containers
,Loaders
,Volumes
andFilesystems
together.Loaders
are used to map theContainers
,Volumes
andFilesystems
of the target onto theTarget
object.The plugins of dissect.target get mapped onto the
Target
too. They become available as attributes on aTarget
object. For example,t.hostname
,t.evtx()
. By executing the plugin function with a target, it will perform the function on itself.- Parameters:
path – The path of a target.
- property name: str#
Return a name for this target.
The function is guaranteed to give back some name. The name will be guaranteed to not have slashes, backslashes and spaces. The name won’t be guaranteed to be unique.
- Returns:
The name of a target.
- classmethod set_event_callback(*, event_type: Event | None = None, event_callback: Callable) None #
Sets
event_callbacks
on a Target class.event_callbacks
get used to handle specific events denoted byEvent
. This records events related to the target, such as:a plugin gets registered to the target
a plugin is incompatible with the target
a function succeededs in its execution
a function fails in execution
- send_event(event_type: Event, **kwargs) None #
Notify event callbacks for the given
event_type
.Each event can have multiple callback methods, it calls all the callbacks that fit the corresponding event type.
None
is a catch-all method for event callbacks that always get called.- Parameters:
event_type – The type of event
- apply() None #
Resolve all disks, volumes and filesystems and load an operating system on the current
Target
.
- classmethod open(path: str | pathlib.Path) Target #
Try to find a suitable loader for the given path and load a
Target
from it.- Parameters:
path – Path to load the
Target
from.- Returns:
A Target with a linked
Loader
object.
- classmethod open_raw(path: str | pathlib.Path) Target #
Open a Target with the given path using the
RawLoader
.- Parameters:
path – Path to load the Target from.
- classmethod open_all(paths: list[str | pathlib.Path], include_children: bool = False) Iterator[Target] #
Yield targets from a list of paths.
If the path is a directory, iterate files one directory deep.
- Parameters:
paths – A list of paths to load
Targets
from.- Raises:
TargetError – Raised when not a single
Target
can be loaded.
- open_child(child: str | pathlib.Path) Target #
Open a child target.
- Parameters:
child – The location of a target within the current
Target
.- Returns:
An opened
Target
object of the child target.
- open_children(recursive: bool = False) Iterator[Target] #
Open all the child targets on a
Target
.Will open all discovered child targets if the current
Target
has them, such as VMs on a hypervisor.- Parameters:
recursive – Whether to check the child
Target
for moreTargets
.- Returns:
An interator of
Targets
.
- list_children() Iterator[dissect.target.helpers.record.ChildTargetRecord] #
Lists all child targets that compatible
ChildTargetPlugin
classes can discover.
- add_plugin(plugin_cls: dissect.target.plugin.Plugin | type[dissect.target.plugin.Plugin], check_compatible: bool = True) dissect.target.plugin.Plugin #
Add and register a plugin by class.
- Parameters:
plugin_cls – The plugin to add and register, this can either be a class or instance. When this is a class, it will be instantiated.
check_compatible – A flag that determines if we check whether the plugin is compatible with the
Target
.
- Returns:
The
plugin_cls
instance.- Raises:
UnsupportedPluginError – Raised when plugins were found, but they were incompatible
PluginError – Raised when any other exception occurs while trying to load the plugin.
- get_function(function: str) FunctionTuple #
Attempt to get a given function.
If the function is not already registered, look for plugins that export the function and register them.
- Parameters:
function – Function name to look for.
- Returns:
A tuple of the plugin and the corresponding function.
- Raises:
UnsupportedPluginError – Raised when plugins were found, but they were incompatible
PluginError – Raised when any other exception occurs while trying to load the plugin.
- has_function(function: str) bool #
Return whether this Target supports a given function.
- Parameters:
function – The function name to look for.
- Returns:
True
if the function can be found,False
otherwise.
- __getattr__(attr: str) dissect.target.plugin.Plugin | Any #
Override of the default __getattr__ so plugins and functions can be called from a
Target
object.
- __dir__()#
Override the default __dir__ to provide autocomplete for things like IPython.
- __repr__()#
Return repr(self).
- dissect.target.target.T#
- class dissect.target.target.Collection(target: Target)#
Bases:
Generic
[T
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- add(entry: T) None #
- __getitem__(k: str) T #
- __iter__() Iterator[T] #
- __len__() int #
- __repr__() str #
Return repr(self).
- class dissect.target.target.DiskCollection(target: Target)#
Bases:
Collection
[dissect.target.container.Container
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- apply() None #
- class dissect.target.target.VolumeCollection(target: Target)#
Bases:
Collection
[dissect.target.volume.Volume
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- open(vol: dissect.target.volume.Volume) None #
- apply() None #
- class dissect.target.target.FilesystemCollection(target: Target)#
Bases:
Collection
[dissect.target.filesystem.Filesystem
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default