soot.toolkits.graph.BriefUnitGraph Java Examples

The following examples show how to use soot.toolkits.graph.BriefUnitGraph. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NullnessDriver.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
protected void internalTransform(Body b, String phaseName, 
                                 java.util.Map options)
{
    NullnessAnalysis na = new NullnessAnalysis(new BriefUnitGraph(b));

    java.util.Iterator uIt = b.getUnits().iterator();
    while (uIt.hasNext())
    {
        Unit u = (Unit)uIt.next();

        StringBuffer n = new StringBuffer();
        u.addTag(new StringTag("IN: "+na.getFlowBefore(u).toString()));

        if (u.fallsThrough())
        { 
            ArraySparseSet s = (ArraySparseSet)na.getFallFlowAfter(u);
            u.addTag(new StringTag("FALL: "+s.toString())); 
        }
        if (u.branches())
        { 
            ArraySparseSet t = (ArraySparseSet)na.
                getBranchFlowAfter(u).get(0);
            u.addTag(new StringTag("BRANCH: "+t.toString())); 
        }
    }
}
 
Example #2
Source File: MoveLoadsAboveIfs.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private boolean checkCandidate(List<Unit> succs, BriefUnitGraph bug) {
  if (succs.size() < 2)
    return false;
  
  Object o = succs.get(0);
  for (int i = 1; i < succs.size(); i++) {
    if (succs.get(i).getClass() != o.getClass()) 
      return false;
  }
  
  if (o instanceof BLoadInst) {
    BLoadInst bl = (BLoadInst)o;
    Local l = bl.getLocal();
    for (int i = 1; i < succs.size(); i++) {
      BLoadInst bld = (BLoadInst)succs.get(i);
      if (bld.getLocal() != l || bug.getPredsOf(bld).size() > 1)
        return false;
    }
    return true;
  }
  
  return false;
}
 
Example #3
Source File: UtilSMT.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
public static Unit getPostDominatorOfUnit(IInfoflowCFG cfg, Unit dataFlowStatement) {		
	Map<Unit, Set<ControlFlowPath>> controlFlowPathsAtUnit = new HashMap<Unit, Set<ControlFlowPath>>();
	Set<ControlFlowPath> currentPaths = new HashSet<ControlFlowPath>();
	Stack<Unit> worklist = new Stack<Unit>();
	worklist.add(dataFlowStatement);	

	while(!worklist.isEmpty()) {
		Unit currentUnit = worklist.pop();
		
		if(currentUnit.hasTag(InstrumentedCodeTag.name)) {
			List<Unit> successors = cfg.getSuccsOf(currentUnit);
			
			for(Unit nextUnit : successors) {
				if(proceedWithNextUnit(currentUnit, nextUnit, currentPaths, controlFlowPathsAtUnit)) {
					worklist.push(nextUnit);				
				}
			}
			continue;
		}
		
		SootMethod currentMethod = cfg.getMethodOf(currentUnit);
		
		//this is a kind of hack: We excluded exception-edges here and also keep in mind that ALL dominator-algorithms are intra-procedural
		MHGPostDominatorsFinder<Unit> postdominatorFinder = new MHGPostDominatorsFinder<Unit>(new BriefUnitGraph(currentMethod.retrieveActiveBody()));
		Unit immediatePostDominator = postdominatorFinder.getImmediateDominator(currentUnit);
		while(immediatePostDominator.hasTag(InstrumentedCodeTag.name)) {
			immediatePostDominator = postdominatorFinder.getImmediateDominator(immediatePostDominator);
		}
		return immediatePostDominator;
	}	
	return null;
}
 
Example #4
Source File: DavaBody.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs a DavaBody from the given Body.
 */
DavaBody(Body body) {
	this(body.getMethod());
	debug("DavaBody","creating DavaBody for"+body.getMethod().toString());
	Dava.v().log("\nstart method " + body.getMethod().toString());
	
	if(DEBUG){
		if(body.getMethod().getExceptions().size()!=0)
			debug("DavaBody","printing NON EMPTY exception list for "+body.getMethod().toString()+ " " + body.getMethod().getExceptions().toString());
	}
	// copy and "convert" the grimp representation
	//DEBUG=true;
	copy_Body(body);
	//DEBUG=false;
	
	// prime the analysis
	AugmentedStmtGraph asg = new AugmentedStmtGraph(
			new BriefUnitGraph(this), new TrapUnitGraph(this));
	//System.out.println(asg.toString());

	ExceptionFinder.v().preprocess(this, asg);
	SETNode SET = new SETTopNode(asg.get_ChainView());

	while (true) {
		try {
			CycleFinder.v().find(this, asg, SET);
			IfFinder.v().find(this, asg, SET);
			SwitchFinder.v().find(this, asg, SET);
			SynchronizedBlockFinder.v().find(this, asg, SET);
			ExceptionFinder.v().find(this, asg, SET);
			SequenceFinder.v().find(this, asg, SET);
			LabeledBlockFinder.v().find(this, asg, SET);
			AbruptEdgeFinder.v().find(this, asg, SET);
		} catch (RetriggerAnalysisException rae) {
			SET = new SETTopNode(asg.get_ChainView());
			consumedConditions = new HashSet<Object>();
			continue;
		}
		break;
	}

	MonitorConverter.v().convert(this);
	ThrowNullConverter.v().convert(this);

	ASTNode AST = SET.emit_AST();

	// get rid of the grimp representation, put in the new AST
	getTraps().clear();
	getUnits().clear();
	getUnits().addLast(AST);

	// perform transformations on the AST	
	/*
	 * Nomair This should be refactored to use the new AnalysisAdapter classes
	 */
	do {
		G.v().ASTAnalysis_modified = false;

		AST.perform_Analysis(UselessTryRemover.v());

	} while (G.v().ASTAnalysis_modified);

	/*
	 Nomair A Naeem 10-MARCH-2005

	 IT IS ESSENTIAL TO CALL THIS METHOD
	 This method initializes the locals of the current method being processed
	 Failure to invoke this method here will result in no locals being printed out
	 */
	if (AST instanceof ASTMethodNode) {
		((ASTMethodNode) AST).storeLocals(this);

		/*
		 * January 12th, 2006
		 * Deal with the super() problem before continuing
		 */
		Map options = PhaseOptions.v().getPhaseOptions("db.force-recompile");
        boolean force = PhaseOptions.getBoolean(options, "enabled");
        //System.out.println("force is "+force);
        if(force){
        	AST.apply(new SuperFirstStmtHandler((ASTMethodNode) AST));
        }

        debug("DavaBody","PreInit booleans is" + G.v().SootMethodAddedByDava);

	}
	Dava.v().log("end method " + body.getMethod().toString());
}
 
