Class MaskedBytes

java.lang.Object
ghidra.pcode.emu.jit.folding.MaskedBytes

public final class MaskedBytes extends Object
A masked array of bytes.

This consists of a pair of byte arrays. One that represents the values, if known, and another that indicates which bits of the values array are actually known.

  • Method Details

    • of

      public static MaskedBytes of(byte[] val, byte[] msk)
      Construct from arrays

      The given arrays are copied, and the mask is applied so that all unknown bits have 0s in the values array.

      Parameters:
      val - the value array
      msk - the mask array
      Returns:
      the masked bytes
    • of

      public static MaskedBytes of(BigInteger val, BigInteger msk, int length, Endian endian)
      Construct from big integers
      Parameters:
      val - the value
      msk - the bits of the value that are known
      length - the size of the value in bytes
      endian - the endianness of the bytes
      Returns:
      the masked bytes
    • of

      public static MaskedBytes of(long val, long msk, int length, Endian endian)
      Construct from longs
      Parameters:
      val - the value
      msk - the bits of the value that are known
      length - the size of the value in bytes
      endian - the endianness of the bytes
      Returns:
      the masked bytes
    • ofKnown

      public static MaskedBytes ofKnown(byte[] val)
      Construct from known bytes

      The resulting mask is all 1s.

      Parameters:
      val - the known values
      Returns:
      the masked bytes
    • ofUnknown

      public static MaskedBytes ofUnknown(int length)
      Construct completely unknown

      The contents of both arrays (value and mask) are all 0s

      Parameters:
      length - the number of bytes
      Returns:
      the masked bytes
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isMasked

      public boolean isMasked()
      Returns true if any portion, even a single bit, of the value is unknown.
      Returns:
      true if any portion, even a single bit, of the value is unknown
    • bigValue

      public BigInteger bigValue(Endian endian)
      Returns the value as an unsigned big integer.
      Parameters:
      endian - the endianness of the bytes
      Returns:
      the value as an unsigned big integer
    • bigValueSigned

      public BigInteger bigValueSigned(Endian endian)
      Returns the value as a signed big integer.
      Parameters:
      endian - the endianness of the bytes
      Returns:
      the value as a signed big integer
    • bigMask

      public BigInteger bigMask(Endian endian)
      Returns the mask as an unsigned big integer.
      Parameters:
      endian - the endianness of the bytes
      Returns:
      the mask as an unsigned big integer
    • bigMaskSigned

      public BigInteger bigMaskSigned(Endian endian)
      Returns the mask as a signed big integer.
      Parameters:
      endian - the endianness of the bytes
      Returns:
      the mask as a signed big integer
    • negate

      public MaskedBytes negate()
      Invert the known bits
      Returns:
      the new masked bytes
    • and

      public MaskedBytes and(MaskedBytes that)
      Perform a bitwise and

      Note that known 0s in either operand cause known 0s in the result, even if the same bit of the other operand was unknown.

      Parameters:
      that - the other operand
      Returns:
      the result
    • or

      public MaskedBytes or(MaskedBytes that)
      Perform a bitwise or

      Note that known 1s in either operand cause known ss in the result, even if the same bit of the other operand was unknown.

      Parameters:
      that - the other operand
      Returns:
      the result
    • xor

      public MaskedBytes xor(MaskedBytes that)
      Perform a bitwise xor
      Parameters:
      that - the other operand
      Returns:
      the result
    • floatAbs

      public MaskedBytes floatAbs(Endian endian)
      Zero out the first bit

      The first bit becomes a known 0 in the result, even if it was unknown.

      Parameters:
      endian - the endianness of the bytes
      Returns:
      the result
    • floatNeg

      public MaskedBytes floatNeg(Endian endian)
      Invert the first bit, if it is known
      Parameters:
      endian - the endianness of the bytes
      Returns:
      the result
    • copyOfRange

      public MaskedBytes copyOfRange(int start, int stop)
      Copy a range of the masked bytes
      Parameters:
      start - the first byte to include
      stop - the last byte, exclusive
      Returns:
      the copy
    • sext

      public MaskedBytes sext(int size, Endian endian)
      Perform sign extension

      The sign bit (known 0, known 1, or unknown) is extended to fill the requested size.

      Parameters:
      size - the size in bytes of the result
      endian - the endianness of the bytes
      Returns:
      the extended masked bytes
    • zext

      public MaskedBytes zext(int size, Endian endian)
      Perform zero/unsigned extension

      Known 0s fill to the requested size

      Parameters:
      size - the size in bytes of the result
      endian - the endianness of the bytes
      Returns:
      the extended masked bytes