Package ghidra.util.bytesearch
Class DittedBitSequence
- java.lang.Object
-
- ghidra.util.bytesearch.DittedBitSequence
-
- Direct Known Subclasses:
Pattern
public class DittedBitSequence extends java.lang.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 bitsDittedBitSequence(DittedBitSequence op2)
Copy contructorDittedBitSequence(DittedBitSequence s1, DittedBitSequence s2)
DittedBitSequence(java.lang.String dittedBitData)
Constructor from a ditted-bit-sequence string where white space is ignored (e.g., "10..11.0");DittedBitSequence(java.lang.String dittedBitData, boolean hex)
Constructor from a ditted-bit string where white space is ignored.
-
Method Summary
All Methods Instance Methods Concrete Methods 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(java.lang.Object obj)
java.lang.String
getHexString()
get a ditted hex string representing this sequenceint
getIndex()
Get the index or identifying id attached to this patternbyte[]
getMaskBytes()
int
getNumFixedBits()
Get number of bits that must be 0/1int
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 bytesbyte[]
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: 0x..d.4de2 ....0000 .1......void
setIndex(int index)
Set a an index in a larger sequence, or identifing id on this patternjava.lang.String
toString()
void
writeBits(java.lang.StringBuffer buf)
-
-
-
Constructor Detail
-
DittedBitSequence
public DittedBitSequence()
-
DittedBitSequence
public DittedBitSequence(java.lang.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:
java.lang.IllegalArgumentException
- if invalid dittedBitData specified
-
DittedBitSequence
public DittedBitSequence(java.lang.String dittedBitData, boolean hex)
Constructor from a ditted-bit string where white space is ignored. If there are no dits,hex
is true, andhex
does not begin with {code 0x},0x
will 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
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 aboutmask
- 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 Detail
-
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.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 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
public void writeBits(java.lang.StringBuffer buf)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getHexString
public java.lang.String getHexString()
get a ditted hex string representing this sequence- Returns:
- ditted hex string
-
restoreXmlData
protected int restoreXmlData(XmlPullParser parser) throws java.io.IOException
restore ditted string from XML stream with hex/binary ditted sequences in the form: 0x..d.4de2 ....0000 .1...... 00101101 11101001 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 tag
- Throws:
java.io.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
-
-