Package ghidra.program.model.block
Class SimpleBlockModel
java.lang.Object
ghidra.program.model.block.SimpleBlockModel
- All Implemented Interfaces:
CodeBlockModel
- Direct Known Subclasses:
BasicBlockModel
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.
This model does not implement the pure simple block model because unreachable code is still considered a block.
This model handles delay slot instructions with the following assumptions:
- 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. Therefore, 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:
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final CodeBlock[]
protected static final boolean
protected AddressObjectMap
protected final boolean
protected Listing
static final String
protected Program
protected ReferenceManager
Fields inherited from interface ghidra.program.model.block.CodeBlockModel
emptyBlockArray
-
Constructor Summary
ConstructorDescriptionSimpleBlockModel
(Program program) Construct a SimpleBlockModel on a program.SimpleBlockModel
(Program program, boolean includeExternals) Construct a SimpleBlockModel on a program. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
Returns true if externals are handled by the model, false if externals are ignored.Get the basic block model used by this model.getCodeBlockAt
(Address addr, TaskMonitor monitor) Get the code/data block starting at this address.getCodeBlocks
(TaskMonitor monitor) Get an iterator over the code blocks in the entire program.getCodeBlocksContaining
(Address addr, TaskMonitor monitor) Get all the Code Blocks containing the address.getCodeBlocksContaining
(AddressSetView addrSet, TaskMonitor monitor) Get an iterator over CodeBlocks which overlap the specified address set.getDestinations
(CodeBlock block, TaskMonitor monitor) Get an iterator over destination blocks flowing from this block.getFirstCodeBlockContaining
(Address addr, TaskMonitor monitor) Get the First Code Block that contains the address.getFlowType
(CodeBlock block) Return in general how things flow out of this node.protected Listing
Returns the program listing associated with this model.getName()
Returns the model name.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 iteratorReturns the program object associated with this CodeBlockModel instance.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 Details
-
NAME
- See Also:
-
emptyArray
-
program
-
listing
-
referenceMgr
-
foundBlockMap
-
includeExternals
protected final boolean includeExternals -
followIndirectFlows
protected static final boolean followIndirectFlows- See Also:
-
-
Constructor Details
-
SimpleBlockModel
Construct a SimpleBlockModel on a program. Externals will be excluded.- Parameters:
program
- program to create blocks from.
-
SimpleBlockModel
Construct a SimpleBlockModel on a program.- Parameters:
program
- program to create blocks from.includeExternals
- externals will be included if true
-
-
Method Details
-
getCodeBlockAt
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
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
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
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
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:
-
getListing
Returns the program listing associated with this model.- Returns:
- the program listing associated with this model
-
isBlockStart
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
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
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:
-
getFlowType
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
Description copied from interface:CodeBlockModel
Get the basic block model used by this model.- Specified by:
getBasicBlockModel
in interfaceCodeBlockModel
- See Also:
-
getName
Description copied from interface:CodeBlockModel
Returns the model name.- Specified by:
getName
in interfaceCodeBlockModel
- Returns:
- the model name
- See Also:
-
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:
-
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
-