Class InstructionBlock

java.lang.Object
ghidra.program.model.lang.InstructionBlock
All Implemented Interfaces:
Iterable<Instruction>

public class InstructionBlock extends Object implements Iterable<Instruction>
Represents a block of instructions. Used as part of an InstructionSet to be added to the program.
  • Constructor Details

    • InstructionBlock

      public InstructionBlock(Address startAddr)
  • Method Details

    • setStartOfFlow

      public void setStartOfFlow(boolean isStart)
      Allows the block to be tagged as start of flow to force InstructionSet iterator to treat as a flow start. This method should not be used after this block has been added to an InstructionSet
      Parameters:
      isStart -
    • isFlowStart

      public boolean isFlowStart()
      Returns:
      true if this block should be treated as the start of a new flow when added to a InstructionSet.
    • getStartAddress

      public Address getStartAddress()
      Returns the minimum/start address of the block;
      Returns:
      the minimum/start address of the block
    • getMaxAddress

      public Address getMaxAddress()
      Returns the maximum address of the block, or null if the block is empty;
      Returns:
      the maximum address of the block.
    • getInstructionAt

      public Instruction getInstructionAt(Address address)
      Returns the instruction at the specified address within this block
      Parameters:
      address -
      Returns:
      instruction at the specified address within this block or null if not found
    • findFirstIntersectingInstruction

      public Instruction findFirstIntersectingInstruction(Address min, Address max)
      Find the first instruction within this block which intersects the specified range. This method should be used sparingly since it uses a brute-force search.
      Parameters:
      min - the minimum intersection address
      max - the maximum intersection address
      Returns:
      instruction within this block which intersects the specified range or null if not found
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addInstruction

      public void addInstruction(Instruction instruction)
      Adds an instruction to this block. If the block in not empty, the newly added instruction must be directly after the current block maximum address. In other words, all instructions int the block must be consecutive.
      Parameters:
      instruction - the instruction to add to this block.
      Throws:
      IllegalArgumentException - if the new instruction does not immediately follow the last instruction added.
    • addBlockFlow

      public void addBlockFlow(InstructionBlockFlow blockFlow)
      Add a block flow specified by a InstructionBlockFlow object. These flows include all calls, branches and fall-throughs and may span across multiple InstructionSets and are not used by the block flow iterator within the associated InstructionSet.
      Parameters:
      blockFlow - block flow
    • addBranchFlow

      public void addBranchFlow(Address destinationAddress)
      Adds a branch type flow to this instruction block and is used by the block flow iterator of the associated InstructionSet.
      Parameters:
      destinationAddress - the destination of a branch type flow from this instruction block.
    • setFallThrough

      public void setFallThrough(Address fallthroughAddress)
      Sets the fall through address for this block and is used by the block flow iterator of the associated InstructionSet. The fallthrough should not be set if it is added as a block flow.
      Parameters:
      fallthroughAddress - the address of the fallthrough
    • getBranchFlows

      public List<Address> getBranchFlows()
      Returns a list of all the branch flows that were added to this instruction block and flow to other blocks within the associated InstructionSet.
      Returns:
      a list of all the branch flows that were added to this instruction block.
    • getBlockFlows

      public List<InstructionBlockFlow> getBlockFlows()
      Returns a list of all block flows that were added to this instruction block as a list of InstructionBlockFlow objects. NOTE: These flows may not be contained within the associated InstructionSet.
      Returns:
      a list of all flows that were added to this instruction block.
    • getFallThrough

      public Address getFallThrough()
      Returns the fallthrough address. Null is returned if there is no fall through.
      Returns:
      the fallthrough address.
    • setInstructionError

      public void setInstructionError(InstructionError.InstructionErrorType type, Address intendedInstructionAddress, Address conflictAddress, Address flowFromAddress, String message)
      Sets this block to have an instruction error.
      Parameters:
      type - The type of error/conflict.
      intendedInstructionAddress - address of intended instruction which failed to be created
      conflictAddress - the address of the exiting code unit that is preventing the instruction in this block to be laid down (required for CODE_UNIT or DUPLCIATE conflict error).
      flowFromAddress - the flow-from instruction address or null if unknown
      message - - A message that describes the conflict to a user.
    • setInstructionMemoryError

      public void setInstructionMemoryError(Address instrAddr, Address flowFromAddr, String errorMsg)
      Set instruction memory error
      Parameters:
      instrAddr - instruction address
      flowFromAddr - flow-from address
      errorMsg -
    • setInconsistentPrototypeConflict

      public void setInconsistentPrototypeConflict(Address instrAddr, Address flowFromAddr)
      Set inconsistent instruction prototype CODE_UNIT conflict
      Parameters:
      instrAddr - instruction addr where inconsistent prototype exists
      flowFromAddr - flow-from address
    • setCodeUnitConflict

      public void setCodeUnitConflict(Address codeUnitAddr, Address newInstrAddr, Address flowFromAddr, boolean isInstruction, boolean isOffcut)
      Set offcut-instruction or data CODE_UNIT conflict
      Parameters:
      codeUnitAddr - existing instruction/data address
      newInstrAddr - new disassembled instruction address
      flowFromAddr - flow-from address
      isInstruction - true if conflict is due to offcut-instruction, otherwise data is assumed
      isOffcut - true if conflict due to offcut instruction
    • setParseConflict

      public void setParseConflict(Address conflictAddress, RegisterValue contextValue, Address flowFromAddress, String message)
      Sets this block to have a PARSE conflict which means that the instruction parse failed at the specified conflictAddress using the specified contextValue.
      Parameters:
      conflictAddress - the address of the exiting code unit that is preventing the instruction in this block to be laid down.
      contextValue - the context-register value used during the failed parse attempt
      flowFromAddress - the flow-from instruction address or null
      message - - A message that describes the conflict to a user.
    • clearConflict

      public void clearConflict()
      Clears any conflict associated with this block.
    • getInstructionConflict

      public InstructionError getInstructionConflict()
      Returns the current conflict associated with this block.
      Returns:
      the current conflict associated with this block.
    • iterator

      public Iterator<Instruction> iterator()
      Returns an iterator over all the instructions in this block.
      Specified by:
      iterator in interface Iterable<Instruction>
    • getLastInstructionAddress

      public Address getLastInstructionAddress()
      Returns:
      address of last instruction contained within this block
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if no instructions exist within this block
    • getInstructionCount

      public int getInstructionCount()
      Returns:
      number of instructions contained within this block
    • getInstructionsAddedCount

      public int getInstructionsAddedCount()
      Returns:
      number of instructions which were added to the program successfully.
    • setInstructionsAddedCount

      public void setInstructionsAddedCount(int count)
      Set the number of instructions which were added to the program
      Parameters:
      count -
    • getFlowFromAddress

      public Address getFlowFromAddress()
    • setFlowFromAddress

      public void setFlowFromAddress(Address flowFrom)
    • hasInstructionError

      public boolean hasInstructionError()