class documentation

class Register(object):

View In Hierarchy

Models an architecture register that can serve as key to designate that register.

Also provides useful information about the register, such as its size, category or parent register

A Register instance is not meant to be constructed directly. Use registers defined in the reven2.arch modules instead.

Examples

Registers are predefined inside of the arch submodules arch.x64, arch.x87, arch.msr and arch.sse2.

>>> arch.x64.rax
Register(x64.rax)

The main use of registers is to pass them as keys to various methods:

>>> context.read(arch.x64.rax) # reads rax in the current context
42

You can also get some information about the registers:

>>> arch.x64.rax.category
Category(general_purpose)
>>> arch.x64.rax.size_bytes
8
Static Method from_name Get the register from its name or None if reg_name doesn't represent a valid register.
Method __eq__ Compares the instance for equality with an object.
Method __getitem__ Returns the reven2.RegisterSlice corresponding to the indexed register, in bits.
Method __hash__ Returns the hash for this value.
Method __init__ Initializes a Register from a low-level object. Not meant to be called directly.
Method __ne__ Compares the instance for equality with an object.
Method __repr__ Undocumented
Method children An iterator over the children of this register, if any.
Method parent The parent register of this register, if exists. Otherwise, None
Method root The root register of this register.
Property arch Property: The architecture of the register, as a string.
Property bit_offset Property: The offset in bits from the parent register.
Property category Property: The category of the register.
Property name Property: The name of this register as a string.
Property root_bit_offset Property: The offset in bits from the root register.
Property size_bits Property: The exact size of the register, in bits
Property size_bytes Property: The smallest number of bytes required to contain the register
Instance Variable _arch Undocumented
Instance Variable _rvn_node Undocumented
Instance Variable _rvn_reg Undocumented
@staticmethod
def from_name(reg_name):

Get the register from its name or None if reg_name doesn't represent a valid register.

Information

Parameters
reg_name:strthe name of register.
Returns
_Optional[Register]A Register such that its name is equal to reg_name.
def __eq__(self, r):

Compares the instance for equality with an object.

  • if the object is not a Register, it will never be equal to this instance.
def __getitem__(self, item):

Returns the reven2.RegisterSlice corresponding to the indexed register, in bits.

Information

Parameters
item:_Union[int, slice]Undocumented
Returns
_RegisterSliceUndocumented
Raises
IndexErrorif the specified index would be out of bounds.
ValueErrorif the specified slice index contains a step, which is not supported.
def __hash__(self):

Returns the hash for this value.

Returns
intUndocumented
def __init__(self, _rvn_reg, arch):

Initializes a Register from a low-level object. Not meant to be called directly.

Use registers defined in the reven2.arch modules instead.

Information

Parameters
_rvn_reg:_rvn_api.Registerlow-level representation of a register
arch:strstring representing the architecture of that register
def __ne__(self, r):

Compares the instance for equality with an object.

  • if the object is not a Register, it will never be equal to this instance.
def __repr__(self):

Undocumented

def children(self):

An iterator over the children of this register, if any.

Returns
_Iterator[Register]Undocumented
def parent(self):

The parent register of this register, if exists. Otherwise, None

Examples

>>> arch.x64.ah.parent()
Register(x64.eax)
>>> arch.x64.ah.parent().parent()
Register(x64.rax)
>>> arch.x64.ah.parent().parent().parent()
None

Information

Returns
_Optional[Register]A Register.
def root(self):

The root register of this register.

Examples

>>> arch.x64.ah.root()
Register(x64.rax)

Information

Returns
RegisterA Register.
@property
arch: str =

Property: The architecture of the register, as a string.

The architecture is always the same as the module name in which the register resides.

Note: "architectures" are currently defined somewhat arbitrarily:

  • x64: GPR + flags + rip registers
  • sse2: SIMD registers
  • x87: floating point registers
  • msr: msr registers

Examples

>>> arch.x64.iopl.arch
'x64'
>>> arch.sse2.xmm0.arch
'sse2'
>>> arch.x87.fp0.arch
'x87'
>>> arch.msr.aperf.arch
'msr'

Information

Returns
A string.
@property
bit_offset: int =

Property: The offset in bits from the parent register.

If there is no parent register (e.g., rax), returns 0.

Examples

>>> arch.x64.iopl.bit_offset
12
>>> arch.x64.pf.bit_offset
2
>>> arch.x64.rax.bit_offset
0
>>> arch.x87.top.bit_offset
11
>>> arch.msr.aperf.bit_offset
0

Information

Returns
An integer.
@property
category: Category =

Property: The category of the register.

Examples

>>> arch.x64.iopl.category
Category(flags)
>>> arch.x64.rflags.category
Category(condensed_flags)
>>> arch.x64.rax.category
Category(general_purpose)
>>> arch.x64.rip.category
Category(pc)

Information

Returns
A Category instance.
@property
name: str =

Property: The name of this register as a string.

Examples

>>> arch.x64.rax.name
'rax'
>>> arch.x87.fp0.name
'fp0'

Information

Returns
A string.
@property
root_bit_offset: int =

Property: The offset in bits from the root register.

If the current register is the root register (e.g. rax), returns 0.

Note: Most of the time, this returns the same as Register.bit_offset.

Examples

>>> arch.x64.iopl.root_bit_offset
12
>>> arch.x64.pf.root_bit_offset
2
>>> arch.x64.rax.root_bit_offset
0
>>> arch.x87.top.root_bit_offset
11
>>> arch.msr.aperf.root_bit_offset
0

Information

Returns
An integer.
@property
size_bits: int =

Property: The exact size of the register, in bits

Examples

>>> arch.sse2.zmm0.size_bits
512
>>> arch.x64.rax.size_bits
64
>>> arch.x64.iopl.size_bits
2
>>> arch.x64.cf.size_bits
1

Information

Returns
An integer.
@property
size_bytes: int =

Property: The smallest number of bytes required to contain the register

Examples

>>> arch.sse2.zmm0.size_bytes
64
>>> arch.x64.rax.size_bytes
8
>>> arch.x64.iopl.size_bytes
1
>>> arch.x64.cf.size_bytes
1

Information

Returns
An integer.
_arch =

Undocumented

_rvn_node =

Undocumented

_rvn_reg =

Undocumented