Class CFGUtil
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.cfg.CFGUtil
Static utility routines for control flow graphs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends IInstruction>
booleancompare
(int failmode, Comparator<T> comparator, CFG<T> cfg1, CFG<T> cfg2) Basic CFG comparison.static <T extends IInstruction>
booleanBasic 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>
intremoveUnreachableBlocks
(CFG<T> cfg) Remove all blocks not reachable from the entry-point.static <T extends IInstruction>
intremoveUnreachableBlocks
(CFG<T> cfg, List<BasicBlock<T>> tbr) Remove a list of blocks from the CFG.
-
Constructor Details
-
CFGUtil
public CFGUtil()
-
-
Method Details
-
compare
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).- Type Parameters:
T
-- Parameters:
cfg1
- first CFGcfg2
- second CFG- Returns:
- true if both CFGs are equals, per the above definition
-
compare
public static <T extends IInstruction> 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).- Type Parameters:
T
-- Parameters:
failmode
- 0=normal failure (no log, return false)
1=normal failure with log, return false
2=throw aRuntimeException
with messagecomparator
- custom instruction comparator (optional)cfg1
- first CFGcfg2
- second CFG- Returns:
- true if both CFGs are equals, per the above definition
-
duplicateShallow
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
-
getReachableBlocks
Collect the list of all blocks reachable from the entry point.- Type Parameters:
T
-- Parameters:
cfg
-- Returns:
- collection of blocks
-
removeUnreachableBlocks
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.- Type Parameters:
T
-- Parameters:
cfg
- CFG- Returns:
- count of removed blocks
-
removeUnreachableBlocks
public static <T extends IInstruction> 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.- Type Parameters:
T
-- Parameters:
cfg
- CFGtbr
- 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
-