Skip to content

Commit 61e7430

Browse files
authored
Merge pull request #1753 from volatilityfoundation/feature/use-less-memory-2
Don't completely remove the chainmap, but change one dict to a namedm…
2 parents e1613d6 + b73e4f0 commit 61e7430

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

volatility3/framework/contexts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def object(
130130
object_info=interfaces.objects.ObjectInformation(
131131
layer_name=layer_name,
132132
offset=offset,
133-
native_layer_name=native_layer_name,
133+
native_layer_name=native_layer_name or layer_name,
134134
size=object_template.size,
135135
),
136136
)

volatility3/framework/interfaces/objects.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import collections.abc
99
import contextlib
1010
import logging
11-
from typing import Any, Dict, List, Mapping, Optional
11+
from typing import Any, Dict, List, Mapping, NamedTuple, Optional
1212

1313
from volatility3.framework import constants, interfaces
1414

@@ -52,7 +52,7 @@ def __eq__(self, other):
5252
return dict(self) == dict(other)
5353

5454

55-
class ObjectInformation(ReadOnlyMapping):
55+
class ObjectInformation(NamedTuple):
5656
"""Contains common information useful/pertinent only to an individual
5757
object (like an instance)
5858
@@ -63,35 +63,20 @@ class ObjectInformation(ReadOnlyMapping):
6363
in a single place. These values are based on the :class:`ReadOnlyMapping` class, to prevent their modification.
6464
"""
6565

66-
def __init__(
67-
self,
68-
layer_name: str,
69-
offset: int,
70-
member_name: Optional[str] = None,
71-
parent: Optional["ObjectInterface"] = None,
72-
native_layer_name: Optional[str] = None,
73-
size: Optional[int] = None,
74-
):
75-
"""Constructs a container for basic information about an object.
66+
layer_name: str
67+
offset: int
68+
native_layer_name: str
69+
member_name: Optional[str] = None
70+
parent: Optional["ObjectInterface"] = None
71+
size: Optional[int] = None
7672

77-
Args:
78-
layer_name: Layer from which the data for the object will be read
79-
offset: Offset within the layer at which the data for the object will be read
80-
member_name: If the object was accessed as a member of a parent object, this was the name used to access it
81-
parent: If the object was accessed as a member of a parent object, this is the parent object
82-
native_layer_name: If this object references other objects (such as a pointer), what layer those objects live in
83-
size: The size that the whole structure consumes in bytes
84-
"""
85-
super().__init__(
86-
{
87-
"layer_name": layer_name,
88-
"offset": offset,
89-
"member_name": member_name,
90-
"parent": parent,
91-
"native_layer_name": native_layer_name or layer_name,
92-
"size": size,
93-
}
94-
)
73+
def __getitem__(self, key):
74+
if key in self._fields:
75+
return getattr(self, key)
76+
raise KeyError(f"NamedTuple does not have a key {key}")
77+
78+
def __contains__(self, key):
79+
return key in self._fields
9580

9681

9782
class ObjectInterface(metaclass=abc.ABCMeta):
@@ -183,7 +168,7 @@ def cast(self, new_type_name: str, **additional) -> "ObjectInterface":
183168
offset=self.vol.offset,
184169
member_name=self.vol.member_name,
185170
parent=self.vol.parent,
186-
native_layer_name=self.vol.native_layer_name,
171+
native_layer_name=self.vol.native_layer_name or self.vol.layer_name,
187172
size=object_template.size,
188173
)
189174
return object_template(context=self._context, object_info=object_info)

volatility3/framework/objects/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ def dereference(
458458
offset=offset,
459459
parent=self,
460460
size=self.vol.subtype.size,
461+
native_layer_name=layer_name,
461462
),
462463
)
463464
return self._cache[layer_name]
@@ -811,7 +812,7 @@ def __getitem__(self, i):
811812
layer_name=self.vol.layer_name,
812813
offset=mask & (self.vol.offset + (self.vol.subtype.size * index)),
813814
parent=self,
814-
native_layer_name=self.vol.native_layer_name,
815+
native_layer_name=self.vol.native_layer_name or self.vol.layer_name,
815816
size=self.vol.subtype.size,
816817
)
817818
result += [self.vol.subtype(context=self._context, object_info=object_info)]
@@ -978,7 +979,7 @@ def __getattr__(self, attr: str) -> Any:
978979
offset=mask & (self.vol.offset + relative_offset),
979980
member_name=attr,
980981
parent=self,
981-
native_layer_name=self.vol.native_layer_name,
982+
native_layer_name=self.vol.native_layer_name or self.vol.layer_name,
982983
size=template.size,
983984
)
984985
member = template(context=self._context, object_info=object_info)

0 commit comments

Comments
 (0)