diff --git a/volatility/framework/interfaces/configuration.py b/volatility/framework/interfaces/configuration.py index 0b5ec54a1..1a0898995 100644 --- a/volatility/framework/interfaces/configuration.py +++ b/volatility/framework/interfaces/configuration.py @@ -585,12 +585,7 @@ class SymbolRequirement(ConstructableRequirementInterface): def construct(self, context, config_path): """Constructs the symbol space within the context based on the subrequirements""" # Determine the space name - name = self.name - if name in context.symbol_space: - index = 2 - while name in context.symbol_space: - name = self.name + str(index) - index += 1 + name = context.symbol_space.free_table_name(self.name) config_path = path_join(config_path, self.name) args = {"context": context, diff --git a/volatility/framework/interfaces/symbols.py b/volatility/framework/interfaces/symbols.py index 4645ae94c..b0c0d963c 100644 --- a/volatility/framework/interfaces/symbols.py +++ b/volatility/framework/interfaces/symbols.py @@ -51,6 +51,9 @@ class Symbol(validity.ValidityRoutines): class SymbolSpaceInterface(collections.abc.Mapping): """An interface for the container that holds all the symbol-containing tables for use within a context""" + def free_table_name(self, prefix = "layer"): + """Returns an unused table name to ensure no collision occurs when inserting a symbol table""" + @abstractmethod def get_symbols_by_type(self, type_name): """Returns all symbols based on the type of the symbol""" diff --git a/volatility/framework/symbols/__init__.py b/volatility/framework/symbols/__init__.py index 4a988e725..249ab182c 100644 --- a/volatility/framework/symbols/__init__.py +++ b/volatility/framework/symbols/__init__.py @@ -3,7 +3,7 @@ import collections.abc import enum import logging -from volatility.framework import constants, exceptions, interfaces, objects +from volatility.framework import constants, exceptions, interfaces, objects, validity from volatility.framework.symbols import native, windows, linux vollog = logging.getLogger(__name__) @@ -15,7 +15,7 @@ class SymbolType(enum.Enum): ENUM = 3 -class SymbolSpace(interfaces.symbols.SymbolSpaceInterface): +class SymbolSpace(interfaces.symbols.SymbolSpaceInterface, validity.ValidityRoutines): """Handles an ordered collection of SymbolTables This collection is ordered so that resolution of symbols can @@ -23,10 +23,20 @@ class SymbolSpace(interfaces.symbols.SymbolSpaceInterface): """ def __init__(self): + super().__init__() self._dict = collections.OrderedDict() # Permanently cache all resolved symbols self._resolved = {} + def free_table_name(self, prefix = "layer"): + """Returns an unused table name to ensure no collision occurs when inserting a symbol table""" + self._check_type(prefix, str) + + count = 1 + while prefix + str(count) in self: + count += 1 + return prefix + str(count) + ### Symbol functions def get_symbols_by_type(self, type_name):