diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index 5d766ea81..8e5b7b582 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -52,6 +52,14 @@ class DataLayerInterface(validity.ValidityRoutines, metaclass = ABCMeta): Note: Writes are not atomic, therefore some data can be written, even if an exception is thrown. """ + def destroy(self): + """Allows DataLayers to close any open handles, etc. + + Systems that make use of Data Layers should called destroy when they are done with them. + This will close all handles, and make the object unreadable + (exceptions will be thrown using a DataLayer after destruction)""" + pass + class TranslationLayerInterface(DataLayerInterface, metaclass = ABCMeta): @abstractmethod diff --git a/volatility/framework/layers/__init__.py b/volatility/framework/layers/__init__.py index b891dfb05..c4384bd5e 100644 --- a/volatility/framework/layers/__init__.py +++ b/volatility/framework/layers/__init__.py @@ -50,6 +50,7 @@ class Memory(validity.ValidityRoutines): if depend_list: raise exceptions.LayerException("Layer " + layer.name + " is depended upon by " + ", ".join(depend_list)) + self._layers[name].destroy() del self._layers[name] def __getitem__(self, name): diff --git a/volatility/framework/layers/physical.py b/volatility/framework/layers/physical.py index 245b66c45..7a84fb351 100644 --- a/volatility/framework/layers/physical.py +++ b/volatility/framework/layers/physical.py @@ -93,3 +93,7 @@ class FileLayer(interfaces.layers.DataLayerInterface): raise exceptions.InvalidAddressException("Data segment outside of the " + self.name + " file boundaries") self._file.seek(offset) self._file.write(data) + + def destroy(self): + """Closes the file handle""" + self._file.close()