Class 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 space
      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
      java.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 space
      long getValue​(Varnode vn)
      A convenience method for reading a value directly from a varnode rather than querying for the offset and space
      long 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 components
      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
      void setValue​(Varnode vn, long cval)
      A convenience method for setting a value directly on a varnode rather than breaking out the components
      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
      void 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 written
        cval - 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 written
        cval - 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 register
        cval - 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 to
        off - is the offset where the value should be written
        size - is the number of bytes to be written
        cval - 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 queried
        off - is the offset of the value being queried
        size - 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 written
        cval - 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 written
        cval - 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 register
        cval - 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 to
        off - is the offset where the value should be written
        size - is the number of bytes to be written
        cval - 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 read
        signed - 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 queried
        off - is the offset of the value being queried
        size - is the number of bytes to query
        signed - 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 bytes
        spc - the desired address space
        off - the starting offset of the byte range being read
        size - the number of bytes being read
        stopOnUnintialized - 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 MemoryState
        spc - the address space being written
        off - the starting offset of the range being written
        size - 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 not
        spc - the address space being written
        off - the starting offset of the range being written
        size - the number of bytes to write