88import collections .abc
99import contextlib
1010import logging
11- from typing import Any , Dict , List , Mapping , Optional
11+ from typing import Any , Dict , List , Mapping , NamedTuple , Optional
1212
1313from 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
9782class 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 )
0 commit comments