Search in sources :

Example 31 with AllocNode

use of soot.jimple.spark.pag.AllocNode in project soot by Sable.

the class PropWorklist method handleVarNode.

/**
 * Propagates new points-to information of node src to all its successors.
 */
protected final boolean handleVarNode(final VarNode src) {
    boolean ret = false;
    boolean flush = true;
    if (src.getReplacement() != src)
        throw new RuntimeException("Got bad node " + src + " with rep " + src.getReplacement());
    final PointsToSetInternal newP2Set = src.getP2Set().getNewSet();
    if (newP2Set.isEmpty())
        return false;
    if (ofcg != null) {
        QueueReader<Node> addedEdges = pag.edgeReader();
        ofcg.updatedNode(src);
        ofcg.build();
        while (addedEdges.hasNext()) {
            Node addedSrc = (Node) addedEdges.next();
            Node addedTgt = (Node) addedEdges.next();
            ret = true;
            if (addedSrc instanceof VarNode) {
                VarNode edgeSrc = (VarNode) addedSrc.getReplacement();
                if (addedTgt instanceof VarNode) {
                    VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
                        varNodeWorkList.add(edgeTgt);
                        if (edgeTgt == src)
                            flush = false;
                    }
                } else if (addedTgt instanceof NewInstanceNode) {
                    NewInstanceNode edgeTgt = (NewInstanceNode) addedTgt.getReplacement();
                    if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
                        for (Node element : pag.assignInstanceLookup(edgeTgt)) {
                            varNodeWorkList.add((VarNode) element);
                            if (element == src)
                                flush = false;
                        }
                    }
                }
            } else if (addedSrc instanceof AllocNode) {
                VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
                if (edgeTgt.makeP2Set().add(addedSrc)) {
                    varNodeWorkList.add(edgeTgt);
                    if (edgeTgt == src)
                        flush = false;
                }
            } else if (addedSrc instanceof NewInstanceNode && addedTgt instanceof VarNode) {
                final NewInstanceNode edgeSrc = (NewInstanceNode) addedSrc.getReplacement();
                final VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
                addedSrc.getP2Set().forall(new P2SetVisitor() {

                    @Override
                    public void visit(Node n) {
                        if (n instanceof ClassConstantNode) {
                            ClassConstantNode ccn = (ClassConstantNode) n;
                            Type ccnType = ccn.getClassConstant().toSootType();
                            // If the referenced class has not been loaded,
                            // we do this now
                            SootClass targetClass = ((RefType) ccnType).getSootClass();
                            if (targetClass.resolvingLevel() == SootClass.DANGLING)
                                Scene.v().forceResolve(targetClass.getName(), SootClass.SIGNATURES);
                            // We can only create alloc nodes for types that
                            // we know
                            edgeTgt.makeP2Set().add(pag.makeAllocNode(edgeSrc.getValue(), ccnType, ccn.getMethod()));
                            varNodeWorkList.add(edgeTgt);
                        }
                    }
                });
                if (edgeTgt.makeP2Set().add(addedSrc)) {
                    if (edgeTgt == src)
                        flush = false;
                }
            }
        }
    }
    Node[] simpleTargets = pag.simpleLookup(src);
    for (Node element : simpleTargets) {
        if (element.makeP2Set().addAll(newP2Set, null)) {
            varNodeWorkList.add((VarNode) element);
            if (element == src)
                flush = false;
            ret = true;
        }
    }
    Node[] storeTargets = pag.storeLookup(src);
    for (Node element : storeTargets) {
        final FieldRefNode fr = (FieldRefNode) element;
        final SparkField f = fr.getField();
        ret = fr.getBase().getP2Set().forall(new P2SetVisitor() {

            public final void visit(Node n) {
                AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, f);
                if (nDotF.makeP2Set().addAll(newP2Set, null)) {
                    returnValue = true;
                }
            }
        }) | ret;
    }
    final HashSet<Node[]> storesToPropagate = new HashSet<Node[]>();
    final HashSet<Node[]> loadsToPropagate = new HashSet<Node[]>();
    for (final FieldRefNode fr : src.getAllFieldRefs()) {
        final SparkField field = fr.getField();
        final Node[] storeSources = pag.storeInvLookup(fr);
        if (storeSources.length > 0) {
            newP2Set.forall(new P2SetVisitor() {

                public final void visit(Node n) {
                    AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, field);
                    for (Node element : storeSources) {
                        Node[] pair = { element, nDotF.getReplacement() };
                        storesToPropagate.add(pair);
                    }
                }
            });
        }
        final Node[] loadTargets = pag.loadLookup(fr);
        if (loadTargets.length > 0) {
            newP2Set.forall(new P2SetVisitor() {

                public final void visit(Node n) {
                    AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, field);
                    if (nDotF != null) {
                        for (Node element : loadTargets) {
                            Node[] pair = { nDotF.getReplacement(), element };
                            loadsToPropagate.add(pair);
                        }
                    }
                }
            });
        }
    }
    if (flush)
        src.getP2Set().flushNew();
    for (Node[] p : storesToPropagate) {
        VarNode storeSource = (VarNode) p[0];
        AllocDotField nDotF = (AllocDotField) p[1];
        if (nDotF.makeP2Set().addAll(storeSource.getP2Set(), null)) {
            ret = true;
        }
    }
    for (Node[] p : loadsToPropagate) {
        AllocDotField nDotF = (AllocDotField) p[0];
        VarNode loadTarget = (VarNode) p[1];
        if (loadTarget.makeP2Set().addAll(nDotF.getP2Set(), null)) {
            varNodeWorkList.add(loadTarget);
            ret = true;
        }
    }
    return ret;
}
Also used : VarNode(soot.jimple.spark.pag.VarNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) AllocDotField(soot.jimple.spark.pag.AllocDotField) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) SparkField(soot.jimple.spark.pag.SparkField) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) SootClass(soot.SootClass) RefType(soot.RefType) Type(soot.Type) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor) HashSet(java.util.HashSet)

