mirror of
https://github.com/volatilityfoundation/volatility3.git
synced 2026-09-30 21:44:52 +02:00
Enhance symbol listing and templates, add in gitignore and test rig.
This commit is contained in:
+20
-13
@@ -6,6 +6,7 @@ Created on 17 Feb 2013
|
||||
|
||||
import struct
|
||||
import collections
|
||||
import volatility.framework.templates as templates
|
||||
|
||||
class ObjectInterface(object):
|
||||
""" A base object required to be the ancestor of every object used in volatility """
|
||||
@@ -30,23 +31,25 @@ class PrimitiveObject(ObjectInterface):
|
||||
class Integer(PrimitiveObject, int):
|
||||
"""Primitive Object that handles standard numeric types"""
|
||||
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, size, struct_format, **kwargs):
|
||||
struct_format = context.get_primitive_struct_type("int", symbol_name)
|
||||
return cls._struct_value(struct_format, context, layer_name, offset, symbol_name)
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, struct_format, **kwargs):
|
||||
struct_format, struct_size = context.get_primitive_struct_type("int", symbol_name)
|
||||
struct_size = struct.calcsize(struct_format)
|
||||
return cls._struct_value(struct_format, context, layer_name, offset, symbol_name, size = struct_size)
|
||||
|
||||
class Float(PrimitiveObject, float):
|
||||
"""Primitive Object that handles double or floating point numbers"""
|
||||
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, **kwargs):
|
||||
struct_format = context.get_primitive_struct_type("float", symbol_name)
|
||||
return cls._struct_value(struct_format, context, layer_name, offset, symbol_name)
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, size, **kwargs):
|
||||
struct_format, struct_size = context.get_primitive_struct_type("float", symbol_name)
|
||||
struct_size = struct.calcsize(struct_format)
|
||||
return cls._struct_value(struct_format, context, layer_name, offset, symbol_name, size = struct_size)
|
||||
|
||||
class Bytes(PrimitiveObject, bytes):
|
||||
"""Primitive Object that handles specific series of bytes
|
||||
"""
|
||||
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, **kwargs):
|
||||
return cls._struct_value(str(length) + "s", context, layer_name, offset, symbol_name)
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, size, **kwargs):
|
||||
return cls._struct_value(str(size) + "s", context, layer_name, offset, symbol_name, size)
|
||||
|
||||
class String(PrimitiveObject, str):
|
||||
"""Primitive Object that handles string values
|
||||
@@ -54,21 +57,25 @@ class String(PrimitiveObject, str):
|
||||
length: specifies the maximum possible length that the string could hold in memory
|
||||
"""
|
||||
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, length = 1):
|
||||
return cls._struct_value(str(length) + "s", context, layer_name, offset, symbol_name)
|
||||
def __new__(cls, context, layer_name, offset, symbol_name, size = None, length = 1):
|
||||
return cls._struct_value(str(length) + "s", context, layer_name, offset, symbol_name, size)
|
||||
|
||||
class Struct(ObjectInterface):
|
||||
"""Object which can contain members that are other objects"""
|
||||
|
||||
def __init__(self, context, layer_name, offset, symbol_name, size = None, members = None):
|
||||
super(Struct).__init__(self, context, layer_name, offset, symbol_name, size)
|
||||
# Members should be an iterable mapping of symbol names to callable Object Templates
|
||||
# An object template is a callable that when called with a context, offset, layer_name and symbol_name
|
||||
if not isinstance(members, collections.Iterable):
|
||||
raise
|
||||
if struct_size is None:
|
||||
raise TypeError("Struct members parameter must be iterable not " + type(members))
|
||||
if not all([isinstance(members, templates.MemberTemplate)]):
|
||||
raise TypeError("Struct members must be derived from MemberTemplate objects")
|
||||
if size is None:
|
||||
# Attempt to determine the maximum size by asking
|
||||
for i in members:
|
||||
|
||||
pass
|
||||
|
||||
self._members = members
|
||||
|
||||
def __getattr__(self, attr):
|
||||
|
||||
Reference in New Issue
Block a user