From 55151f546d0e1ccc65c034075eaaaba324cf4734 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 22 Nov 2024 11:46:04 +0000 Subject: [PATCH] Initial work on adding a LayerData renderer type --- volatility3/framework/interfaces/renderers.py | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/volatility3/framework/interfaces/renderers.py b/volatility3/framework/interfaces/renderers.py index e26164ee7..477d743d1 100644 --- a/volatility3/framework/interfaces/renderers.py +++ b/volatility3/framework/interfaces/renderers.py @@ -9,8 +9,10 @@ renderer interface which can interact with a TreeGrid to produce suitable output. """ +from dataclasses import dataclass import datetime -from abc import abstractmethod, ABCMeta +from volatility3.framework import interfaces +from abc import ABCMeta, abstractmethod from collections import abc from typing import ( Any, @@ -20,9 +22,9 @@ from typing import ( List, NamedTuple, Optional, - TypeVar, - Type, Tuple, + Type, + TypeVar, Union, ) @@ -124,6 +126,13 @@ class Disassembly: self.offset = offset +@dataclass +class LayerData(object): + layer_name: str + offset: int + length: int + + # We don't class these off a shared base, because the BaseTypes must only # contain the types that the validator will accept (which would not include the base) @@ -136,6 +145,7 @@ BaseTypes = Union[ Type[datetime.datetime], Type[BaseAbsentValue], Type[Disassembly], + Type[LayerData], ] ColumnsType = List[Tuple[str, BaseTypes]] VisitorSignature = Callable[[TreeNode, _Type], _Type] @@ -163,7 +173,12 @@ class TreeGrid(metaclass=ABCMeta): Disassembly, ) - def __init__(self, columns: ColumnsType, generator: Generator) -> None: + def __init__( + self, + columns: ColumnsType, + generator: Generator, + context: Optional[interfaces.context.ContextInterface] = None, + ) -> None: """Constructs a TreeGrid object using a specific set of columns. The TreeGrid itself is a root element, that can have children but no values. @@ -174,6 +189,15 @@ class TreeGrid(metaclass=ABCMeta): columns: A list of column tuples made up of (name, type). generator: An iterable containing row for a tree grid, each row contains a indent level followed by the values for each column in order. """ + self._context = context + + @property + def context(self) -> Optional[interfaces.context.ContextInterface]: + """Returns the context value for the tree grid (to retrieve data items) + + This is a property to ensure the renderers don't try changing the context for any reason + """ + return self._context @staticmethod @abstractmethod