Example 32 with AllocNode

use of soot.jimple.spark.pag.AllocNode 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 33 with AllocNode

use of soot.jimple.spark.pag.AllocNode in project soot by Sable.

the class StartJoinAnalysis method getMayAliasList.

private List<AllocNode> getMayAliasList(PointsToSetInternal pts) {
    List<AllocNode> list = new ArrayList<AllocNode>();
    final HashSet<AllocNode> ret = new HashSet<AllocNode>();
    pts.forall(new P2SetVisitor() {

        public void visit(Node n) {
            ret.add((AllocNode) n);
        }
    });
    Iterator<AllocNode> it = ret.iterator();
    while (it.hasNext()) {
        list.add(it.next());
    }
    return list;
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 34 with AllocNode

use of soot.jimple.spark.pag.AllocNode in project soot by Sable.

the class PropAlias method handleAllocNode.

/* End of public methods. */
/* End of package methods. */
/**
 * Propagates new points-to information of node src to all its successors.
 */
protected final boolean handleAllocNode(AllocNode src) {
    boolean ret = false;
    Node[] targets = pag.allocLookup(src);
    for (Node element : targets) {
        if (element.makeP2Set().add(src)) {
            addToWorklist((VarNode) element);
            ret = true;
        }
    }
    return ret;
}
Also used : FieldRefNode(soot.jimple.spark.pag.FieldRefNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode)

Example 35 with AllocNode

use of soot.jimple.spark.pag.AllocNode in project soot by Sable.

the class PropIter method handleStores.

protected final boolean handleStores(VarNode src) {
    boolean ret = false;
    final PointsToSetInternal srcSet = src.getP2Set();
    if (srcSet.isEmpty())
        return false;
    Node[] storeTargets = pag.storeLookup(src);
    for (Node element : storeTargets) {
        final FieldRefNode fr = (FieldRefNode) element;
        final SparkField f = fr.getField();
        ret = fr.getBase().getP2Set().forall(new P2SetVisitor() {

            public final void visit(Node n) {
                AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, f);
                if (nDotF.makeP2Set().addAll(srcSet, null)) {
                    returnValue = true;
                }
            }
        }) | ret;
    }
    return ret;
}
Also used : FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocDotField(soot.jimple.spark.pag.AllocDotField) AllocNode(soot.jimple.spark.pag.AllocNode) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) SparkField(soot.jimple.spark.pag.SparkField) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Aggregations

AllocNode (soot.jimple.spark.pag.AllocNode)67 Node (soot.jimple.spark.pag.Node)37 VarNode (soot.jimple.spark.pag.VarNode)36 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)28 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)25 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)22 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)19 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)18 SegmentNode (soot.jimple.spark.geom.dataRep.SegmentNode)18 SootMethod (soot.SootMethod)17 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)17 SparkField (soot.jimple.spark.pag.SparkField)16 RefType (soot.RefType)14 Type (soot.Type)13 AllocDotField (soot.jimple.spark.pag.AllocDotField)13 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)11 HashSet (java.util.HashSet)10 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)10 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)10 SootClass (soot.SootClass)9