public class

BasicBlock

extends Object
implements IBasicBlock<InsnType extends IInstruction> Iterable<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(InsnType insn)
DANGEROUS! Append an instruction to the block.
Iterable<AddressableInstruction<InsnType>> addressableInstructions()
int allinsize()
Get the total number of input edges to this block.
int alloutsize()
boolean canThrow()
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)
List<BasicBlock<InsnType>> getAllInputBlocks()
List<BasicBlock<InsnType>> getAllOutputBlocks()
Get regular and irregular output blocks.
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.
Map<Integer, Set<Long>> getFullDefUseChains(int index)
Map<Integer, Set<Long>> getFullUseDefChains(int index)
int getIndexOfInstruction(long address)
BasicBlock<InsnType> getInputBlock(int index)
Get a regular input block.
List<BasicBlock<InsnType>> getInputBlocks()
Get the regular input blocks.
InsnType getInstruction(int index)
InsnType getInstruction(long 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()
BasicBlock<InsnType> getIrregularOutputBlock(int index)
Get an irregular output block.
List<BasicBlock<InsnType>> getIrregularOutputBlocks()
Get 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.
Map<Integer, Set<Integer>> getSimpleDefUseChains(int index)
Map<Integer, Set<Integer>> getSimpleUseDefChains(int index)
Tracker<InsnType> getTrackerLiveRegisters()
Tracker<InsnType> getTrackerReachingRegisters()
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)
Replace an instruction.
void setData(String name, Object object)
Custom data is reset when a DFA is invalidated.
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.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 (InsnType insn)

DANGEROUS! Append an instruction to the block.

The instruction is appended to the block. The edges are not updated.
The caller is solely responsible for maintaining the consistency of the block and of the CFG.

Parameters
insn the instruction to be appended

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 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 List<BasicBlock<InsnType>> getAllInputBlocks ()

public List<BasicBlock<InsnType>> getAllOutputBlocks ()

Get regular and irregular output blocks.

Returns
  • a copy of the list of all output blocks

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

Retrieve the branching instruction, if any.

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 Map<Integer, Set<Long>> getFullDefUseChains (int index)

public Map<Integer, Set<Long>> getFullUseDefChains (int index)

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 InsnType getInstruction (int index)

public InsnType getInstruction (long 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 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 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 Map<Integer, Set<Integer>> getSimpleDefUseChains (int index)

public Map<Integer, Set<Integer>> getSimpleUseDefChains (int index)

public Tracker<InsnType> getTrackerLiveRegisters ()

public Tracker<InsnType> getTrackerReachingRegisters ()

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)

Replace an instruction. Sizes must match.

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 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 ()