public class

BasicBlock

extends Object
implements IBasicBlock<InsnType extends IInstruction> Comparable<T>
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.asm.cfg.BasicBlock<InsnType extends com.pnfsoftware.jeb.core.units.code.IInstruction>

Class Overview

This class represents a basic block of generic instructions.

See Also

Summary

Public Constructors
BasicBlock(long base)
Create a new empty basic block.
BasicBlock(long base, List<InsnType> insns, List<Long> dstOffsets, List<Long> irrdstOffsets, boolean unknownDst)
Create a new basic block.
Public Methods
void add(int index, InsnType insn)
DANGEROUS METHOD.
void add(InsnType insn)
DANGEROUS METHOD.
void addAll(Collection<InsnType> coll)
DANGEROUS METHOD.
void addAll(int index, Collection<InsnType> coll)
DANGEROUS METHOD.
Iterable<AddressableInstruction<InsnType>> addressableInstructions()
int allinsize()
Get the total number of input edges to this block.
int alloutsize()
boolean canThrow()
int compareTo(BasicBlock<InsnType> o)
InsnType get(int index)
Get the instruction at the specified index.
AddressableInstruction<InsnType> get2(int index)
Get the instruction at the specified index, in an addressable form.
long getAddressOfInstruction(int index)
long[] getAddresses()
Get a list of the addresses of each instruction in the block.
List<BasicBlock<InsnType>> getAllInputBlocks()
Iterable<BasicBlock<InsnType>> getAllInputs()
Retrieve a read-only iterable of regular and irregular input blocks.
List<BasicBlock<InsnType>> getAllOutputBlocks()
Get regular and irregular output blocks.
Iterable<BasicBlock<InsnType>> getAllOutputs()
Retrieve a read-only iterable of regular and irregular output blocks.
long getBase()
Address of first instruction in the block.
AddressableInstruction<InsnType> getBranchingInstruction2(boolean includeBreaking, boolean includeCalling)
Retrieve the branching instruction, if any.
AddressableInstruction<InsnType> getBranchingInstruction2()
Object getData(String name)
May return null if the custom object does not exist.
long getEndAddress()
Address following the last instruction of the block (ie, last exclusive address).
long getFirstAddress()
Address of first instruction in the block.
int getIndexOfInstruction(InsnType insn)
Locate an instruction in the block.
int getIndexOfInstruction(long address)
BasicBlock<InsnType> getInputBlock(int index)
Get a regular input block.
List<BasicBlock<InsnType>> getInputBlocks()
Get the regular input blocks.
List<Long> getInputOffsets()
List<BasicBlock<InsnType>> getInputs()
Retrieve a read-only list of input blocks (regular).
InsnType getInstruction(long address)
Get the instruction located at the exact address.
List<InsnType> getInstructions()
Get a copy of the list of instructions that make up this basic block.
BasicBlock<InsnType> getIrregularInputBlock(int index)
Get an irregular input block.
List<BasicBlock<InsnType>> getIrregularInputBlocks()
List<Long> getIrregularInputOffsets()
List<BasicBlock<InsnType>> getIrregularInputs()
Retrieve a read-only list of irregular input blocks.
BasicBlock<InsnType> getIrregularOutputBlock(int index)
Get an irregular output block.
List<BasicBlock<InsnType>> getIrregularOutputBlocks()
Get irregular output blocks.
List<Long> getIrregularOutputOffsets()
List<BasicBlock<InsnType>> getIrregularOutputs()
Retrieve a read-only list of irregular output blocks.
InsnType getLast()
Get the last instruction of the block.
AddressableInstruction<InsnType> getLast2()
Get the last instruction of the block, in an addressable form.
long getLastAddress()
Address of last instruction in the block.
BasicBlock<InsnType> getOutputBlock(int index)
Get a regular output block.
List<BasicBlock<InsnType>> getOutputBlocks()
Get the regular output blocks.
List<Long> getOutputOffsets()
List<BasicBlock<InsnType>> getOutputs()
Retrieve a read-only list of output blocks (regular).
int getSizeOfInstructions()
boolean hasUnknownDst()
int insize()
Get the number of regular input edges to this block.
int irrinsize()
Get the number of irregular input edges to this block.
int irroutsize()
boolean isEmpty()
Determine if the block has 0 instruction.
boolean isInfiniteLoop()
Check if the block has a single regular out-edge which points to itself.
boolean isSelfReferencing()
Check if the block has at least one regular out-edge pointing to itself.
Iterator<InsnType> iterator()
int outsize()
boolean remove(int index)
Remove an instruction from the block as well as associated chains.
boolean removeData(String name)
InsnType set(int index, InsnType insn)
DANGEROUS METHOD.
void setData(String name, Object object)
Custom data is reset when a DFA is invalidated.
InsnType setLast(InsnType insn)
void setUnknownDst(boolean unknownDst)
BasicBlock<InsnType> shallowCopy(boolean copyBlockReferences)
Shallow duplication of a basic block.
int size()
Get the number of instructions in the block.
String toString()
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pnfsoftware.jeb.core.units.code.IBasicBlock
From interface java.lang.Comparable
From interface java.lang.Iterable

