Skip to content

Latest commit

 

History

History
54 lines (51 loc) · 2.35 KB

README.md

File metadata and controls

54 lines (51 loc) · 2.35 KB

HelloDataflow-Soot

Getting started to write Dataflow analysis in Soot. (Without standard Soot templates)

Code Guidelines for Soot APIs

  1. See basic steps to access Class and methods from Soot API , following Soot APIs are provided to implement Dataflow Analysis. Assuming, you have a SootMethod object as sootMethod, using following snippet get all the Basic Blocks in a method.
Body methodBody = sootMethod.retrieveActiveBody();
BlockGraph blockGraph = new BriefBlockGraph(methodBody);
  1. (Optional) Create a List object, if you want to re-order basic blocks such as Topological sort or other operations. Since, graph can not be modified directly.
List<Block> blocks = new ArrayList<Block>(blockGraph.getBlocks());
  1. Get Basic Blocks and iterate over the instructions.
Iterator<Block> graphIt = blockGraph.getBlocks().iterator();  
while (graphIt.hasNext()) {  
    Block block = graphIt.next();  
    ...
}
  1. Use Following API to retrieve all the successor(s) of the basic blocs. (Tip: you will get multiple successors for branch)
List<Block> successors = block.getSuccs();
  1. Use Following API to get all the predecessor(s) of the basic block.
List<Block> predecessors = block.getPreds();
  1. Next, iterate over the Block object and go through the statements.
Iterator<Unit> blockIt = block.iterator();  
while (blockIt.hasNext()) {  
    Unit unit = blockIt.next();  
    ...  
}
  1. Soot Provides a special data structure FlowSet, Which provides basic set operations such as Union between two sets.
// import soot.toolkits.scalar.FlowSet;
// import soot.toolkits.scalar.ArraySparseSet;

FlowSet<T> firstSet = new ArraySparseSet<T>(); //create set object
// use  firstSet.add(object); to add elements
FlowSet<T> secondSet = new ArraySparseSet<T>(); //create another object and add elements
FlowSet<T> thirdSet = new ArraySparseSet<T>(); //keep this object empty to store results

firstSet.union(secondSet, thirdSet); // writes Union (firstSet+secondSet) to thirdSet
  1. Similarly, intersection and difference operations can be performed.
firstSet.difference(secondSet, thirdSet); // writes difference (firstSet-secondSet) to thirdSet
firstSet.intersection(secondSet, thirdSet); // writes Common elements of both sets to thirdSet