decompiler  1.0.0
Public Member Functions | Protected Attributes | List of all members
MemoryState Class Reference

All storage/state for a pcode machine. More...

#include <memstate.hh>

Public Member Functions

 MemoryState (Translate *t)
 A constructor for MemoryState. More...
 
TranslategetTranslate (void) const
 Get the Translate object. More...
 
void setMemoryBank (MemoryBank *bank)
 Map a memory bank into the state. More...
 
MemoryBankgetMemoryBank (AddrSpace *spc) const
 Get a memory bank associated with a particular space. More...
 
void setValue (AddrSpace *spc, uintb off, int4 size, uintb cval)
 Set a value on the memory state. More...
 
uintb getValue (AddrSpace *spc, uintb off, int4 size) const
 Retrieve a memory value from the memory state. More...
 
void setValue (const string &nm, uintb cval)
 Set a value on a named register in the memory state. More...
 
uintb getValue (const string &nm) const
 Retrieve a value from a named register in the memory state. More...
 
void setValue (const VarnodeData *vn, uintb cval)
 Set value on a given varnode. More...
 
uintb getValue (const VarnodeData *vn) const
 Get a value from a varnode. More...
 
void getChunk (uint1 *res, AddrSpace *spc, uintb off, int4 size) const
 Get a chunk of data from memory state. More...
 
void setChunk (const uint1 *val, AddrSpace *spc, uintb off, int4 size)
 Set a chunk of data from memory state. More...
 

Protected Attributes

Translatetrans
 Architecture information about memory spaces.
 
vector< MemoryBank * > memspace
 Memory banks associated with each address space.
 

Detailed Description

All storage/state for a pcode machine.

Every piece of information in a pcode machine is representable as a triple (AddrSpace,offset,size). This class allows getting and setting of all state information of this form.

Constructor & Destructor Documentation

MemoryState::MemoryState ( Translate t)
inline

A constructor for MemoryState.

The MemoryState needs a Translate object in order to be able to convert register names into varnodes

Parameters
tis the translator

Member Function Documentation

void MemoryState::getChunk ( uint1 *  res,
AddrSpace spc,
uintb  off,
int4  size 
) const

Get a chunk of data from memory state.

This is the main interface for reading a range of bytes from the MemorySate. The MemoryBank associated with the address space of the query is looked up and the request is forwarded to the getChunk method on the MemoryBank. If there is no registered MemoryBank or some other error, an exception is thrown

Parameters
resis a pointer to the result buffer for storing retrieved bytes
spcis the desired address space
offis the starting offset of the byte range being queried
sizeis the number of bytes being queried

References MemoryBank::getChunk(), and AddrSpace::getName().

MemoryBank * MemoryState::getMemoryBank ( AddrSpace spc) const

Get a memory bank associated with a particular space.

Any MemoryBank that has been registered with this MemoryState can be retrieved via this method if the MemoryBank's associated address space is known.

Parameters
spcis the address space of the desired MemoryBank
Returns
a pointer to the MemoryBank or null if no bank is associated with spc.

References AddrSpace::getIndex().

Translate * MemoryState::getTranslate ( void  ) const
inline

Get the Translate object.

Retrieve the actual pcode translator being used by this machine state

Returns
a pointer to the Translate object
uintb MemoryState::getValue ( AddrSpace spc,
uintb  off,
int4  size 
) const

Retrieve a memory value from the memory state.

This is the main interface for reading values from the MemoryState. If there is no registered MemoryBank for the desired address space, or if there is some other error, an exception is thrown.

Parameters
spcis the address space being queried
offis the offset of the value being queried
sizeis the number of bytes to query
Returns
the queried value

References AddrSpace::getName(), AddrSpace::getType(), MemoryBank::getValue(), and IPTR_CONSTANT.

uintb MemoryState::getValue ( const string &  nm) const

Retrieve a value from a named register in the memory state.

This is a convenience method for reading registers by name. Any register name known to the Translate object can be used as a read location. The associated address space, offset, and size is looked up and automatically passed to the main getValue routine.

Parameters
nmis the name of the register
Returns
the value associated with that register

References MemoryBank::getValue().

uintb MemoryState::getValue ( const VarnodeData vn) const
inline

Get a value from a varnode.

A convenience method for reading a value directly from a varnode rather than querying for the offset and space

Parameters
vnis a pointer to the varnode to be read
Returns
the value read from the varnode

References MemoryBank::getValue(), VarnodeData::offset, VarnodeData::size, and VarnodeData::space.

void MemoryState::setChunk ( const uint1 *  val,
AddrSpace spc,
uintb  off,
int4  size 
)

Set a chunk of data from memory state.

This is the main interface for setting values for a range of bytes in the MemoryState. The MemoryBank associated with the desired address space is looked up and the write is forwarded to the setChunk method on the MemoryBank. If there is no registered MemoryBank or some other error, an exception is throw.

Parameters
valis a pointer to the byte values to be written into the MemoryState
spcis the address space being written
offis the starting offset of the range being written
sizeis the number of bytes to write

References AddrSpace::getName(), and MemoryBank::setChunk().

void MemoryState::setMemoryBank ( MemoryBank bank)

Map a memory bank into the state.

MemoryBanks associated with specific address spaces must be registers with this MemoryState via this method. Each address space that will be used during emulation must be registered separately. The MemoryState object does not assume responsibility for freeing the MemoryBank

Parameters
bankis a pointer to the MemoryBank to be registered

References AddrSpace::getIndex(), and MemoryBank::getSpace().

void MemoryState::setValue ( AddrSpace spc,
uintb  off,
int4  size,
uintb  cval 
)

Set a value on the memory state.

This is the main interface for writing values to the MemoryState. If there is no registered MemoryBank for the desired address space, or if there is some other error, an exception is thrown.

Parameters
spcis the address space to write to
offis the offset where the value should be written
sizeis the number of bytes to be written
cvalis the value to be written

References AddrSpace::getName(), and MemoryBank::setValue().

void MemoryState::setValue ( const string &  nm,
uintb  cval 
)

Set a value on a named register in the memory state.

This is a convenience method for setting registers by name. Any register name known to the Translate object can be used as a write location. The associated address space, offset, and size is looked up and automatically passed to the main setValue routine.

Parameters
nmis the name of the register
cvalis the value to write to the register

References MemoryBank::setValue().

void MemoryState::setValue ( const VarnodeData vn,
uintb  cval 
)
inline

Set value on a given varnode.

A convenience method for setting a value directly on a varnode rather than breaking out the components

Parameters
vnis a pointer to the varnode to be written
cvalis the value to write into the varnode

References VarnodeData::offset, MemoryBank::setValue(), VarnodeData::size, and VarnodeData::space.


The documentation for this class was generated from the following files: