From f0d7dbdf68b29fb0e7625b790dfc51c4d119dfa8 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 8 Aug 2017 17:45:36 +0100 Subject: [PATCH] Add in translate method for TranslationLayers. --- volatility/framework/interfaces/layers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/volatility/framework/interfaces/layers.py b/volatility/framework/interfaces/layers.py index 3b0c9b6be..87938139f 100644 --- a/volatility/framework/interfaces/layers.py +++ b/volatility/framework/interfaces/layers.py @@ -9,6 +9,7 @@ import multiprocessing from abc import ABCMeta, abstractmethod from volatility.framework import constants, exceptions, validity +from volatility.framework.exceptions import InvalidAddressException from volatility.framework.interfaces import configuration, context vollog = logging.getLogger(__name__) @@ -254,6 +255,19 @@ class TranslationLayerInterface(DataLayerInterface, metaclass = ABCMeta): """Returns a list of layer names that this layer translates onto""" return [] + ### Translation layer convenience function + + def translate(self, offset, ignore_errors = False): + mapping = self.mapping(offset, 0, ignore_errors) + if mapping: + _, mapped_offset, _, layer = list(mapping)[0] + else: + if ignore_errors: + # We should only hit this if we ignored errors, but check anyway + return None, None + raise InvalidAddressException("Cannot translate {} in layer {}".format(offset, self.name)) + return mapped_offset, layer + # ## Read/Write functions for mapped pages def read(self, offset, length, pad = False):