:py:mod:`dissect.target.plugins.os.unix.linux.debian.apt` ========================================================= .. py:module:: dissect.target.plugins.os.unix.linux.debian.apt Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: dissect.target.plugins.os.unix.linux.debian.apt.AptPlugin Functions ~~~~~~~~~ .. autoapisummary:: :nosignatures: dissect.target.plugins.os.unix.linux.debian.apt.split_into_records dissect.target.plugins.os.unix.linux.debian.apt.split_package_names Attributes ~~~~~~~~~~ .. autoapisummary:: dissect.target.plugins.os.unix.linux.debian.apt.APT_LOG_OPERATIONS dissect.target.plugins.os.unix.linux.debian.apt.REGEX_PACKAGE_NAMES .. py:data:: APT_LOG_OPERATIONS :value: ['Install', 'Reinstall', 'Upgrade', 'Downgrade', 'Remove', 'Purge'] .. py:data:: REGEX_PACKAGE_NAMES .. py:class:: AptPlugin(target: dissect.target.Target) Bases: :py:obj:`dissect.target.plugin.Plugin` Base class for plugins. Plugins can optionally be namespaced by specifying the ``__namespace__`` class attribute. Namespacing results in your plugin needing to be prefixed with this namespace when being called. For example, if your plugin has specified ``test`` as namespace and a function called ``example``, you must call your plugin with ``test.example``:: A ``Plugin`` class has the following private class attributes: - ``__namespace__`` - ``__record_descriptors__`` With the following three being assigned in :func:`register`: - ``__plugin__`` - ``__functions__`` - ``__exports__`` Additionally, the methods and attributes of :class:`Plugin` receive more private attributes by using decorators. The :func:`export` decorator adds the following private attributes - ``__exported__`` - ``__output__``: Set with the :func:`export` decorator. - ``__record__``: Set with the :func:`export` decorator. The :func:`internal` decorator and :class:`InternalPlugin` set the ``__internal__`` attribute. Finally. :func:`args` decorator sets the ``__args__`` attribute. :param target: The :class:`~dissect.target.target.Target` object to load the plugin for. .. py:attribute:: __namespace__ :value: 'apt' .. py:attribute:: LOG_DIR_PATH :value: '/var/log/apt' .. py:attribute:: LOG_FILES_GLOB :value: 'history.*' .. py:method:: check_compatible() -> None Perform a compatibility check with the target. This function should return ``None`` if the plugin is compatible with the current target (``self.target``). For example, check if a certain file exists. Otherwise it should raise an ``UnsupportedPluginError``. :raises UnsupportedPluginError: If the plugin could not be loaded. .. py:method:: logs() -> Iterator[dissect.target.plugins.os.unix.packagemanager.PackageManagerLogRecord] Package manager log parser for Apt. Apt creates logs that are multiline and therefore requires somewhat complex parsing logic. We create one ``PackageManagerLogRecord`` per package and type; the example below hence generates *three* records. Example log format:: Start-Date: 2022-09-21 06:48:56 Commandline: /usr/bin/unattended-upgrade Install: linux-headers-5.4.0-126:amd64 (5.4.0-126.142, automatic), Upgrade: linux-headers-generic:amd64 (5.4.0.125.126, 5.4.0.126.127), libpython3.9-minimal:amd64 (3.9.5-3ubuntu0~20.04.1, automatic) Requested-By: user (1000) End-Date: 2022-09-21 06:48:57 .. py:function:: split_into_records(chunk: Iterator[str], tz: zoneinfo.ZoneInfo, target: dissect.target.Target) -> Iterator[dissect.target.plugins.os.unix.packagemanager.PackageManagerLogRecord] Parse the chunk line for line and try to extract as much information from each line as possible. .. py:function:: split_package_names(package_names: str) -> list[str] Splits a comma separated list of package names. Example ``package_names``:: linux-headers-5.4.0-126:amd64 (5.4.0-126.142, automatic), linux-headers-5.4.0-126-generic:amd64 (5.4.0-126.142, automatic), linux-modules-extra-5.4.0-126-generic:amd64 (5.4.0-126.142, automatic), linux-modules-5.4.0-126-generic:amd64 (5.4.0-126.142, automatic), linux-image-5.4.0-126-generic:amd64 (5.4.0-126.142, automatic) :returns: A list of package names, e.g. ``['linux-headers-5.4.0-126:amd64 (5.4.0-126.142, automatic)', ...]``