From 4cde0da8a91d93be3261c60044a860a7fd4465ff Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sat, 10 Aug 2019 00:25:21 +0100 Subject: [PATCH] Support passing through functions from specific to generic template. --- volatility/framework/interfaces/objects.py | 1 + volatility/framework/objects/__init__.py | 1 + volatility/framework/objects/templates.py | 9 ++++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/volatility/framework/interfaces/objects.py b/volatility/framework/interfaces/objects.py index 5aa290ad3..a34dc9720 100644 --- a/volatility/framework/interfaces/objects.py +++ b/volatility/framework/interfaces/objects.py @@ -174,6 +174,7 @@ class ObjectInterface(metaclass = ABCMeta): Each method also takes a template since the templates may contain the necessary data about the yet-to-be-constructed object. It allows objects to control how their templates respond without needing to write new templates for each and every potental object type.""" + _methods = [] @classmethod @abc.abstractmethod diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index 12e445ca6..bc22f08d7 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -451,6 +451,7 @@ class Enumeration(interfaces.objects.ObjectInterface, int): raise NotImplementedError("Writing to Enumerations is not yet implemented") class VolTemplateProxy(interfaces.objects.ObjectInterface.VolTemplateProxy): + _methods = ['lookup'] @classmethod def lookup(cls, template: interfaces.objects.Template, value: int) -> str: diff --git a/volatility/framework/objects/templates.py b/volatility/framework/objects/templates.py index 05cac5e4d..6dc68ef2d 100644 --- a/volatility/framework/objects/templates.py +++ b/volatility/framework/objects/templates.py @@ -17,6 +17,7 @@ # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the # specific language governing rights and limitations under the License. # +import functools import logging from typing import Any, ClassVar, Dict, List, Type @@ -40,11 +41,9 @@ class ObjectTemplate(interfaces.objects.Template): super().__init__(type_name = type_name, **arguments) self._arguments['object_class'] = object_class - # proxy_cls = self.vol.object_class.VolTemplateProxy - # for method_name in dir(proxy_cls): - # if (method_name not in dir(interfaces.objects.ObjectInterface.VolTemplateProxy) - # and callable(getattr(proxy_cls, method_name)) and not method_name.startswith('_')): - # setattr(self, method_name, functools.partial(getattr(proxy_cls, method_name), self)) + proxy_cls = self.vol.object_class.VolTemplateProxy + for method_name in proxy_cls._methods: + setattr(self, method_name, functools.partial(getattr(proxy_cls, method_name), self)) @property def size(self) -> int: