public class

CFGUtil

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.units.code.asm.cfg.CFGUtil

Class Overview

Static utility routines for control flow graphs.

Summary

Public Constructors
CFGUtil()
Public Methods
static <T extends IInstruction> boolean compare(CFG<T> cfg1, CFG<T> cfg2)
Basic CFG comparison.
static <T extends IInstruction> boolean compare(int failmode, Comparator<T> comparator, CFG<T> cfg1, CFG<T> cfg2)
Basic CFG comparison.
static <T extends IInstruction> CFG<T> duplicateShallow(CFG<T> cfg)
Shallow duplication of a CFG.
static <T extends IInstruction> Collection<BasicBlock<T>> getReachableBlocks(CFG<T> cfg)
Collect the list of all blocks reachable from the entry point.
static <T extends IInstruction> int removeUnreachableBlocks(CFG<T> cfg)
Remove all blocks not reachable from the entry-point.
static <T extends IInstruction> int removeUnreachableBlocks(CFG<T> cfg, List<BasicBlock<T>> tbr)
Remove a list of blocks from the CFG.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CFGUtil ()

Public Methods

public static boolean compare (CFG<T> cfg1, CFG<T> cfg2)

Basic CFG comparison. Expect same flags, same addresses, same blocks, same instruction in blocks. What is not checked: DFA data (N/A), flow/edges information (theoretically equal if comparison succeeds since flow information is derived from CFG flags + instructions).

Parameters
cfg1 first CFG
cfg2 second CFG
Returns
  • true if both CFGs are equals, per the above definition

public static boolean compare (int failmode, Comparator<T> comparator, CFG<T> cfg1, CFG<T> cfg2)

Basic CFG comparison. Expect same flags, same addresses, same blocks, same instruction in blocks. What is not checked: DFA data (N/A), flow/edges information (theoretically equal if comparison succeeds since flow information is derived from CFG flags + instructions).

Parameters
failmode 0=normal failure (no log, return false)
1=normal failure with log, return false
2=throw a RuntimeException with message
comparator custom instruction comparator (optional)
cfg1 first CFG
cfg2 second CFG
Returns
  • true if both CFGs are equals, per the above definition

public static CFG<T> duplicateShallow (CFG<T> cfg)

Shallow duplication of a CFG. The duplicated CFG references the instructions of the original CFG.

Parameters
cfg original CFG
Returns
  • a duplicated CFG - instructions are NOT duplicated

public static Collection<BasicBlock<T>> getReachableBlocks (CFG<T> cfg)

Collect the list of all blocks reachable from the entry point.

Returns
  • collection of blocks

public static int removeUnreachableBlocks (CFG<T> cfg)

Remove all blocks not reachable from the entry-point.

If the CFG is composed of IResizableInstruction, instruction sizes may be adjusted to avoid the introduction of gaps between blocks.

Parameters
cfg CFG
Returns
  • count of removed blocks

public static int removeUnreachableBlocks (CFG<T> cfg, List<BasicBlock<T>> tbr)

Remove a list of blocks from the CFG.

If the CFG is composed of IResizableInstruction, instruction sizes may be adjusted to avoid the introduction of gaps between blocks.

Parameters
cfg CFG
tbr bootstrap list of blocks to be removed: those blocks will be removed as well as all blocks no longer reachable from the entry point from the result of those deletions
Returns
  • count of removed blocks