From 634e7d52b56f085bc73b767393876e226a7f4ac5 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sun, 24 Mar 2024 15:09:34 +0000 Subject: [PATCH] Enforce proper requirements on Module objects. --- volatility3/framework/contexts/__init__.py | 15 +++++++++++++++ volatility3/framework/interfaces/context.py | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/volatility3/framework/contexts/__init__.py b/volatility3/framework/contexts/__init__.py index 73868a58f..d1a5c871a 100644 --- a/volatility3/framework/contexts/__init__.py +++ b/volatility3/framework/contexts/__init__.py @@ -14,6 +14,7 @@ import logging from typing import Callable, Iterable, List, Optional, Set, Tuple, Union from volatility3.framework import constants, interfaces, symbols, exceptions +from volatility3.framework.configuration import requirements from volatility3.framework.objects import templates vollog = logging.getLogger(__name__) @@ -226,6 +227,20 @@ class Module(interfaces.context.ModuleInterface): # Add the module to the context modules collection return return_val + @classmethod + def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: + """Returns a list of Requirement objects for this type of layer.""" + return [ + requirements.IntRequirement(name="offset", optional=False), + requirements.TranslationLayerRequirement(name="layer_name", optional=False), + requirements.TranslationLayerRequirement( + name="native_layer_name", optional=True + ), + requirements.SymbolTableRequirement( + name="symbol_table_name", optional=False + ), + ] + def object( self, object_type: str, diff --git a/volatility3/framework/interfaces/context.py b/volatility3/framework/interfaces/context.py index a95f2b464..3847ffb59 100644 --- a/volatility3/framework/interfaces/context.py +++ b/volatility3/framework/interfaces/context.py @@ -157,6 +157,10 @@ class ModuleInterface(interfaces.configuration.ConfigurableInterface): super().__init__(context, config_path) self._module_name = name + @classmethod + def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: + """Returns a list of Requirement objects for this type of layer.""" + @property def _layer_name(self) -> str: return self.config["layer_name"] @@ -175,7 +179,6 @@ class ModuleInterface(interfaces.configuration.ConfigurableInterface): def build_configuration(self) -> "interfaces.configuration.HierarchicalDict": """Builds the configuration dictionary for this specific Module""" - config = super().build_configuration() config["offset"] = self.config["offset"]