Skip to content

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

License

Notifications You must be signed in to change notification settings

ufarooq/HelloDataflow-Soot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published