Package ghidra.program.model.block
Class SimpleBlockModel
- java.lang.Object
-
- ghidra.program.model.block.SimpleBlockModel
-
- All Implemented Interfaces:
CodeBlockModel
- Direct Known Subclasses:
BasicBlockModel
public class SimpleBlockModel extends java.lang.Object implements CodeBlockModel
This BlockModel implements the simple block model. Each Codeblock is made up of contiguous instructions in address order. Blocks satisfy the following:- Any instruction with a label starts a block.
- Each instruction that could cause program control flow to change is the last instruction of a Codeblock.
- All other instructions are "NOP" fallthroughs, meaning after execution the program counter will be at the instruction immediately following.
- Any instruction that is unreachable and has no label is also considered the start of a block.
- A delayed instruction is always corresponds to a change in flow and terminates a block. The delay slot instructions following this instruction are always included with the block. Therefor, delay slot instructions will always fall at the bottom of a simple block.
- The delay slot depth of the delayed instruction will always correspond to the number of delay slot instructions immediately following the instruction. The model may not behave properly if the disassembled code violates this assumption.
- See Also:
CodeBlockModel
-
-
Field Summary
Fields Modifier and Type Field Description protected static CodeBlock[]
emptyArray
protected static boolean
followIndirectFlows
protected AddressObjectMap
foundBlockMap
protected boolean
includeExternals
protected Listing
listing
static java.lang.String
NAME
protected Program
program
protected ReferenceManager
referenceMgr
-
Fields inherited from interface ghidra.program.model.block.CodeBlockModel
emptyBlockArray
-
-
Constructor Summary
Constructors Constructor Description SimpleBlockModel(Program program)
Construct a SimpleBlockModel on a program.SimpleBlockModel(Program program, boolean includeExternals)
Construct a SimpleBlockModel on a program.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
allowsBlockOverlap()
Return true if this model allows overlapping of address sets for the blocks it returns.protected CodeBlock
createSimpleDataBlock(Address start, Address end)
Create a new block over an address range with a single entry-point.boolean
externalsIncluded()
Returns true if externals are handled by the model, false if externals are ignored.CodeBlockModel
getBasicBlockModel()
Get the basic block model used by this model.CodeBlock
getCodeBlockAt(Address addr, TaskMonitor monitor)
Get the code/data block starting at this address.CodeBlockIterator
getCodeBlocks(TaskMonitor monitor)
Get an iterator over the code blocks in the entire program.CodeBlock[]
getCodeBlocksContaining(Address addr, TaskMonitor monitor)
Get all the Code Blocks containing the address.CodeBlockIterator
getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor)
Get an iterator over CodeBlocks which overlap the specified address set.CodeBlockReferenceIterator
getDestinations(CodeBlock block, TaskMonitor monitor)
Get an iterator over destination blocks flowing from this block.CodeBlock
getFirstCodeBlockContaining(Address addr, TaskMonitor monitor)
Get the First Code Block that contains the address.FlowType
getFlowType(CodeBlock block)
Return in general how things flow out of this node.protected Listing
getListing()
Returns the program listing associated with this model.java.lang.String
getName()
Returns the model name.java.lang.String
getName(CodeBlock block)
Get a name for this block.int
getNumDestinations(CodeBlock block, TaskMonitor monitor)
Deprecated.this method should be avoided since it repeats the work of the getDestinations iteratorint
getNumSources(CodeBlock block, TaskMonitor monitor)
Deprecated.this method should be avoided since it repeats the work of the getSources iteratorProgram
getProgram()
Returns the program object associated with this CodeBlockModel instance.CodeBlockReferenceIterator
getSources(CodeBlock block, TaskMonitor monitor)
Get an iterator over source blocks flowing into this block.protected boolean
hasEndOfBlockFlow(Instruction instr)
Examine an instruction for out-bound flows which qualify it as an end-of-block.protected boolean
isBlockStart(Address addr)
Check if the instruction at the address is the start of a basic block.boolean
isBlockStart(Instruction instruction)
Check if the instruction starts a Simple block.
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
emptyArray
protected static final CodeBlock[] emptyArray
-
program
protected Program program
-
listing
protected Listing listing
-
referenceMgr
protected ReferenceManager referenceMgr
-
foundBlockMap
protected AddressObjectMap foundBlockMap
-
includeExternals
protected final boolean includeExternals
-
followIndirectFlows
protected static final boolean followIndirectFlows
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SimpleBlockModel
public SimpleBlockModel(Program program)
Construct a SimpleBlockModel on a program. Externals will be excluded.- Parameters:
program
- program to create blocks from.
-
SimpleBlockModel
public SimpleBlockModel(Program program, boolean includeExternals)
Construct a SimpleBlockModel on a program.- Parameters:
program
- program to create blocks from.includeExternals
- externals will be included if true
-
-
Method Detail
-
getCodeBlockAt
public CodeBlock getCodeBlockAt(Address addr, TaskMonitor monitor) throws CancelledException
Get the code/data block starting at this address.- Specified by:
getCodeBlockAt
in interfaceCodeBlockModel
- Parameters:
addr
-monitor
- task monitor which allows user to cancel operation.- Returns:
- null if there is no codeblock starting at the address
- Throws:
CancelledException
- if the monitor cancels the operation.
-
hasEndOfBlockFlow
protected boolean hasEndOfBlockFlow(Instruction instr)
Examine an instruction for out-bound flows which qualify it as an end-of-block.- Parameters:
instr
-- Returns:
- true if end-of-block flow exists from specified instruction.
-
createSimpleDataBlock
protected CodeBlock createSimpleDataBlock(Address start, Address end)
Create a new block over an address range with a single entry-point.- Parameters:
start
- the first address which is also the only entry-point.end
- the last address.- Returns:
- CodeBlock
-
getCodeBlocksContaining
public CodeBlock[] getCodeBlocksContaining(Address addr, TaskMonitor monitor) throws CancelledException
Get all the Code Blocks containing the address.- Specified by:
getCodeBlocksContaining
in interfaceCodeBlockModel
- Parameters:
addr
- Address to find a containing block.monitor
- task monitor which allows user to cancel operation.- Returns:
- A SimpleBlock if any block contains the address empty array otherwise.
- Throws:
CancelledException
- if the monitor cancels the operation.
-
getFirstCodeBlockContaining
public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor) throws CancelledException
Get the First Code Block that contains the address.- Specified by:
getFirstCodeBlockContaining
in interfaceCodeBlockModel
- Parameters:
addr
- Address to find a containing block.monitor
- task monitor which allows user to cancel operation.- Returns:
- A SimpleBlock if any block contains the address. null otherwise.
- Throws:
CancelledException
- if the monitor cancels the operation.
-
getCodeBlocks
public CodeBlockIterator getCodeBlocks(TaskMonitor monitor) throws CancelledException
Get an iterator over the code blocks in the entire program.- Specified by:
getCodeBlocks
in interfaceCodeBlockModel
- Parameters:
monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getCodeBlocksContaining
public CodeBlockIterator getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor) throws CancelledException
Get an iterator over CodeBlocks which overlap the specified address set.- Specified by:
getCodeBlocksContaining
in interfaceCodeBlockModel
- Parameters:
addrSet
- an address set within programmonitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getProgram
public Program getProgram()
Description copied from interface:CodeBlockModel
Returns the program object associated with this CodeBlockModel instance.- Specified by:
getProgram
in interfaceCodeBlockModel
- Returns:
- program associated with this CodeBlockModel.
- See Also:
CodeBlockModel.getProgram()
-
getListing
protected Listing getListing()
Returns the program listing associated with this model.- Returns:
- the program listing associated with this model
-
isBlockStart
protected boolean isBlockStart(Address addr)
Check if the instruction at the address is the start of a basic block.- Parameters:
addr
- Address to check- Returns:
- true - if the address starts a basic block false - otherwise
-
isBlockStart
public boolean isBlockStart(Instruction instruction)
Check if the instruction starts a Simple block.- Parameters:
instruction
- instruction to test if it starts a block- Returns:
- true if this instruction is the start of a simple block.
-
getName
public java.lang.String getName(CodeBlock block)
Description copied from interface:CodeBlockModel
Get a name for this block.- Specified by:
getName
in interfaceCodeBlockModel
- Returns:
- usually the label at the start address of the block however the model can choose any name it wants for its blocks.
- See Also:
CodeBlockModel.getName(ghidra.program.model.block.CodeBlock)
-
getFlowType
public FlowType getFlowType(CodeBlock block)
Return in general how things flow out of this node. If there are any abnormal ways to flow out of this node, (ie: jump, call, etc...) then the flow type of the node takes on that type. If there are multiple unique ways out of the node, then we should return FlowType.UNKNOWN (or FlowType.MULTIFLOW ?). Fallthrough is returned if that is the only way out. If this block really has no valid instructions, it can't flow, so FlowType.INVALID is returned.- Specified by:
getFlowType
in interfaceCodeBlockModel
- Returns:
- flow type of this node
-
getSources
public CodeBlockReferenceIterator getSources(CodeBlock block, TaskMonitor monitor) throws CancelledException
Get an iterator over source blocks flowing into this block.- Specified by:
getSources
in interfaceCodeBlockModel
- Parameters:
block
- code block to get the source iterator for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getNumSources
@Deprecated public int getNumSources(CodeBlock block, TaskMonitor monitor) throws CancelledException
Deprecated.this method should be avoided since it repeats the work of the getSources iteratorGet number of source blocks flowing into this block- Specified by:
getNumSources
in interfaceCodeBlockModel
- Parameters:
block
- code block to get the source iterator for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getDestinations
public CodeBlockReferenceIterator getDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
Get an iterator over destination blocks flowing from this block.- Specified by:
getDestinations
in interfaceCodeBlockModel
- Parameters:
block
- code block to get the destination block iterator for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getNumDestinations
@Deprecated public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
Deprecated.this method should be avoided since it repeats the work of the getDestinations iteratorGet number of destination blocks flowing out of this block- Specified by:
getNumDestinations
in interfaceCodeBlockModel
- Parameters:
block
- code block to get the destination block iterator for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.
-
getBasicBlockModel
public CodeBlockModel getBasicBlockModel()
Description copied from interface:CodeBlockModel
Get the basic block model used by this model.- Specified by:
getBasicBlockModel
in interfaceCodeBlockModel
- See Also:
CodeBlockModel.getBasicBlockModel()
-
getName
public java.lang.String getName()
Description copied from interface:CodeBlockModel
Returns the model name.- Specified by:
getName
in interfaceCodeBlockModel
- Returns:
- the model name
- See Also:
CodeBlockModel.getName()
-
allowsBlockOverlap
public boolean allowsBlockOverlap()
Description copied from interface:CodeBlockModel
Return true if this model allows overlapping of address sets for the blocks it returns.- Specified by:
allowsBlockOverlap
in interfaceCodeBlockModel
- Returns:
- true if this model allows overlapping of address sets for the blocks it returns. This implies that getBlocksContaining() can return more than one block. false implies that getBlocksContaining() will return at most one block.
- See Also:
CodeBlockModel.allowsBlockOverlap()
-
externalsIncluded
public boolean externalsIncluded()
Description copied from interface:CodeBlockModel
Returns true if externals are handled by the model, false if externals are ignored. When handled, externals are represented by an ExtCodeBlockImpl.- Specified by:
externalsIncluded
in interfaceCodeBlockModel
-
-