From be075939d216ea8a5cd0335af32f9f3839891d7e Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Sun, 18 Dec 2016 19:38:05 +0000 Subject: [PATCH] Remove flags as a fully-fledged object until it's been discussed --- volatility/framework/objects/__init__.py | 24 ---------------------- volatility/framework/symbols/wrappers.py | 26 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 volatility/framework/symbols/wrappers.py diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index 00e684f1d..d553879e6 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -296,30 +296,6 @@ class Enumeration(interfaces.objects.ObjectInterface, int): return template._vol['base_type'].size -class Flags(Integer): - """Object that converts an integer into a set of flags based on their masks""" - - def __init__(self, context, type_name, object_info, struct_format, choices = None): - super().__init__(context, type_name, object_info, struct_format) - self._check_type(choices, collections.Mapping) - for k, v in choices.items(): - self._check_type(k, str) - self._check_type(v, int) - self._vol['choices'] = choices - - @property - def choices(self): - return self._vol['choices'] - - @property - def flags(self): - result = [] - for k, v in self.choices.items(): - if self & v: - result.append(k) - return result - - class Array(interfaces.objects.ObjectInterface, collections.Sequence): """Object which can contain a fixed number of an object type""" diff --git a/volatility/framework/symbols/wrappers.py b/volatility/framework/symbols/wrappers.py new file mode 100644 index 000000000..94c6f2640 --- /dev/null +++ b/volatility/framework/symbols/wrappers.py @@ -0,0 +1,26 @@ +import collections + +from volatility.framework import interfaces, validity + + +class Flags(validity.ValidityRoutines): + """Object that converts an integer into a set of flags based on their masks""" + + def __init__(self, choices = None): + self._check_type(choices, collections.Mapping) + for k, v in choices.items(): + self._check_type(k, str) + self._check_type(v, int) + self._choices = interfaces.objects.ReadOnlyMapping(choices) + + @property + def choices(self): + return self._choices + + def __call__(self, value): + """Return the appropriate Flags """ + result = [] + for k, v in self.choices.items(): + if value & v: + result.append(k) + return result