Package ghidra.util.bytesearch
Class DittedBitSequence
java.lang.Object
ghidra.util.bytesearch.DittedBitSequence
- Direct Known Subclasses:
Pattern
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 -
Constructor Summary
ConstructorsConstructorDescriptionDittedBitSequence(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 bitsCopy contructorDittedBitSequence(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 TypeMethodDescriptionconcatenate(DittedBitSequence toConat) Concatenates a sequence to the end of another sequence and returns a new sequence.booleanget a ditted hex string representing this sequenceintgetIndex()Get the index or identifying id attached to this patternbyte[]intGet number of bits that must be 0/1intgetNumInitialFixedBits(int marked) Get the number of bits that are fixed, not ditted (don't care)intGet number of bits that are ditted (don't care)intgetSize()get the size of this sequence in bytesbyte[]inthashCode()booleanisMatch(int pos, int val) Check for a match of a value at a certain offset in the pattern.protected intrestoreXmlData(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)voidsetIndex(int index) Set a an index in a larger sequence, or identifing id on this patterntoString()voidwriteBits(StringBuffer buf)
-
Field Details
-
popcount
public static int[] popcount
-
-
Constructor Details
-
DittedBitSequence
public DittedBitSequence() -
DittedBitSequence
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
Constructor from a ditted-bit string where white space is ignored. If there are no dits,hexis true, andhexdoes not begin with {code 0x},0xwill be prepended to the string before constructing theDittedBitSequence.- 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
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 aboutmask- is an array of bytes masking off the bits that should be cared about, a 0 indicates a "don't care"
-
DittedBitSequence
-
-
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() -
equals
-
concatenate
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 matchval- 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
-
toString
-
getHexString
get a ditted hex string representing this sequence- Returns:
- ditted hex string
-
restoreXmlData
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
-