Package ghidra.util.bytesearch

# Class DittedBitSequence

java.lang.Object
ghidra.util.bytesearch.DittedBitSequence

Direct Known Subclasses:
  `Pattern`

public class DittedBitSequence extends Object
A pattern of bits/mask to match to a stream of bytes. The bits/mask can be of any length. The sequence can be initialized by: a string an array of bytes (no mask) an array of bytes and for mask The dits represent bits(binary) or nibbles(hex) that are don't care, for example: 0x..d.4de2 ....0000 .1...... 00101101 11101001 where 0x starts a hex number and '.' is a don't care nibble (hex) or bit (binary)

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static int[]`
  `popcount`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DittedBitSequence()`
  `DittedBitSequence(byte[] bytes)`
  Construct a sequence of bytes to search for.
  `DittedBitSequence(byte[] bytes, byte[] mask)`
  Construct a bit pattern to search for consisting of 0 bits, 1 bits, and don't care bits
  `DittedBitSequence(DittedBitSequence op2)`
  Copy contructor
  `DittedBitSequence(DittedBitSequence s1, DittedBitSequence s2)`
  `DittedBitSequence(String dittedBitData)`
  Constructor from a ditted-bit-sequence string where white space is ignored (e.g., "10..11.0");
  `DittedBitSequence(String dittedBitData, boolean hex)`
  Constructor from a ditted-bit string where white space is ignored.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `DittedBitSequence`
  `concatenate(DittedBitSequence toConat)`
  Concatenates a sequence to the end of another sequence and returns a new sequence.
  `boolean`
  `equals(Object obj)`
  `String`
  `getHexString()`
  get a ditted hex string representing this sequence
  `int`
  `getIndex()`
  Get the index or identifying id attached to this pattern
  `byte[]`
  `getMaskBytes()`
  `int`
  `getNumFixedBits()`
  Get number of bits that must be 0/1
  `int`
  `getNumInitialFixedBits(int marked)`
  Get the number of bits that are fixed, not ditted (don't care)
  `int`
  `getNumUncertainBits()`
  Get number of bits that are ditted (don't care)
  `int`
  `getSize()`
  get the size of this sequence in bytes
  `byte[]`
  `getValueBytes()`
  `int`
  `hashCode()`
  `boolean`
  `isMatch(int pos, int val)`
  Check for a match of a value at a certain offset in the pattern.
  `protected int`
  `restoreXmlData(XmlPullParser parser)`
  restore ditted string from XML stream with hex/binary ditted sequences in the form: `<data> 0x..d.4de2 ....0000 .1...... 00101101 11101001 </data>` where 0x starts a hex number and '.' is a don't care nibble (hex) or bit (binary)
  `void`
  `setIndex(int index)`
  Set a an index in a larger sequence, or identifing id on this pattern
  `String`
  `toString()`
  `void`
  `writeBits(StringBuffer buf)`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### popcount

    public static int[] popcount

- ## Constructor Details

  - ### DittedBitSequence

    public DittedBitSequence()

  - ### DittedBitSequence

    public DittedBitSequence(String dittedBitData)
    Constructor from a ditted-bit-sequence string where white space is ignored (e.g., "10..11.0");
    Parameters:
      `dittedBitData` - ditted sequence specified as a string
    Throws:
      `IllegalArgumentException` - if invalid dittedBitData specified

  - ### DittedBitSequence

    public DittedBitSequence(String dittedBitData, boolean hex)
    Constructor from a ditted-bit string where white space is ignored. If there are no dits, `hex` is true, and `hex` does not begin with {code 0x}, `0x` will be prepended to the string before constructing the `DittedBitSequence`.
    Parameters:
      `dittedBitData` - string of bits and dits or hex numbers and dits (e.g., 0.1..0, 0xAB..)
      `hex` - true to force hex on the sequence

  - ### DittedBitSequence

    public DittedBitSequence(DittedBitSequence op2)
    Copy contructor
    Parameters:
      `op2` - is bit sequence being copied

  - ### DittedBitSequence

    public DittedBitSequence(byte[] bytes)
    Construct a sequence of bytes to search for. No bits are masked off.
    Parameters:
      `bytes` - byte values that must match

  - ### DittedBitSequence

    public DittedBitSequence(byte[] bytes, byte[] mask)
    Construct a bit pattern to search for consisting of 0 bits, 1 bits, and don't care bits
    Parameters:
      `bytes` - is an array of bytes indicating the 0 and 1 bits that are cared about
      `mask` - is an array of bytes masking off the bits that should be cared about, a 0 indicates a "don't care"

  - ### DittedBitSequence

    public DittedBitSequence(DittedBitSequence s1, DittedBitSequence s2)

- ## Method Details

  - ### getValueBytes

    public byte[] getValueBytes()
    Returns:
      value bytes

  - ### getMaskBytes

    public byte[] getMaskBytes()
    Returns:
      mask bytes which correspond to value bytes

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### concatenate

    public DittedBitSequence concatenate(DittedBitSequence toConat)
    Concatenates a sequence to the end of another sequence and returns a new sequence.
    Parameters:
      `toConat` - sequence to concatenate to this sequence
    Returns:
      a new sequence that is the concat of this and toConcat

  - ### isMatch

    public boolean isMatch(int pos, int val)
    Check for a match of a value at a certain offset in the pattern. An outside matcher will keep track of the match position within this ditted bit sequence. Then call this method to match.
    Parameters:
      `pos` - position in the pattern to match
      `val` - a byte to be match at the given byte offset in the pattern
    Returns:
      true if the byte matches the sequence mask/value

  - ### setIndex

    public void setIndex(int index)
    Set a an index in a larger sequence, or identifing id on this pattern
    Parameters:
      `index` - - index in match sequence, or unique id

  - ### getIndex

    public int getIndex()
    Get the index or identifying id attached to this pattern
    Returns:
      index or unique id attached to this sequence

  - ### getSize

    public int getSize()
    get the size of this sequence in bytes
    Returns:
      size in bytes

  - ### getNumFixedBits

    public int getNumFixedBits()
    Get number of bits that must be 0/1
    Returns:
      number of bits that are not don't care (ditted)

  - ### getNumUncertainBits

    public int getNumUncertainBits()
    Get number of bits that are ditted (don't care)
    Returns:
      number of ditted bits (don't care)

  - ### writeBits

    public void writeBits(StringBuffer buf)

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### getHexString

    public String getHexString()
    get a ditted hex string representing this sequence
    Returns:
      ditted hex string

  - ### restoreXmlData

    protected int restoreXmlData(XmlPullParser parser) throws IOException
    restore ditted string from XML stream with hex/binary ditted sequences in the form: `<data> 0x..d.4de2 ....0000 .1...... 00101101 11101001 </data>` where 0x starts a hex number and '.' is a don't care nibble (hex) or bit (binary)
    Parameters:
      `parser` - XML pull parser stream
    Returns:
      number of bytes read from XML `<data>` tag
    Throws:
      `IOException` - if XML read has an error

  - ### getNumInitialFixedBits

    public int getNumInitialFixedBits(int marked)
    Get the number of bits that are fixed, not ditted (don't care)
    Parameters:
      `marked` - number of bytes in the pattern to check
    Returns:
      number of initial fixed bits