Package ghidra.program.model.block
Class OverlapCodeSubModel
- java.lang.Object
-
- ghidra.program.model.block.OverlapCodeSubModel
-
- All Implemented Interfaces:
CodeBlockModel
,SubroutineBlockModel
- Direct Known Subclasses:
IsolatedEntrySubModel
public class OverlapCodeSubModel extends java.lang.Object implements SubroutineBlockModel
OverlapCodeSubModel
(O-model) defines subroutines with a unique entry point, which may share code with other subroutines. Each entry- point may either be a source or called entry-point and is identified using the MultEntSubModel. This model defines the set of addresses contained within each subroutine based upon the possible flows from its entry- point. Flows which encounter another entry-point are terminated.NOTE: This differs from the original definition of an entry point, however, the intent of the O-Model is preserved.
- See Also:
CodeBlockModel
,MultEntSubModel
-
-
Field Summary
Fields Modifier and Type Field Description protected ghidra.program.model.block.CodeBlockCache
foundOSubs
protected Listing
listing
protected MultEntSubModel
modelM
static java.lang.String
OVERLAP_MODEL_NAME
protected Program
program
-
Fields inherited from interface ghidra.program.model.block.CodeBlockModel
emptyBlockArray
-
-
Constructor Summary
Constructors Constructor Description OverlapCodeSubModel(Program program)
Construct aOverlapCodeSubModel
subroutine on a program.OverlapCodeSubModel(Program program, boolean includeExternals)
Construct aOverlapCodeSubModel
subroutine on a program.
-
Method Summary
All Methods Instance Methods Concrete 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
createSub(AddressSetView addrSet, Address entryPt)
Create a new Subroutine which has specified address set and entry point.boolean
externalsIncluded()
Returns true if externals are handled by the model, false if externals are ignored.SubroutineBlockModel
getBaseSubroutineModel()
Get the underlying base subroutine model.CodeBlockModel
getBasicBlockModel()
Get the basic block model used by this model.CodeBlock
getCodeBlockAt(Address addr, TaskMonitor monitor)
Get the code block with a starting address (i.e., entry-point) of addr.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 code blocks which overlap the specified address set.CodeBlockReferenceIterator
getDestinations(CodeBlock block, TaskMonitor monitor)
Get an iterator over the destination flows out of the block.CodeBlock
getFirstCodeBlockContaining(Address addr, TaskMonitor monitor)
Get the first code block that contains the given address.FlowType
getFlowType(CodeBlock block)
Return in general how things flow out of this node.Listing
getListing()
Returns the listing associated with this block model.protected MultEntSubModel
getModelM()
Returns the Multiple Entry Block Model used by 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)
Get the number of destination flows out of the block.int
getNumSources(CodeBlock block, TaskMonitor monitor)
Get the number of source flows into the block.Program
getProgram()
Returns the program object associated with this CodeBlockModel instance.CodeBlockReferenceIterator
getSources(CodeBlock block, TaskMonitor monitor)
Get an iterator over the source flows into the block.protected CodeBlock
getSubroutine(Address mStartAddr, TaskMonitor monitor)
Get the subroutine code block which starts at the specified address which is an entry point of a Model-M subroutine.
-
-
-
Field Detail
-
OVERLAP_MODEL_NAME
public static final java.lang.String OVERLAP_MODEL_NAME
- See Also:
- Constant Field Values
-
program
protected Program program
-
listing
protected Listing listing
-
foundOSubs
protected ghidra.program.model.block.CodeBlockCache foundOSubs
-
modelM
protected MultEntSubModel modelM
-
-
Constructor Detail
-
OverlapCodeSubModel
public OverlapCodeSubModel(Program program)
Construct aOverlapCodeSubModel
subroutine on a program.- Parameters:
program
- program to create blocks from.
-
OverlapCodeSubModel
public OverlapCodeSubModel(Program program, boolean includeExternals)
Construct aOverlapCodeSubModel
subroutine on a program.- Parameters:
program
- program to create blocks from.includeExternals
- external blocks will be included if true
-
-
Method Detail
-
getSubroutine
protected CodeBlock getSubroutine(Address mStartAddr, TaskMonitor monitor) throws CancelledException
Get the subroutine code block which starts at the specified address which is an entry point of a Model-M subroutine. Classes which extend this class should implement this method.- Parameters:
mStartAddr
- = a Model-M subroutine entry point.monitor
- task monitor which allows user to cancel operation.- Returns:
- a subroutine code block or null if not found.
- Throws:
CancelledException
- if the monitor cancels the operation.
-
getCodeBlockAt
public CodeBlock getCodeBlockAt(Address addr, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get the code block with a starting address (i.e., entry-point) of addr.- Specified by:
getCodeBlockAt
in interfaceCodeBlockModel
- Parameters:
addr
- starting address of a codeblock.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.- See Also:
CodeBlockModel.getCodeBlockAt(ghidra.program.model.address.Address, ghidra.util.task.TaskMonitor)
-
getCodeBlocksContaining
public CodeBlock[] getCodeBlocksContaining(Address addr, TaskMonitor monitor) throws CancelledException
Get all the Code Blocks containing the address. Model-O is the only of the MOP models that allows for there to be more than one- Specified by:
getCodeBlocksContaining
in interfaceCodeBlockModel
- Parameters:
addr
- Address to find a containing block.monitor
- task monitor which allows user to cancel operation.- Returns:
- A CodeBlock array with one entry containing the subroutine that contains the address empty array otherwise.
- Throws:
CancelledException
- if the monitor cancels the operation.
-
getFirstCodeBlockContaining
public CodeBlock getFirstCodeBlockContaining(Address addr, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get the first code block that contains the given 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 block that contains the address, or null otherwise.
- Throws:
CancelledException
- if the monitor cancels the operation.- See Also:
CodeBlockModel.getFirstCodeBlockContaining(ghidra.program.model.address.Address, ghidra.util.task.TaskMonitor)
-
getCodeBlocks
public CodeBlockIterator getCodeBlocks(TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
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.- See Also:
CodeBlockModel.getCodeBlocks(ghidra.util.task.TaskMonitor)
-
getCodeBlocksContaining
public CodeBlockIterator getCodeBlocksContaining(AddressSetView addrSet, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get an iterator over code blocks 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.- See Also:
CodeBlockModel.getCodeBlocksContaining(ghidra.program.model.address.AddressSetView, ghidra.util.task.TaskMonitor)
-
getModelM
protected MultEntSubModel getModelM()
Returns the Multiple Entry Block Model used by this model.- Returns:
- the Multiple Entry Block Model used by this model
-
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
public Listing getListing()
Returns the listing associated with this block model.- Returns:
- the listing associated with this block model
-
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. This method exists for the SIMPLEBLOCK model.Since it doesn't make a great deal of sense to ask for this method in the case of subroutines, we return FlowType.UNKNOWN as long as the block exists.
If this block 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
Description copied from interface:CodeBlockModel
Get an iterator over the source flows into the block.- Specified by:
getSources
in interfaceCodeBlockModel
- Parameters:
block
- the block to get the destination flows for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.- See Also:
CodeBlockModel.getSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)
-
getNumSources
public int getNumSources(CodeBlock block, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get the number of source flows into the block.- Specified by:
getNumSources
in interfaceCodeBlockModel
- Parameters:
block
- the code blocks to get the destination flows for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.- See Also:
CodeBlockModel.getNumSources(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)
-
getDestinations
public CodeBlockReferenceIterator getDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get an iterator over the destination flows out of the block.- Specified by:
getDestinations
in interfaceCodeBlockModel
- Parameters:
block
- the block to get the destination flows for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.- See Also:
CodeBlockModel.getDestinations(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)
-
getNumDestinations
public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException
Description copied from interface:CodeBlockModel
Get the number of destination flows out of the block.- Specified by:
getNumDestinations
in interfaceCodeBlockModel
- Parameters:
block
- the code blocks to get the destination flows for.monitor
- task monitor which allows user to cancel operation.- Throws:
CancelledException
- if the monitor cancels the operation.- See Also:
CodeBlockModel.getNumDestinations(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)
-
createSub
protected CodeBlock createSub(AddressSetView addrSet, Address entryPt)
Create a new Subroutine which has specified address set and entry point. Cache the model-O subroutine.- Parameters:
addrSet
- contains the address set of the model-O subroutineentryPt
- the OSub entry point.- Returns:
- subroutine block that was created
-
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()
-
getBaseSubroutineModel
public SubroutineBlockModel getBaseSubroutineModel()
Description copied from interface:SubroutineBlockModel
Get the underlying base subroutine model. This is generally the MultEntSubModel (M-Model).- Specified by:
getBaseSubroutineModel
in interfaceSubroutineBlockModel
- Returns:
- base subroutine model. If there is no base model, this subroutine model is returned.
- See Also:
SubroutineBlockModel.getBaseSubroutineModel()
-
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
-
-