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

public class CFGUtil extends Object
Static utility routines for control flow graphs.
  • Constructor Details

    • CFGUtil

      public CFGUtil()
  • Method Details

    • compare

      public static <T extends IInstruction> 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).
      Type Parameters:
      T -
      Parameters:
      cfg1 - first CFG
      cfg2 - 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 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
    • duplicateShallow

      public static <T extends IInstruction> 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
    • getReachableBlocks

      public static <T extends IInstruction> Collection<BasicBlock<T>> getReachableBlocks(CFG<T> cfg)
      Collect the list of all blocks reachable from the entry point.
      Type Parameters:
      T -
      Parameters:
      cfg -
      Returns:
      collection of blocks
    • removeUnreachableBlocks

      public static <T extends IInstruction> 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.

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