From bca972f28ab0142270ae33b2335bf8b2eb42bba4 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Mon, 30 Jul 2018 23:58:02 +0100 Subject: [PATCH] Remove the python implementation of __getattribute__ for speed. The __getattribute__ method is called for *all* attribute lookups, and the python implementation is likely slow. The only function the python implementation provided was to check that properties started with helper_. Since this only provided a log message, we could add it back in only if the log level is high enough? Either way, it's not significant enough to warrant costing extra time in every attribute lookup on every object. --- volatility/framework/objects/__init__.py | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/volatility/framework/objects/__init__.py b/volatility/framework/objects/__init__.py index 7ea25eed4..a6c7664f3 100644 --- a/volatility/framework/objects/__init__.py +++ b/volatility/framework/objects/__init__.py @@ -599,27 +599,10 @@ class Struct(interfaces.objects.ObjectInterface): """Specifically named method for retrieving members.""" return self.__getattr__(attr) - def __getattribute__(self, attr: str) -> typing.Any: - """Make sure that class overrides all start with helper_""" - if attr in ['__dict__', '__class__'] or attr in self.__dict__: - return object.__getattribute__(self, attr) - - if not isinstance(getattr(self.__class__, attr), property): - return object.__getattribute__(self, attr) - elif not hasattr(Struct, attr) and not attr.startswith('helper_'): - # Is a property, of an override class that doesn't start with helper - vollog.debug("Deprecated non-helper attribute {} requested from class override {}".format(attr, - self.vol.type_name)) - # Uncomment the following line if we want to prohibit using non-helper properties - # return self.__getattr__(attr) - - # Change this to an attribute error if we want to prohibit rather than deprecate member collisisons - return object.__getattribute__(self, attr) - def __getattr__(self, attr: str) -> typing.Any: """Method for accessing members of the type""" - if attr in self.__getattribute__("_concrete_members"): - return self.__getattribute__("_concrete_members")[attr] + if attr in self._concrete_members: + return self._concrete_members[attr] elif attr in self.vol.members: mask = self._context.memory[self.vol.layer_name].address_mask relative_offset, member = self.vol.members[attr]