From a27a68de4b202791127a85eeabc49ad54cd2d8e8 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Mon, 9 Feb 2015 22:25:36 +0000 Subject: [PATCH] Add support for finalizing DataLayers once we're done using them. --- volatility/framework/interfaces/layers.py | 8 ++++++++ volatility/framework/layers/__init__.py | 1 + volatility/framework/layers/physical.py | 4 ++++ 3 files changed, 13 insertions(+) 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()