Package ghidra.program.model.lang
Class InstructionBlock
java.lang.Object
ghidra.program.model.lang.InstructionBlock
- All Implemented Interfaces:
Iterable<Instruction>
Represents a block of instructions. Used as part of an InstructionSet to be added to the
program.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBlockFlow
(InstructionBlockFlow blockFlow) Add a block flow specified by a InstructionBlockFlow object.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.void
addInstruction
(Instruction instruction) Adds an instruction to this block.void
Clears any conflict associated with this block.findFirstIntersectingInstruction
(Address min, Address max) Find the first instruction within this block which intersects the specified range.Returns a list of all block flows that were added to this instruction block as a list of InstructionBlockFlow objects.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 the fallthrough address.getInstructionAt
(Address address) Returns the instruction at the specified address within this blockReturns the current conflict associated with this block.int
int
Returns the maximum address of the block, or null if the block is empty;Returns the minimum/start address of the block;boolean
boolean
isEmpty()
boolean
iterator()
Returns an iterator over all the instructions in this block.void
setCodeUnitConflict
(Address codeUnitAddr, Address newInstrAddr, Address flowFromAddr, boolean isInstruction, boolean isOffcut) Set offcut-instruction or data CODE_UNIT conflictvoid
setFallThrough
(Address fallthroughAddress) Sets the fall through address for this block and is used by the block flow iterator of the associated InstructionSet.void
setFlowFromAddress
(Address flowFrom) void
setInconsistentPrototypeConflict
(Address instrAddr, Address flowFromAddr) Set inconsistent instruction prototype CODE_UNIT conflictvoid
setInstructionError
(InstructionError.InstructionErrorType type, Address intendedInstructionAddress, Address conflictAddress, Address flowFromAddress, String message) Sets this block to have an instruction error.void
setInstructionMemoryError
(Address instrAddr, Address flowFromAddr, String errorMsg) Set instruction memory errorvoid
setInstructionsAddedCount
(int count) Set the number of instructions which were added to the programvoid
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.void
setStartOfFlow
(boolean isStart) Allows the block to be tagged as start of flow to force InstructionSet iterator to treat as a flow start.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
InstructionBlock
-
-
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
Returns the minimum/start address of the block;- Returns:
- the minimum/start address of the block
-
getMaxAddress
Returns the maximum address of the block, or null if the block is empty;- Returns:
- the maximum address of the block.
-
getInstructionAt
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
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 addressmax
- the maximum intersection address- Returns:
- instruction within this block which intersects the specified range or null if not found
-
toString
-
addInstruction
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
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
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
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
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
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
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 createdconflictAddress
- 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 unknownmessage
- - A message that describes the conflict to a user.
-
setInstructionMemoryError
Set instruction memory error- Parameters:
instrAddr
- instruction addressflowFromAddr
- flow-from addresserrorMsg
-
-
setInconsistentPrototypeConflict
Set inconsistent instruction prototype CODE_UNIT conflict- Parameters:
instrAddr
- instruction addr where inconsistent prototype existsflowFromAddr
- 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 addressnewInstrAddr
- new disassembled instruction addressflowFromAddr
- flow-from addressisInstruction
- true if conflict is due to offcut-instruction, otherwise data is assumedisOffcut
- 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 attemptflowFromAddress
- the flow-from instruction address or nullmessage
- - A message that describes the conflict to a user.
-
clearConflict
public void clearConflict()Clears any conflict associated with this block. -
getInstructionConflict
Returns the current conflict associated with this block.- Returns:
- the current conflict associated with this block.
-
iterator
Returns an iterator over all the instructions in this block.- Specified by:
iterator
in interfaceIterable<Instruction>
-
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
-
setFlowFromAddress
-
hasInstructionError
public boolean hasInstructionError()
-