Class RegisterValue

java.lang.Object
ghidra.program.model.lang.RegisterValue

public class RegisterValue extends Object
Class for representing register values that keep track of which bits are actually set. Values are stored as big-endian: MSB of mask is stored at bytes index 0, MSB of value is stored at (bytes.length/2). Bytes storage example for 4-byte register: Index: 0 1 2 3 4 5 6 7 |MSB| | |LSB|MSB| | |LSB| | ----MASK----- | ----VALUE---- |
  • Constructor Details

    • RegisterValue

      public RegisterValue(Register register)
      Creates a new RegisterValue for a register that has no value (all mask bits are 0);
      Parameters:
      register - the register associated with this value.
    • RegisterValue

      public RegisterValue(Register register, BigInteger value)
      Constructs a new RegisterValue object for the given register and value.
      Parameters:
      value - the value to set. All mask bits for the given register are set to "valid" (on).
    • RegisterValue

      public RegisterValue(Register register, BigInteger value, BigInteger mask)
      Constructs a new RegisterValue using a specified value and mask
      Parameters:
      register -
      value - value corresponding to specified register
      mask - value mask identifying which value bits are valid
    • RegisterValue

      public RegisterValue(Register register, byte[] bytes)
      Constructs a new RegisterValue object for the given register and the mask/value byte array
      Parameters:
      register - the register associated with this value. The register specifies which bits int the total mask/value arrays are used for this register which may be a sub-register of some larger register. The byte[] always is sized for the largest Register that contains the given register.
      bytes - the mask/value array - the first n/2 bytes are the mask and the last n/2 bytes are the value bits.
  • Method Details

    • getRegister

      public Register getRegister()
      Returns the register used in this register value object.
      Returns:
      the register used in this register value object
    • combineValues

      public RegisterValue combineValues(RegisterValue otherValue)
      Creates a new RegisterValue. The resulting value is a combination of this RegisterValue and the given RegisterValue, where the given RegisterValue's value bits take precedence over this RegisterValue's value. Each value bit is determined as follows: If the mask bit in otherValue is "ON", then otherValue's value bit is used. Otherwise, this value bit used. The mask bits are OR'd together to form the new mask bits.
      Parameters:
      otherValue - the currently stored mask and value bytes. The base register must match the base register of this register value.
      Returns:
      a new RegisterValue object containing the original value bits where the new array mask bits are "OFF" and the new value bits where the new array mask bits are "ON". If the registers differ the resulting register value will be relative to the base register.
    • getBaseRegisterValue

      public RegisterValue getBaseRegisterValue()
      Returns this register value in terms of the base register
    • getBaseValueMask

      public byte[] getBaseValueMask()
      Returns the value mask that indicates which bits relative to the base register have a valid value.
    • getValueMask

      public BigInteger getValueMask()
      Returns a value mask which is sized based upon the register
    • assign

      public RegisterValue assign(Register subRegister, RegisterValue value)
      Assign the value to a portion of this register value
      Parameters:
      subRegister - identifies a piece of this register value to be assigned
      value - new value
      Returns:
      new register value after assignment
    • assign

      public RegisterValue assign(Register subRegister, BigInteger value)
      Assign the value to a portion of this register value
      Parameters:
      subRegister - identifies a piece of this register value to be assigned
      value - new value
      Returns:
      new register value after assignment
    • clearBitValues

      public RegisterValue clearBitValues(byte[] mask)
      Clears the value bits corresponding to the "ON" bits in the given mask.
      Parameters:
      mask - the byte array containing the mask bits to clear.
      Returns:
      a new MaskedBytes object containg the original value bits and mask bits cleared where the passed in mask bits were "on".
    • toBytes

      public byte[] toBytes()
      Returns the mask/value bytes for this register value.
      Returns:
      the mask/value bytes for this register value.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • hasValue

      public boolean hasValue()
      Tests if this RegisterValue contains valid value bits for the entire register. In otherwords getSignedValue() or getUnsignedValue will not return null.
      Returns:
      true if all mask bits for the associated register are "ON".
    • getUnsignedValue

      public BigInteger getUnsignedValue()
      Returns the unsigned value for this register if all the appropriate mask bits are "ON". Otherwise, null is return.
      Returns:
      the value for this register if all the appropriate mask bits are "ON". Otherwise, returns null.
    • getUnsignedValueIgnoreMask

      public BigInteger getUnsignedValueIgnoreMask()
      Returns the unsigned value for this register regardless of the mask bits. Bits that have "OFF" mask bits will have the value of 0.
      Returns:
      the unsigned value for this register regardless of the mask bits. Bits that have "OFF" mask bits will have the value of 0.
    • getSignedValue

      public BigInteger getSignedValue()
      Returns the signed value for this register if all the appropriate mask bits are "ON". Otherwise, null is return.
      Returns:
      the signed value for this register if all the appropriate mask bits are "ON". Otherwise, returns null.
    • getSignedValueIgnoreMask

      public BigInteger getSignedValueIgnoreMask()
      Returns the signed value for this register regardless of the mask bits. Bits that have "OFF" mask bits will have the value of 0.
      Returns:
      the signed value for this register regardless of the mask bits. Bits that have "OFF" mask bits will have the value of 0.
    • hasAnyValue

      public boolean hasAnyValue()
    • getRegisterValue

      public RegisterValue getRegisterValue(Register newRegister)