Example #5
Source File: RegionAnalysis.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void findWeakRegions()
{

    /*
     * Check to see what kind of CFG has been passed in and create
     * the appropriate block CFG. Note that almost all of the processing
     * is done on the block CFG.
     */

    if(this.m_cfg instanceof ExceptionalUnitGraph)
        this.m_blockCFG = new ExceptionalBlockGraph((ExceptionalUnitGraph)this.m_cfg);
    else if(this.m_cfg instanceof EnhancedUnitGraph)
        this.m_blockCFG = new EnhancedBlockGraph((EnhancedUnitGraph)this.m_cfg);
    else if(this.m_cfg instanceof BriefUnitGraph)
        this.m_blockCFG = new BriefBlockGraph((BriefUnitGraph)this.m_cfg);
    else
        throw new RuntimeException("Unsupported CFG passed into the RegionAnalyis constructor!");



    this.m_dom = new MHGDominatorTree<Block>(new MHGDominatorsFinder<Block>(this.m_blockCFG));


    try{

        this.m_pdom = new MHGDominatorTree<Block>(new MHGPostDominatorsFinder<Block>(m_blockCFG));

        if(Options.v().verbose())
            G.v().out.println("[RegionAnalysis] PostDominator tree: ");

        this.m_regCount = -1;

        /*
         * If a Brief graph or Exceptional graph is used, the CFG might be multi-headed and/or
         * multi-tailed, which in turn, could result in a post-dominator forest instead of tree.
         * If the post-dominator tree has multiple heads, the weakRegionDFS does not work correctly
         * because it is designed based on the assumption that there is an auxiliary STOP node in the
         * CFG that post-dominates all other nodes. In fact, most of the CFG algorithms augment
         * the control flow graph with two nodes: ENTRY and EXIT (or START and STOP) nodes. We have
         * not added these nodes since the CFG here is created from the Jimple code and to be 
         * consistent we'd have to transform the code to reflect these nodes. Instead, we implemted
         * the EnhancedUnitGraph (EnhancedBlockGraph) which is guaranteed to be single-headed single-tailed.
         * But note that EnhancedUnitGraph represents exceptional flow differently.
         * 
         * 
         */


        if(this.m_blockCFG.getHeads().size() == 1)
        {
            this.m_regCount++;
            this.m_regions.put(this.m_regCount, this.createRegion(this.m_regCount));
            this.weakRegionDFS2(this.m_blockCFG.getHeads().get(0), this.m_regCount);
        }
        else if(this.m_blockCFG.getTails().size() == 1)
        {
            this.m_regCount++;
            this.m_regions.put(this.m_regCount, this.createRegion(this.m_regCount));
            this.weakRegionDFS(this.m_blockCFG.getTails().get(0), this.m_regCount);

        }
        else 
        {
            if(Options.v().verbose())
                G.v().out.println("WARNING: RegionAnalysis: the CFG is multi-headed and tailed, so, the results of this analysis might not be reliable!");

            for(int i = 0; i < this.m_blockCFG.getTails().size(); i++)
            {
                this.m_regCount++;
                this.m_regions.put(this.m_regCount, this.createRegion(this.m_regCount));
                this.weakRegionDFS(this.m_blockCFG.getTails().get(i), this.m_regCount);

            }
            //throw new RuntimeException("RegionAnalysis: cannot properly deal with multi-headed and tailed CFG!");
        }


    }
    catch(RuntimeException e)
    {
        G.v().out.println("[RegionAnalysis] Exception in findWeakRegions: " + e);			
    }


}
 
Example #6
Source File: CFGGraphType.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public DirectedGraph buildGraph(Body b) { 
return new BriefUnitGraph(b); 
     }
 
Example #7
Source File: MyCastChecker.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
public MyCastChecker(BriefUnitGraph cfg) {
    super(cfg);
}
 
Example #8
Source File: ObservableDynamicICFG.java    From SPDS with Eclipse Public License 2.0 4 votes vote down vote up
private DirectedGraph<Unit> makeGraph(Body body) {
    return enableExceptions ? new ExceptionalUnitGraph(body, UnitThrowAnalysis.v(), true)
            : new BriefUnitGraph(body);
}