class documentation

class Pointer(Type):

View In Hierarchy

A type constructor that accepts a type T as parameter and builds the type representing "a pointer to T" (T*).

The main use of pointer types is that they can be dereferenced. See reven2.trace.Context.deref for more information.

When an instance of a pointer type is read, it is returned as an address, built from the read offset and from a base address stored in the pointer type.

Note: when reading the address of a pointer, it is considered like an integer of the same endianness, signedness and size as USize.

Method __eq__ Compares the instance for equality with an object.
Method __hash__ Returns the hash for this value.
Method __init__ Initializes a new pointer type from its element type and the kind of address it should produce.
Method __ne__ Undocumented
Method __str__ Returns the nicely printable string representation of this instance.
Method cast_inner Returns a new pointer type, specifying a different element type it should dereference to.
Method is_context_sensitive Whether the context argument needed by some methods actually has an effect.
Method size_bytes The minimal number of bytes necessary to hold an instance of a pointer, that may depend on the context.
Property elem_type Property: The pointed-to type.
Static Method _compute_base_address Undocumented
Method _construct_type Return the underlying construct instance
Method _decode Undocumented
Method _encode Undocumented
Method _resolve Uses the resolver to return a resolved version of the type, if possible.
Instance Variable _base_address Undocumented
Instance Variable _elem_type Undocumented
Instance Variable _underlying_type Undocumented

Inherited from Type:

Method description The short description of this type.
Method parse Parses the value of an instance of this type from a raw buffer, possibly depending on the context.
Method to_bytes Build a byte buffer from a value of this type.
def __eq__(self, o):

Compares the instance for equality with an object.

  • if the object is not a Pointer, it will never be equal to this instance.
Parameters
o:objectUndocumented
Returns
boolUndocumented
def __hash__(self):

Returns the hash for this value.

Returns
intUndocumented
def __init__(self, elem_type, segment_register=None, segment_index=None, is_linear=False, is_physical=False, base_address=None, size=None):

Initializes a new pointer type from its element type and the kind of address it should produce.

Kind of address

When the value of a Pointer is read, it is returned as an address. Since there are logical addresses with various segments, linear addresses and physical addresses, it is important that a Pointer instance knows which kind of addresses it should produce.

To determine the kind of address produced by a Pointer instance, one of the following arguments can be provided to its constructor:

  • segment_register: to specify a logical address using a segment register
  • segment_index: to specify a logical address using a segment index
  • is_linear: to specify a linear address
  • is_physical: to specify a physical address
  • base_address: to specify that the produced address is an offset relative to an existing base_address. This is useful for instance when reading a table containing offsets used to build function pointers relative to a fixed base address.

If none of these arguments is provided, then the address kind will default to logical addresses with the default segment (ds).

Additionally, the pointer size can either be context-sensitive (by default), meaning it will be 64-bit in 64-bit contexts and 32-bit in 32-bit contexts, or explicitly specified (and thus not context-sensitive).

Information

Parameters
elem_type:Typethe pointed-to type.
segment_register:_Optional[Register]a segment register indicating that logical addresses using this segment register should be produced.
segment_index:_Optional[int]an integer indicating that logical addresses using this segment index should be produced.
is_linear:boolif True, indicates that linear addresses should be produced.
is_physical:boolif True, indicates that physical addresses should be produced.
base_address:_Optional[address._AbstractAddress]the base address from which addresses should be produced.
size:_Optional[int]if provided, the size of the pointer. If None, then the pointer's size is determined by the bitness of the current context.
Raises
TypeErrorif elem_type is not a type
TypeErrorif base_address is not an address
ValueErrorif more than one in 'segment_register', 'segment_index', 'is_linear', 'is_physical' or 'base_address' is provided
ValueErrorif a size different from 2, 4, 8, 16 or None is specified.
def __ne__(self, o):

Undocumented

Parameters
o:objectUndocumented
Returns
boolUndocumented
def __str__(self):

Returns the nicely printable string representation of this instance.

Returns
strUndocumented
def cast_inner(self, inner):

Returns a new pointer type, specifying a different element type it should dereference to.

This method is a cast, able to change the type that the pointer points to. It cannot fail, but make sure the result makes sense.

Parameters
inner:TypeUndocumented
Returns
PointerUndocumented
def is_context_sensitive(self):

Whether the context argument needed by some methods actually has an effect.

Types that return False to this method are context-insensitive types. You can safely pass any object as context parameter (including None) to the methods of such type.

Note that the context-sensitivity of a type may change in the future.

Examples

Getting the size of a type without needing a context for context-insensitive types: >>> types.U32.is_context_sensitive() False >>> types.U32.size_bytes(context=None) 4 >>> array32_12 = types.Array(types.U32, 12) >>> array32_12.is_context_sensitive() False >>> array32_12.size_bytes() # context=None by default 48

Context-sensitive types may raise errors when attempting to get the size without a context: >>> types.USize.is_context_sensitive() True >>> types.USize.size_bytes(context=None) ValueError: Please provide a context when using a context-sensitive type

Returns
boolUndocumented
def size_bytes(self, context=None):

The minimal number of bytes necessary to hold an instance of a pointer, that may depend on the context.

Information

Parameters
context:_Optional[Context]The context object. See package documentation.
Returns
intAn integer.
@property
elem_type: Type =

Property: The pointed-to type.

Information

Returns
A type from reven2.types.
@staticmethod
def _compute_base_address(segment_register, segment_index, is_linear, is_physical, base_address):

Undocumented

Parameters
segment_register:_Optional[Register]Undocumented
segment_index:_Optional[int]Undocumented
is_linear:boolUndocumented
is_physical:boolUndocumented
base_address:_Optional[address._AbstractAddress]Undocumented
Returns
address._AbstractAddressUndocumented
def _construct_type(self, context=None):

Return the underlying construct instance

Parameters
context:_Optional[Context]Undocumented
Returns
_construct.core.ConstructUndocumented
def _decode(self, offset, _):

Undocumented

Parameters
offset:intUndocumented
_Undocumented
Returns
address._AbstractAddressUndocumented
def _encode(self, value, _):

Undocumented

Parameters
value:address._AbstractAddressUndocumented
_Undocumented
Returns
intUndocumented
def _resolve(self, resolver):

Uses the resolver to return a resolved version of the type, if possible.

Parameters
resolver:BaseTypeResolverUndocumented
Returns
TypeUndocumented
_base_address =

Undocumented

_elem_type =

Undocumented

_underlying_type =

Undocumented