decompiler  1.0.0
Public Member Functions | Protected Attributes | List of all members
ghidra::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()

ghidra::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

◆ getChunk()

void ghidra::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 ghidra::MemoryBank::getChunk(), and ghidra::AddrSpace::getName().

◆ getMemoryBank()

MemoryBank * ghidra::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 ghidra::AddrSpace::getIndex().

◆ getTranslate()

Translate * ghidra::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

◆ getValue() [1/3]

uintb ghidra::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 ghidra::AddrSpace::getName(), ghidra::AddrSpace::getType(), ghidra::MemoryBank::getValue(), and ghidra::IPTR_CONSTANT.

◆ getValue() [2/3]

uintb ghidra::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 ghidra::MemoryBank::getValue().

◆ getValue() [3/3]

uintb ghidra::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 ghidra::MemoryBank::getValue(), ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.

◆ setChunk()

void ghidra::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 ghidra::AddrSpace::getName(), and ghidra::MemoryBank::setChunk().

◆ setMemoryBank()

void ghidra::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 ghidra::AddrSpace::getIndex(), and ghidra::MemoryBank::getSpace().

◆ setValue() [1/3]

void ghidra::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 ghidra::AddrSpace::getName(), and ghidra::MemoryBank::setValue().

◆ setValue() [2/3]

void ghidra::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 ghidra::MemoryBank::setValue().

◆ setValue() [3/3]

void ghidra::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 ghidra::VarnodeData::offset, ghidra::MemoryBank::setValue(), ghidra::VarnodeData::size, and ghidra::VarnodeData::space.


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