Package ghidra.pcode.memstate
Class MemoryState
- java.lang.Object
-
- ghidra.pcode.memstate.MemoryState
-
public class MemoryState extends java.lang.Object
All storage/state for a pcode emulator machine Every piece of information in a pcode emulator machine is representable as a triple (AddressSpace,offset,size). This class allows getting and setting of all state information of this form.
-
-
Constructor Summary
Constructors Constructor Description MemoryState(Language language)
MemoryState constructor for a specified processor language
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.math.BigInteger
getBigInteger(AddressSpace spc, long off, int size, boolean signed)
This is the main interface for reading values from the MemoryState.java.math.BigInteger
getBigInteger(Register reg)
A convenience method for reading a value directly from a register rather than querying for the offset and spacejava.math.BigInteger
getBigInteger(Varnode vn, boolean signed)
A convenience method for reading a value directly from a varnode rather than querying for the offset and spacejava.math.BigInteger
getBigInteger(java.lang.String nm)
This is a convenience method for reading registers by name.int
getChunk(byte[] res, AddressSpace spc, long off, int size, boolean stopOnUnintialized)
This is the main interface for reading a range of bytes from the MemorySate.MemoryBank
getMemoryBank(AddressSpace spc)
Any MemoryBank that has been registered with this MemoryState can be retrieved via this method if the MemoryBank's associated address space is known.long
getValue(AddressSpace spc, long off, int size)
This is the main interface for reading values from the MemoryState.long
getValue(Register reg)
A convenience method for reading a value directly from a register rather than querying for the offset and spacelong
getValue(Varnode vn)
A convenience method for reading a value directly from a varnode rather than querying for the offset and spacelong
getValue(java.lang.String nm)
This is a convenience method for reading registers by name.void
setChunk(byte[] val, AddressSpace spc, long off, int size)
This is the main interface for setting values for a range of bytes in the MemoryState.void
setInitialized(boolean initialized, AddressSpace spc, long off, int size)
This is the main interface for setting the initialization status for a range of bytes in the MemoryState.void
setMemoryBank(MemoryBank bank)
MemoryBanks associated with specific address spaces must be registers with this MemoryState via this method.void
setValue(AddressSpace spc, long off, int size, long cval)
This is the main interface for writing values to the MemoryState.void
setValue(AddressSpace spc, long off, int size, java.math.BigInteger cval)
This is the main interface for writing values to the MemoryState.void
setValue(Register reg, long cval)
A convenience method for setting a value directly on a register rather than breaking out the componentsvoid
setValue(Register reg, java.math.BigInteger cval)
A convenience method for setting a value directly on a register rather than breaking out the componentsvoid
setValue(Varnode vn, long cval)
A convenience method for setting a value directly on a varnode rather than breaking out the componentsvoid
setValue(Varnode vn, java.math.BigInteger cval)
A convenience method for setting a value directly on a varnode rather than breaking out the componentsvoid
setValue(java.lang.String nm, long cval)
This is a convenience method for setting registers by name.void
setValue(java.lang.String nm, java.math.BigInteger cval)
This is a convenience method for setting registers by name.
-
-
-
Constructor Detail
-
MemoryState
public MemoryState(Language language)
MemoryState constructor for a specified processor language- Parameters:
language
-
-
-
Method Detail
-
setMemoryBank
public final void setMemoryBank(MemoryBank bank)
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:
bank
- is a pointer to the MemoryBank to be registered
-
getMemoryBank
public final MemoryBank getMemoryBank(AddressSpace spc)
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:
spc
- is the address space of the desired MemoryBank- Returns:
- the MemoryBank or null if no bank is associated with spc.
-
setValue
public final void setValue(Varnode vn, long cval)
A convenience method for setting a value directly on a varnode rather than breaking out the components- Parameters:
vn
- the varnode location to be writtencval
- the value to write into the varnode location
-
setValue
public final void setValue(Register reg, long cval)
A convenience method for setting a value directly on a register rather than breaking out the components- Parameters:
reg
- the register location to be writtencval
- the value to write into the register location
-
setValue
public final void setValue(java.lang.String nm, long cval)
This is a convenience method for setting registers by name. Any register name known to the language 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:
nm
- is the name of the registercval
- is the value to write to the register
-
setValue
public final void setValue(AddressSpace spc, long off, int size, long cval)
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:
spc
- is the address space to write tooff
- is the offset where the value should be writtensize
- is the number of bytes to be writtencval
- is the value to be written
-
getValue
public final long getValue(Varnode vn)
A convenience method for reading a value directly from a varnode rather than querying for the offset and space- Parameters:
vn
- the varnode location to be read- Returns:
- the value read from the varnode location
-
getValue
public final long getValue(Register reg)
A convenience method for reading a value directly from a register rather than querying for the offset and space- Parameters:
reg
- the register location to be read- Returns:
- the value read from the register location
-
getValue
public final long getValue(java.lang.String nm)
This is a convenience method for reading registers by name. any register name known to the language 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:
nm
- is the name of the register- Returns:
- the value associated with that register
-
getValue
public final long getValue(AddressSpace spc, long off, int size)
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:
spc
- is the address space being queriedoff
- is the offset of the value being queriedsize
- is the number of bytes to query- Returns:
- the queried value
-
setValue
public final void setValue(Varnode vn, java.math.BigInteger cval)
A convenience method for setting a value directly on a varnode rather than breaking out the components- Parameters:
vn
- the varnode location to be writtencval
- the value to write into the varnode location
-
setValue
public final void setValue(Register reg, java.math.BigInteger cval)
A convenience method for setting a value directly on a register rather than breaking out the components- Parameters:
reg
- the register location to be writtencval
- the value to write into the register location
-
setValue
public final void setValue(java.lang.String nm, java.math.BigInteger cval)
This is a convenience method for setting registers by name. Any register name known to the language 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:
nm
- is the name of the registercval
- is the value to write to the register
-
setValue
public final void setValue(AddressSpace spc, long off, int size, java.math.BigInteger cval)
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:
spc
- is the address space to write tooff
- is the offset where the value should be writtensize
- is the number of bytes to be writtencval
- is the value to be written
-
getBigInteger
public final java.math.BigInteger getBigInteger(Varnode vn, boolean signed)
A convenience method for reading a value directly from a varnode rather than querying for the offset and space- Parameters:
vn
- the varnode location to be readsigned
- true if signed value should be returned, false for unsigned value- Returns:
- the unsigned value read from the varnode location
-
getBigInteger
public final java.math.BigInteger getBigInteger(Register reg)
A convenience method for reading a value directly from a register rather than querying for the offset and space- Parameters:
reg
- the register location to be read- Returns:
- the unsigned value read from the register location
-
getBigInteger
public final java.math.BigInteger getBigInteger(java.lang.String nm)
This is a convenience method for reading registers by name. any register name known to the language 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:
nm
- is the name of the register- Returns:
- the unsigned value associated with that register
-
getBigInteger
public final java.math.BigInteger getBigInteger(AddressSpace spc, long off, int size, boolean signed)
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:
spc
- is the address space being queriedoff
- is the offset of the value being queriedsize
- is the number of bytes to querysigned
- true if signed value should be returned, false for unsigned value- Returns:
- the queried unsigned value
-
getChunk
public int getChunk(byte[] res, AddressSpace spc, long off, int size, boolean stopOnUnintialized)
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. All getLongValue methods utilize this method to read the bytes from the appropriate memory bank.- Parameters:
res
- the result buffer for storing retrieved bytesspc
- the desired address spaceoff
- the starting offset of the byte range being readsize
- the number of bytes being readstopOnUnintialized
- if true a partial read is permitted and returned size may be smaller than size requested- Returns:
- number of bytes actually read
- Throws:
LowlevelError
- if spc has not been mapped within this MemoryState or memory fault handler generated error
-
setChunk
public void setChunk(byte[] val, AddressSpace spc, long off, int size)
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. All setValue methods utilize this method to read the bytes from the appropriate memory bank.- Parameters:
val
- the byte values to be written into the MemoryStatespc
- the address space being writtenoff
- the starting offset of the range being writtensize
- the number of bytes to write- Throws:
LowlevelError
- if spc has not been mapped within this MemoryState
-
setInitialized
public void setInitialized(boolean initialized, AddressSpace spc, long off, int size)
This is the main interface for setting the initialization status 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 setInitialized method on the MemoryBank. If there is no registered MemoryBank or some other error, an exception is throw. All setValue methods utilize this method to read the bytes from the appropriate memory bank.- Parameters:
initialized
- indicates if range should be marked as initialized or notspc
- the address space being writtenoff
- the starting offset of the range being writtensize
- the number of bytes to write
-
-