Package ghidra.program.model.correlate
Class Block
- java.lang.Object
-
- ghidra.program.model.correlate.Block
-
public class Block extends java.lang.Object
This class holds basic-block information for matching algorithms. It is used as a node to traverse the control-flow graph. It serves as a container for hashing information associated with Instructions in the block. It holds disambiguating hashes (calculated primarily from basic-block parent/child relationships) to help separate identical or near identical sequences of Instructions within one function.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
allUnknown(int startindex, int length)
If the indicated n-gram, within this block, consists of unmatched instructionsprotected void
calcHashes(int minLength, int maxLength, boolean wholeBlock, boolean matchOnly, HashCalculator hashCalc)
Calculate n-gram hashes used for matching (for Instructions in this basic-block).protected void
clearSort()
Clear out structures associated with main sortint
getMatchHash()
int
hashGram(int gramSize, InstructHash instHash, HashCalculator hashCalc)
Calculate an n-gram hash, given a particular hash functionprotected void
setMatched(int index)
Set up block match deconfliction value matchHash.
-
-
-
Field Detail
-
isMatched
protected boolean isMatched
-
isVisited
protected boolean isVisited
-
origBlock
protected CodeBlock origBlock
-
instList
protected InstructHash[] instList
-
-
Constructor Detail
-
Block
public Block(CodeBlock codeBlock)
-
-
Method Detail
-
clearSort
protected void clearSort()
Clear out structures associated with main sort
-
setMatched
protected void setMatched(int index)
Set up block match deconfliction value matchHash. This is fed into the n-gram hashes for Instructions contained by this block to uniquely associate the n-grams with this block (and the matching block on the other side)- Parameters:
index
- is the 1-up index used to uniquely label this block
-
getMatchHash
public int getMatchHash()
- Returns:
- the main deconfliction hash feed
-
allUnknown
protected boolean allUnknown(int startindex, int length)
If the indicated n-gram, within this block, consists of unmatched instructions- Parameters:
startindex
- is the index of the first Instruction in the n-gramlength
- is the number of instructions in the n-gram- Returns:
- true if all Instructions in the n-gram are not matched, false otherwise.
-
hashGram
public int hashGram(int gramSize, InstructHash instHash, HashCalculator hashCalc) throws MemoryAccessException
Calculate an n-gram hash, given a particular hash function- Parameters:
gramSize
- is the size of the n-graminstHash
- is the first Instruction in the n-gramhashCalc
- is the hash function- Returns:
- the final 32-bit hash
- Throws:
MemoryAccessException
-
calcHashes
protected void calcHashes(int minLength, int maxLength, boolean wholeBlock, boolean matchOnly, HashCalculator hashCalc) throws MemoryAccessException
Calculate n-gram hashes used for matching (for Instructions in this basic-block). The exact hashes generated can be changed to get different looks at the data over multiple matching passes.- Parameters:
minLength
- is the minimum length of an n-gram to calculatemaxLength
- is the maximum length of an n-gramwholeBlock
- , true indicates a hash of the whole block should be calculated even if its size is below minLengthmatchOnly
- , true indicates hashes should only be calculated for previously matched, or small, blockshashCalc
- is the hash function for this matching pass- Throws:
MemoryAccessException
-
-