Package ghidra.program.model.lang
Class RegisterValue
- java.lang.Object
-
- ghidra.program.model.lang.RegisterValue
-
public class RegisterValue extends java.lang.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 Summary
Constructors Constructor Description RegisterValue(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, java.math.BigInteger value)
Constructs a new RegisterValue object for the given register and value.RegisterValue(Register register, java.math.BigInteger value, java.math.BigInteger mask)
Constructs a new RegisterValue using a specified value and mask
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegisterValue
assign(Register subRegister, RegisterValue value)
Assign the value to a portion of this register valueRegisterValue
assign(Register subRegister, java.math.BigInteger value)
Assign the value to a portion of this register valueRegisterValue
clearBitValues(byte[] mask)
Clears the value bits corresponding to the "ON" bits in the given mask.RegisterValue
combineValues(RegisterValue otherValue)
Creates a new RegisterValue.boolean
equals(java.lang.Object obj)
RegisterValue
getBaseRegisterValue()
Returns this register value in terms of the base registerbyte[]
getBaseValueMask()
Returns the value mask that indicates which bits relative to the base register have a valid value.Register
getRegister()
Returns the register used in this register value object.RegisterValue
getRegisterValue(Register newRegister)
java.math.BigInteger
getSignedValue()
Returns the signed value for this register if all the appropriate mask bits are "ON".java.math.BigInteger
getSignedValueIgnoreMask()
Returns the signed value for this register regardless of the mask bits.java.math.BigInteger
getUnsignedValue()
Returns the unsigned value for this register if all the appropriate mask bits are "ON".java.math.BigInteger
getUnsignedValueIgnoreMask()
Returns the unsigned value for this register regardless of the mask bits.java.math.BigInteger
getValueMask()
Returns a value mask which is sized based upon the registerboolean
hasAnyValue()
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.java.lang.String
toString()
-
-
-
Constructor Detail
-
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, java.math.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, java.math.BigInteger value, java.math.BigInteger mask)
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
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 Detail
-
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 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
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 java.math.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 assignedvalue
- new value- Returns:
- new register value after assignment
-
assign
public RegisterValue assign(Register subRegister, java.math.BigInteger value)
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
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.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
public java.math.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 java.math.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 java.math.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 java.math.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)
-
-