Search in sources :

Example 6 with MethodOrMethodContext

use of soot.MethodOrMethodContext in project soot by Sable.

the class CallGraphBuilder method build.

public void build() {
    QueueReader<MethodOrMethodContext> worklist = reachables.listener();
    while (true) {
        ofcgb.processReachables();
        reachables.update();
        if (!worklist.hasNext())
            break;
        final MethodOrMethodContext momc = worklist.next();
        List<Local> receivers = ofcgb.methodToReceivers().get(momc.method());
        if (receivers != null)
            for (Iterator<Local> receiverIt = receivers.iterator(); receiverIt.hasNext(); ) {
                final Local receiver = receiverIt.next();
                final PointsToSet p2set = pa.reachingObjects(receiver);
                for (Iterator<Type> typeIt = p2set.possibleTypes().iterator(); typeIt.hasNext(); ) {
                    final Type type = typeIt.next();
                    ofcgb.addType(receiver, momc.context(), type, null);
                }
            }
        List<Local> bases = ofcgb.methodToInvokeArgs().get(momc.method());
        if (bases != null) {
            for (Local base : bases) {
                PointsToSet pts = pa.reachingObjects(base);
                for (Type ty : pts.possibleTypes()) {
                    ofcgb.addBaseType(base, momc.context(), ty);
                }
            }
        }
        List<Local> argArrays = ofcgb.methodToInvokeBases().get(momc.method());
        if (argArrays != null) {
            for (final Local argArray : argArrays) {
                PointsToSet pts = pa.reachingObjects(argArray);
                if (pts instanceof PointsToSetInternal) {
                    PointsToSetInternal ptsi = (PointsToSetInternal) pts;
                    ptsi.forall(new P2SetVisitor() {

                        @Override
                        public void visit(Node n) {
                            assert n instanceof AllocNode;
                            AllocNode an = (AllocNode) n;
                            Object newExpr = an.getNewExpr();
                            ofcgb.addInvokeArgDotField(argArray, an.dot(ArrayElement.v()));
                            if (newExpr instanceof NewArrayExpr) {
                                NewArrayExpr nae = (NewArrayExpr) newExpr;
                                Value size = nae.getSize();
                                if (size instanceof IntConstant) {
                                    IntConstant arrSize = (IntConstant) size;
                                    ofcgb.addPossibleArgArraySize(argArray, arrSize.value, momc.context());
                                } else {
                                    ofcgb.setArgArrayNonDetSize(argArray, momc.context());
                                }
                            }
                        }
                    });
                }
                for (Type t : pa.reachingObjectsOfArrayElement(pts).possibleTypes()) {
                    ofcgb.addInvokeArgType(argArray, momc.context(), t);
                }
            }
        }
        List<Local> stringConstants = ofcgb.methodToStringConstants().get(momc.method());
        if (stringConstants != null)
            for (Iterator<Local> stringConstantIt = stringConstants.iterator(); stringConstantIt.hasNext(); ) {
                final Local stringConstant = stringConstantIt.next();
                PointsToSet p2set = pa.reachingObjects(stringConstant);
                Collection<String> possibleStringConstants = p2set.possibleStringConstants();
                if (possibleStringConstants == null) {
                    ofcgb.addStringConstant(stringConstant, momc.context(), null);
                } else {
                    for (Iterator<String> constantIt = possibleStringConstants.iterator(); constantIt.hasNext(); ) {
                        final String constant = constantIt.next();
                        ofcgb.addStringConstant(stringConstant, momc.context(), constant);
                    }
                }
            }
    }
}
Also used : PointsToSet(soot.PointsToSet) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) Local(soot.Local) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) NewArrayExpr(soot.jimple.NewArrayExpr) Iterator(java.util.Iterator) Value(soot.Value) IntConstant(soot.jimple.IntConstant) Collection(java.util.Collection) MethodOrMethodContext(soot.MethodOrMethodContext) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 7 with MethodOrMethodContext

use of soot.MethodOrMethodContext in project soot by Sable.

the class JimpleBasedInterproceduralCFG method initializeUnitToOwner.

protected void initializeUnitToOwner() {
    for (Iterator<MethodOrMethodContext> iter = Scene.v().getReachableMethods().listener(); iter.hasNext(); ) {
        SootMethod m = iter.next().method();
        initializeUnitToOwner(m);
    }
}
Also used : SootMethod(soot.SootMethod) MethodOrMethodContext(soot.MethodOrMethodContext)

Example 8 with MethodOrMethodContext

use of soot.MethodOrMethodContext in project soot by Sable.

the class OnFlyCallGraphBuilder method processReachables.

public void processReachables() {
    while (true) {
        if (!worklist.hasNext()) {
            rm.update();
            if (!worklist.hasNext())
                break;
        }
        MethodOrMethodContext momc = worklist.next();
        SootMethod m = momc.method();
        if (appOnly && !m.getDeclaringClass().isApplicationClass())
            continue;
        if (analyzedMethods.add(m))
            processNewMethod(m);
        processNewMethodContext(momc);
    }
}
Also used : SootMethod(soot.SootMethod) MethodOrMethodContext(soot.MethodOrMethodContext)

Example 9 with MethodOrMethodContext

use of soot.MethodOrMethodContext in project soot by Sable.

the class ReachableMethods method update.

/**
 * Causes the QueueReader objects to be filled up with any methods that have
 * become reachable since the last call.
 */
public void update() {
    while (edgeSource.hasNext()) {
        Edge e = edgeSource.next();
        if (set.contains(e.getSrc()))
            addMethod(e.getTgt());
    }
    while (unprocessedMethods.hasNext()) {
        MethodOrMethodContext m = unprocessedMethods.next();
        Iterator<Edge> targets = cg.edgesOutOf(m);
        if (filter != null)
            targets = filter.wrap(targets);
        addMethods(new Targets(targets));
    }
}
Also used : MethodOrMethodContext(soot.MethodOrMethodContext)

Example 10 with MethodOrMethodContext

use of soot.MethodOrMethodContext in project soot by Sable.

the class SideEffectAnalysis method readSet.

public RWSet readSet(SootMethod method, Stmt stmt) {
    RWSet ret = null;
    Iterator<MethodOrMethodContext> targets = tt.iterator(stmt);
    while (targets.hasNext()) {
        SootMethod target = (SootMethod) targets.next();
        if (target.isNative()) {
            if (ret == null)
                ret = new SiteRWSet();
            ret.setCallsNative();
        } else if (target.isConcrete()) {
            RWSet ntr = nonTransitiveReadSet(target);
            if (ntr != null) {
                if (ret == null)
                    ret = new SiteRWSet();
                ret.union(ntr);
            }
        }
    }
    if (ret == null)
        return ntReadSet(method, stmt);
    ret.union(ntReadSet(method, stmt));
    return ret;
}
Also used : SootMethod(soot.SootMethod) MethodOrMethodContext(soot.MethodOrMethodContext)

Aggregations

MethodOrMethodContext (soot.MethodOrMethodContext)12 SootMethod (soot.SootMethod)7 ArrayList (java.util.ArrayList)3 Unit (soot.Unit)3 Value (soot.Value)3 CallGraph (soot.jimple.toolkits.callgraph.CallGraph)3 EquivalentValue (soot.EquivalentValue)2 Type (soot.Type)2 Stmt (soot.jimple.Stmt)2 AllocNode (soot.jimple.spark.pag.AllocNode)2 Node (soot.jimple.spark.pag.Node)2 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Local (soot.Local)1 PointsToSet (soot.PointsToSet)1 RefLikeType (soot.RefLikeType)1 RefType (soot.RefType)1