Package envi :: Module registers :: Class RegisterContext
[hide private]
[frames] | no frames]

Class RegisterContext

source code

Known Subclasses:

Instance Methods [hide private]
 
__init__(self, regdef=(), metas=(), pcindex=None, spindex=None)
Hand in a register definition which consists of a list of (<name>, <width>) tuples.
source code
 
_rctx_Export(self, sobj)
Given an object with attributes with the same names as registers in our context, set the ones he has to match our values.
source code
 
_rctx_Import(self, sobj)
Given an object with attributes with the same names as registers in our context, populate our values from it.
source code
 
_xlateToMetaReg(self, index, value)
Translate a register value to the meta register value (used when getting a meta register)
source code
 
_xlateToNativeReg(self, index, value)
Translate a register value to the native register value (used when setting a meta register)
source code
 
addMetaRegister(self, name, idx, offset, width)
Meta registers are registers which are really just directly addressable parts of already existing registers (eax -> al).
source code
 
getMetaRegInfo(self, index)
Return the appropriate realreg, shift, mask info for the specified metareg idx (or None if it's not meta).
source code
 
getProgramCounter(self)
Get the value of the program counter for this register context.
source code
 
getRegDef(self) source code
 
getRegister(self, index)
Return the current value of the specified register index.
source code
 
getRegisterByName(self, name) source code
 
getRegisterIndex(self, name)
Get a register index by name.
source code
 
getRegisterInfo(self, meta=False)
Return an object which can be stored off, and restored to re-initialize a register context.
source code
 
getRegisterName(self, index) source code
 
getRegisterNameIndexes(self)
Return a list of all the "real" (non meta) registers and their indexes.
source code
 
getRegisterNames(self) source code
 
getRegisterSnap(self)
Use this to bulk save off the register state.
source code
 
getRegisterWidth(self, index)
Return the width of the register which lives at the specified index (width is always in bits).
source code
 
getRegisters(self)
Get all the *real* registers from this context as a dictionary of name value pairs.
source code
 
getStackCounter(self) source code
 
isDirty(self)
Returns true if registers in this context have been modififed since their import.
source code
 
isMetaRegister(self, index) source code
 
loadRegDef(self, regdef, defval=0)
Load a register definition.
source code
 
loadRegMetas(self, metas)
Load a set of defined "meta" registers for this architecture.
source code
 
reprRegister(self, idx)
This may be used to allow a register context to provide extended repr (flags breakouts, etc) info about a register.
source code
 
setIsDirty(self, bool) source code
 
setProgramCounter(self, value)
Set the value of the program counter for this register contex.
source code
 
setRegister(self, index, value)
Set a register value by index.
source code
 
setRegisterByName(self, name, value) source code
 
setRegisterIndexes(self, pcindex, spindex) source code
 
setRegisterInfo(self, info)
Import the exported data from
source code
 
setRegisterSnap(self, snap)
Use this to bulk restore the register state.
source code
 
setRegisters(self, regdict)
For any name value pairs in the specified dictionary, set the current register values in this context.
source code
 
setStackCounter(self, value) source code
Method Details [hide private]

_rctx_Import(self, sobj)

source code 

Given an object with attributes with the same names as registers in our context, populate our values from it.

NOTE: This also clears the dirty flag

addMetaRegister(self, name, idx, offset, width)

source code 

Meta registers are registers which are really just directly addressable parts of already existing registers (eax -> al).

To add a meta register, you give the name, the idx of the *real* register, the width of the meta reg, and it's left shifted (in bits) offset into the real register value. The RegisterContext will take care of accesses after that.

getMetaRegInfo(self, index)

source code 

Return the appropriate realreg, shift, mask info
for the specified metareg idx (or None if it's not
meta).

Example:
    real_reg, lshift, mask = r.getMetaRegInfo(x)

getRegisterIndex(self, name)

source code 

Get a register index by name. (faster to use the index multiple times)

getRegisterInfo(self, meta=False)

source code 

Return an object which can be stored off, and restored to re-initialize a register context. (much like snapshot but it takes the definitions with it)

getRegisterNameIndexes(self)

source code 

Return a list of all the "real" (non meta) registers and their indexes.

Example: for regname, regidx in x.getRegisterNameIndexes():

loadRegDef(self, regdef, defval=0)

source code 

Load a register definition. A register definition consists of a list of tuples with the following format: (regname, regwidth)

NOTE: All widths in envi RegisterContexts are in bits.

loadRegMetas(self, metas)

source code 

Load a set of defined "meta" registers for this architecture. Meta registers are defined as registers who exist as a subset of the bits in some other "real" register. The argument metas is a list of tuples with the following format: (regname, reg_shift_offset, reg_width) The given example is for the AX register in the i386 subsystem regname: "ax" reg_shift_offset: 0 reg_width: 16

setRegisterSnap(self, snap)

source code 

Use this to bulk restore the register state.

NOTE: This may only be used under the assumption that the
      RegisterContext has been initialized the same way
      (like context switches in tracers, or emulaction snaps)