Search in sources :

Example 26 with Body

use of soot.Body in project soot by Sable.

the class AbstractJimpleBasedICFG method getEndPointsOf.

@Override
public Collection<Unit> getEndPointsOf(SootMethod m) {
    if (m.hasActiveBody()) {
        Body body = m.getActiveBody();
        DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body);
        return unitGraph.getTails();
    }
    return Collections.emptySet();
}
Also used : Unit(soot.Unit) Body(soot.Body)

Example 27 with Body

use of soot.Body in project soot by Sable.

the class AbstractJimpleBasedICFG method getPredsOf.

@Override
public List<Unit> getPredsOf(Unit u) {
    assert u != null;
    Body body = unitToOwner.get(u);
    DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body);
    return unitGraph.getPredsOf(u);
}
Also used : Unit(soot.Unit) Body(soot.Body)

Example 28 with Body

use of soot.Body in project soot by Sable.

the class AbstractJimpleBasedICFG method isExitStmt.

@Override
public boolean isExitStmt(Unit u) {
    Body body = unitToOwner.get(u);
    DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body);
    return unitGraph.getTails().contains(u);
}
Also used : Unit(soot.Unit) Body(soot.Body)

Example 29 with Body

use of soot.Body in project soot by Sable.

the class OnTheFlyJimpleBasedICFG method initForMethod.

protected Body initForMethod(SootMethod m) {
    assert Scene.v().hasFastHierarchy();
    Body b = null;
    if (m.isConcrete()) {
        SootClass declaringClass = m.getDeclaringClass();
        ensureClassHasBodies(declaringClass);
        synchronized (Scene.v()) {
            b = m.retrieveActiveBody();
        }
        if (b != null) {
            for (Unit u : b.getUnits()) {
                if (unitToOwner.put(u, b) != null) {
                    // simply skip the rest
                    break;
                }
            }
        }
    }
    assert Scene.v().hasFastHierarchy();
    return b;
}
Also used : SootClass(soot.SootClass) Unit(soot.Unit) Body(soot.Body)

Example 30 with Body

use of soot.Body in project soot by Sable.

the class OnTheFlyJimpleBasedICFG method main.

public static void main(String[] args) {
    PackManager.v().getPack("wjtp").add(new Transform("wjtp.onflyicfg", new SceneTransformer() {

        @Override
        protected void internalTransform(String phaseName, Map<String, String> options) {
            if (Scene.v().hasCallGraph())
                throw new RuntimeException("call graph present!");
            loadAllClassesOnClassPathToSignatures();
            SootMethod mainMethod = Scene.v().getMainMethod();
            OnTheFlyJimpleBasedICFG icfg = new OnTheFlyJimpleBasedICFG(mainMethod);
            Set<SootMethod> worklist = new LinkedHashSet<SootMethod>();
            Set<SootMethod> visited = new HashSet<SootMethod>();
            worklist.add(mainMethod);
            int monomorphic = 0, polymorphic = 0;
            while (!worklist.isEmpty()) {
                Iterator<SootMethod> iter = worklist.iterator();
                SootMethod currMethod = iter.next();
                iter.remove();
                visited.add(currMethod);
                System.err.println(currMethod);
                // MUST call this method to initialize ICFG for every method
                Body body = currMethod.getActiveBody();
                if (body == null)
                    continue;
                for (Unit u : body.getUnits()) {
                    Stmt s = (Stmt) u;
                    if (s.containsInvokeExpr()) {
                        Set<SootMethod> calleesOfCallAt = icfg.getCalleesOfCallAt(s);
                        if (s.getInvokeExpr() instanceof VirtualInvokeExpr || s.getInvokeExpr() instanceof InterfaceInvokeExpr) {
                            if (calleesOfCallAt.size() <= 1)
                                monomorphic++;
                            else
                                polymorphic++;
                            System.err.println("mono: " + monomorphic + "   poly: " + polymorphic);
                        }
                        for (SootMethod callee : calleesOfCallAt) {
                            if (!visited.contains(callee)) {
                                System.err.println(callee);
                            // worklist.add(callee);
                            }
                        }
                    }
                }
            }
        }
    }));
    Options.v().set_on_the_fly(true);
    soot.Main.main(args);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) Unit(soot.Unit) SceneTransformer(soot.SceneTransformer) Stmt(soot.jimple.Stmt) SootMethod(soot.SootMethod) Transform(soot.Transform) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) HashMap(java.util.HashMap) Map(java.util.Map) Body(soot.Body) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Body (soot.Body)57 Unit (soot.Unit)37 SootMethod (soot.SootMethod)32 Local (soot.Local)20 SootClass (soot.SootClass)19 Value (soot.Value)15 InvokeExpr (soot.jimple.InvokeExpr)14 StaticInvokeExpr (soot.jimple.StaticInvokeExpr)13 Type (soot.Type)12 Stmt (soot.jimple.Stmt)12 InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)11 JimpleBody (soot.jimple.JimpleBody)11 SpecialInvokeExpr (soot.jimple.SpecialInvokeExpr)11 RefType (soot.RefType)10 VoidType (soot.VoidType)10 VirtualInvokeExpr (soot.jimple.VirtualInvokeExpr)10 LinkedList (java.util.LinkedList)9 SootMethodRef (soot.SootMethodRef)9 ArrayList (java.util.ArrayList)8 PrimType (soot.PrimType)8