Public Constructors

public BasicBlock (long base)

Create a new empty basic block.

public BasicBlock (long base, List<InsnType> insns, List<Long> dstOffsets, List<Long> irrdstOffsets, boolean unknownDst)

Create a new basic block.

Public Methods

public void add (int index, InsnType insn)

DANGEROUS METHOD. Add an instruction into the block.

public void add (InsnType insn)

DANGEROUS METHOD. Append an instruction to the block.

The instruction is appended to the block. The edges are not updated.
The caller is responsible for verifying the instruction (no null, no dup., etc.).
The caller is responsible for maintaining the consistency of the block and of the CFG.

Parameters
insn the instruction to be appended

public void addAll (Collection<InsnType> coll)

DANGEROUS METHOD. Append instructions to the block.

The instructions are appended to the block. The edges are not updated.
The caller is responsible for verifying the instructions (no null, no dup., etc.).
The caller is responsible for maintaining the consistency of the block and of the CFG.

public void addAll (int index, Collection<InsnType> coll)

DANGEROUS METHOD. Add instructions into the block.

public Iterable<AddressableInstruction<InsnType>> addressableInstructions ()

public int allinsize ()

Get the total number of input edges to this block.

public int alloutsize ()

public boolean canThrow ()

public int compareTo (BasicBlock<InsnType> o)

public InsnType get (int index)

Get the instruction at the specified index.

public AddressableInstruction<InsnType> get2 (int index)

Get the instruction at the specified index, in an addressable form.

public long getAddressOfInstruction (int index)

public long[] getAddresses ()

Get a list of the addresses of each instruction in the block.

public List<BasicBlock<InsnType>> getAllInputBlocks ()

public Iterable<BasicBlock<InsnType>> getAllInputs ()

Retrieve a read-only iterable of regular and irregular input blocks.

NOTE: This method is faster than getAllInputBlocks() since it does not provide a copy of the list.

public List<BasicBlock<InsnType>> getAllOutputBlocks ()

Get regular and irregular output blocks.

Returns
  • a copy of the list of all output blocks

public Iterable<BasicBlock<InsnType>> getAllOutputs ()

Retrieve a read-only iterable of regular and irregular output blocks.

NOTE: This method is faster than getAllOutputBlocks() since it does not provide a copy of the list.

public long getBase ()

Address of first instruction in the block.

public AddressableInstruction<InsnType> getBranchingInstruction2 (boolean includeBreaking, boolean includeCalling)

Retrieve the branching instruction, if any. In the general case, it should not be assumed that the branching instruction must be the last instruction of a block. Example: on delay-slot architectures, a number of instructions may follow the branching instructions. They are included in the block. That means that the branching instruction, when there is one, may be the one/two/Nth-before-last.

Returns
  • the branching instruction+address, or null if none

public AddressableInstruction<InsnType> getBranchingInstruction2 ()

public Object getData (String name)

May return null if the custom object does not exist.

public long getEndAddress ()

Address following the last instruction of the block (ie, last exclusive address).

public long getFirstAddress ()

Address of first instruction in the block.

public int getIndexOfInstruction (InsnType insn)

Locate an instruction in the block. Comparison is done by identity.

Returns
  • the instruction index, -1 if not found

public int getIndexOfInstruction (long address)

public BasicBlock<InsnType> getInputBlock (int index)

Get a regular input block.

Parameters
index block index
Returns
  • a block

