Package ghidra.program.model.lang
Class RegisterValue
java.lang.Object
ghidra.program.model.lang.RegisterValue
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 Summary
ConstructorDescriptionRegisterValue
(Register register) Creates a new RegisterValue for a register that has no value (all mask bits are 0);RegisterValue
(Register register, byte[] bytes) Constructs a new RegisterValue object for the given register and the mask/value byte arrayRegisterValue
(Register register, BigInteger value) Constructs a new RegisterValue object for the given register and value.RegisterValue
(Register register, BigInteger value, BigInteger mask) Constructs a new RegisterValue using a specified value and mask -
Method Summary
Modifier and TypeMethodDescriptionassign
(Register subRegister, RegisterValue value) Assign the value to a portion of this register valueassign
(Register subRegister, BigInteger value) Assign the value to a portion of this register valueclearBitValues
(byte[] mask) Clears the value bits corresponding to the "ON" bits in the given mask.combineValues
(RegisterValue otherValue) Creates a new RegisterValue.boolean
Returns this register value in terms of the base registerbyte[]
Returns the value mask that indicates which bits relative to the base register have a valid value.Returns the register used in this register value object.getRegisterValue
(Register newRegister) Returns the signed value for this register if all the appropriate mask bits are "ON".Returns the signed value for this register regardless of the mask bits.Returns the unsigned value for this register if all the appropriate mask bits are "ON".Returns the unsigned value for this register regardless of the mask bits.Returns a value mask which is sized based upon the registerboolean
int
hashCode()
boolean
hasValue()
Tests if this RegisterValue contains valid value bits for the entire register.byte[]
toBytes()
Returns the mask/value bytes for this register value.toString()
-
Constructor Details
-
RegisterValue
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
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
Constructs a new RegisterValue using a specified value and mask- Parameters:
register
-value
- value corresponding to specified registermask
- value mask identifying which value bits are valid
-
RegisterValue
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
Returns the register used in this register value object.- Returns:
- the register used in this register value object
-
combineValues
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 inotherValue
is "ON", thenotherValue
'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
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
Returns a value mask which is sized based upon the register -
assign
Assign the value to a portion of this register value- Parameters:
subRegister
- identifies a piece of this register value to be assignedvalue
- new value- Returns:
- new register value after assignment
-
assign
Assign the value to a portion of this register value- Parameters:
subRegister
- identifies a piece of this register value to be assignedvalue
- new value- Returns:
- new register value after assignment
-
clearBitValues
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() -
equals
-
toString
-
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
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
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
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
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
-