Add in support for AbsentValues.

This commit is contained in:
Mike Auty
2018-03-08 00:26:25 +00:00
parent 3f37ab760c
commit de9ad62412
3 changed files with 42 additions and 8 deletions
+9 -1
View File
@@ -73,9 +73,17 @@ class TreeNode(collections.Sequence, metaclass = ABCMeta):
"""
class BaseAbsentValue(object):
"""Class that represents values which are not present for some reason"""
_Type = typing.TypeVar("_Type")
ColumnsType = typing.List[typing.Tuple[str, typing.Type]]
SimpleTypes = typing.Union[typing.Type[int], typing.Type[str], typing.Type[float], typing.Type[bytes]]
SimpleTypes = typing.Union[typing.Type[int],
typing.Type[str],
typing.Type[float],
typing.Type[bytes],
typing.Type[BaseAbsentValue]]
VisitorSignature = typing.Callable[[TreeNode, _Type], _Type]
+13 -1
View File
@@ -8,6 +8,18 @@ import typing
from volatility.framework import interfaces
class UnreadableValue(interfaces.renderers.BaseAbsentValue):
"""Class that represents values which are empty because the data cannot be read"""
class UnparsableValue(interfaces.renderers.BaseAbsentValue):
"""Class that represents values which are empty because the data cannot be interpreted correctly"""
class NotApplicableValue(interfaces.renderers.BaseAbsentValue):
"""Class that represents values which are empty because they don't make sense for this node"""
class TreeNode(interfaces.renderers.TreeNode):
"""Class representing a particular node in a tree grid"""
@@ -40,7 +52,7 @@ class TreeNode(interfaces.renderers.TreeNode):
"Values must be a list of objects made up of simple types and number the same as the columns")
for index in range(len(self._treegrid.columns)):
column = self._treegrid.columns[index]
if not isinstance(values[index], column.type):
if not isinstance(values[index], (column.type, interfaces.renderers.BaseAbsentValue)):
raise TypeError(
"Values item with index {} is the wrong type for column {} (got {} but expected {})".format(
index,
+20 -6
View File
@@ -1,6 +1,7 @@
import sys
import typing
from volatility.framework import interfaces
from volatility.framework import interfaces, renderers
from volatility.framework.renderers import format_hints
@@ -24,12 +25,25 @@ def hex_bytes_as_text(value: bytes) -> str:
return output
class Optional(object):
def __init__(self, func: typing.Callable[[typing.Any], str]) -> None:
self._func = func
def __call__(self, x: typing.Any) -> str:
if isinstance(x, interfaces.renderers.BaseAbsentValue):
if isinstance(x, renderers.NotApplicableValue):
return "N/A"
else:
return "-"
return self._func(x)
class QuickTextRenderer(interfaces.renderers.Renderer):
type_renderers = {format_hints.Bin: lambda x: "0b{:b}".format(x),
format_hints.Hex: lambda x: "0x{:x}".format(x),
format_hints.HexBytes: hex_bytes_as_text,
bytes: lambda x: x.decode("utf-8"),
'default': lambda x: "{}".format(x)}
type_renderers = {format_hints.Bin: Optional(lambda x: "0b{:b}".format(x)),
format_hints.Hex: Optional(lambda x: "0x{:x}".format(x)),
format_hints.HexBytes: Optional(hex_bytes_as_text),
bytes: Optional(lambda x: x.decode("utf-8")),
'default': Optional(lambda x: "{}".format(x))}
def __init__(self, options = None) -> None:
super().__init__(options)