public List<BasicBlock<InsnType>> getInputBlocks ()

Get the regular input blocks.

Returns
  • a copy of the list of regular input blocks

public List<Long> getInputOffsets ()

public List<BasicBlock<InsnType>> getInputs ()

Retrieve a read-only list of input blocks (regular).

NOTE: This method is faster than getInputBlocks() since it does not provide a copy of the list.

public InsnType getInstruction (long address)

Get the instruction located at the exact address.

public List<InsnType> getInstructions ()

Get a copy of the list of instructions that make up this basic block.

public BasicBlock<InsnType> getIrregularInputBlock (int index)

Get an irregular input block.

Parameters
index block index
Returns
  • a block

public List<BasicBlock<InsnType>> getIrregularInputBlocks ()

public List<Long> getIrregularInputOffsets ()

public List<BasicBlock<InsnType>> getIrregularInputs ()

Retrieve a read-only list of irregular input blocks.

NOTE: This method is faster than getIrregularInputBlocks() since it does not provide a copy of the list.

public BasicBlock<InsnType> getIrregularOutputBlock (int index)

Get an irregular output block.

public List<BasicBlock<InsnType>> getIrregularOutputBlocks ()

Get irregular output blocks.

Returns
  • a copy of the list of irregular output blocks

public List<Long> getIrregularOutputOffsets ()

public List<BasicBlock<InsnType>> getIrregularOutputs ()

Retrieve a read-only list of irregular output blocks.

NOTE: This method is faster than getIrregularOutputBlocks() since it does not provide a copy of the list.

public InsnType getLast ()

Get the last instruction of the block.

Keep in mind that a branching instruction may NOT be the last instruction of a basic block if it supports delay-slots.

public AddressableInstruction<InsnType> getLast2 ()

Get the last instruction of the block, in an addressable form.

Keep in mind that a branching instruction may NOT be the last instruction of a basic block if it supports delay-slots.

public long getLastAddress ()

Address of last instruction in the block.

public BasicBlock<InsnType> getOutputBlock (int index)

Get a regular output block.

public List<BasicBlock<InsnType>> getOutputBlocks ()

Get the regular output blocks.

Returns
  • a copy of the list of regular output blocks

public List<Long> getOutputOffsets ()

public List<BasicBlock<InsnType>> getOutputs ()

Retrieve a read-only list of output blocks (regular).

NOTE: This method is faster than getOutputBlocks() since it does not provide a copy of the list.

public int getSizeOfInstructions ()

public boolean hasUnknownDst ()

public int insize ()

Get the number of regular input edges to this block.

public int irrinsize ()

Get the number of irregular input edges to this block.

public int irroutsize ()

public boolean isEmpty ()

Determine if the block has 0 instruction.

public boolean isInfiniteLoop ()

Check if the block has a single regular out-edge which points to itself.

public boolean isSelfReferencing ()

Check if the block has at least one regular out-edge pointing to itself.

public Iterator<InsnType> iterator ()

public int outsize ()

public boolean remove (int index)

Remove an instruction from the block as well as associated chains. Usage is not recommended for public clients.

This method may have the nasty side-effect of making the block empty. In that case, it returns true, and it is the caller's responsibility to refresh the CFG at their earliest convenience.

Another issue the client needs to take care of is the removal of the last instruction, which should only happen on very specific conditions, since the trailing instruction typically conditions the out-edges of the block.

Returns
  • true if the CFG need refreshing

public boolean removeData (String name)

public InsnType set (int index, InsnType insn)

DANGEROUS METHOD. Replace an instruction. Sizes must match.

Edges are not updated.
The caller is responsible for maintaining the consistency of the block and of the CFG.

Parameters
insn the instruction
Returns
  • the instruction that was replaced

public void setData (String name, Object object)

Custom data is reset when a DFA is invalidated.

public InsnType setLast (InsnType insn)

public void setUnknownDst (boolean unknownDst)

public BasicBlock<InsnType> shallowCopy (boolean copyBlockReferences)

Shallow duplication of a basic block. USE THE RESULTING BLOCK WITH CAUTION. - Instructions references are copied
- Block references (edges) are optionally copied (the blocks are not)
- DFA data is not copied

Returns
  • a new block

public int size ()

Get the number of instructions in the block.

public String toString ()