Skip to content

Commit 50b5d22

Browse files
committed
Core: Add type parameter to object_from_symbol
1 parent 1ff2d80 commit 50b5d22

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

API_CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ API Changes
44
When an addition to the existing API is made, the minor version is bumped.
55
When an API feature or function is removed or changed, the major version is bumped.
66

7+
2.5.0
8+
=====
9+
Add in support for specifying a type override for object_from_symbol
10+
711
2.4.0
812
=====
913
Add a `get_size()` method to Windows VAD structures and fix several off-by-one issues when calculating VAD sizes.

volatility3/framework/constants/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444

4545
# We use the SemVer 2.0.0 versioning scheme
4646
VERSION_MAJOR = 2 # Number of releases of the library with a breaking change
47-
VERSION_MINOR = 4 # Number of changes that only add to the interface
48-
VERSION_PATCH = 2 # Number of changes that do not change the interface
47+
VERSION_MINOR = 5 # Number of changes that only add to the interface
48+
VERSION_PATCH = 0 # Number of changes that do not change the interface
4949
VERSION_SUFFIX = ""
5050

5151
# TODO: At version 2.0.0, remove the symbol_shift feature

volatility3/framework/contexts/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ def object_from_symbol(
272272
symbol_name: str,
273273
native_layer_name: Optional[str] = None,
274274
absolute: bool = False,
275+
object_type: Optional[Union[str, interfaces.objects.ObjectInterface]] = None,
275276
**kwargs,
276-
) -> "interfaces.objects.ObjectInterface":
277+
) -> interfaces.objects.ObjectInterface:
277278
"""Returns an object based on a specific symbol (containing type and
278279
offset information) and the layer_name of the Module. This will throw
279280
a ValueError if the symbol does not contain an associated type, or if
@@ -284,6 +285,7 @@ def object_from_symbol(
284285
symbol_name: Name of the symbol (within the module) to construct
285286
native_layer_name: Name of the layer in which constructed objects are made (for pointers)
286287
absolute: whether the symbol's address is absolute or relative to the module
288+
object_type: Override for the type from the symobl to use (or if the symbol type is missing)
287289
"""
288290
if constants.BANG not in symbol_name:
289291
symbol_name = self.symbol_table_name + constants.BANG + symbol_name
@@ -299,16 +301,21 @@ def object_from_symbol(
299301
if not absolute:
300302
offset += self._offset
301303

302-
if symbol_val.type is None:
303-
raise TypeError(f"Symbol {symbol_val.name} has no associated type")
304+
if object_type is None:
305+
if symbol_val.type is None:
306+
raise TypeError(
307+
f"Symbol {symbol_val.name} has no associated type and no object_type specified"
308+
)
309+
else:
310+
object_type = symbol_val.type
304311

305312
# Ensure we don't use a layer_name other than the module's, why would anyone do that?
306313
if "layer_name" in kwargs:
307314
del kwargs["layer_name"]
308315

309316
# Since type may be a template, we don't just call our own module method
310317
return self._context.object(
311-
object_type=symbol_val.type,
318+
object_type=object_type,
312319
layer_name=self._layer_name,
313320
offset=offset,
314321
native_layer_name=native_layer_name or self._native_layer_name,

volatility3/framework/interfaces/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def object_from_symbol(
253253
symbol_name: str,
254254
native_layer_name: Optional[str] = None,
255255
absolute: bool = False,
256+
object_type: Optional[Union[str, interfaces.objects.ObjectInterface]] = None,
256257
**kwargs,
257258
) -> "interfaces.objects.ObjectInterface":
258259
"""Returns an object created using the symbol_table_name and layer_name
@@ -262,6 +263,7 @@ def object_from_symbol(
262263
symbol_name: The name of a symbol (that must be present in the module's symbol table). The symbol's associated type will be used to construct an object at the symbol's offset.
263264
native_layer_name: The native layer for objects that reference a different layer (if not the default provided during module construction)
264265
absolute: A boolean specifying whether the offset is absolute within the layer, or relative to the start of the module
266+
object_type: Override for the type from the symobl to use (or if the symbol type is missing)
265267
266268
Returns:
267269
The constructed object

0 commit comments

Comments
 (0)