Class 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:
    1. Any instruction with a label starts a block.
    2. Each instruction that could cause program control flow to change is the last instruction of a Codeblock.
    3. All other instructions are "NOP" fallthroughs, meaning after execution the program counter will be at the instruction immediately following.
    4. Any instruction that is unreachable and has no label is also considered the start of a block.
    So a CodeBlock in this model consists of contiguous code that has zero or more nonflow fallthrough instructions followed by a single flow instruction. Each block may or may not have a label at the first instruction, but may not have a label at any other instruction contained in the 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:
    1. 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.
    2. 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
    • 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

      • 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 interface CodeBlockModel
        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 interface CodeBlockModel
        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.
      • 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.
      • 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 interface CodeBlockModel
        Returns:
        flow type of this node
      • 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 iterator
        Get number of source blocks flowing into this block
        Specified by:
        getNumSources in interface CodeBlockModel
        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.
      • 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 iterator
        Get number of destination blocks flowing out of this block
        Specified by:
        getNumDestinations in interface CodeBlockModel
        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.
      • 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 interface CodeBlockModel
        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 interface CodeBlockModel