Search in sources :

Example 56 with Node

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

the class PtInsNode method do_before_propagation.

@Override
public void do_before_propagation() {
    // if ( complex_cons == null )
    do_pts_interval_merge();
    // if ( !(me instanceof LocalVarNode) )
    do_flow_edge_interval_merge();
    // This pointer filter, please read the comments at this line in file FullSensitiveNode.java
    Node wrappedNode = getWrappedNode();
    if (wrappedNode instanceof LocalVarNode && ((LocalVarNode) wrappedNode).isThisPtr()) {
        SootMethod func = ((LocalVarNode) wrappedNode).getMethod();
        if (!func.isConstructor()) {
            // We don't process the specialinvoke call edge
            SootClass defClass = func.getDeclaringClass();
            Hierarchy typeHierarchy = Scene.v().getActiveHierarchy();
            for (Iterator<AllocNode> it = new_pts.keySet().iterator(); it.hasNext(); ) {
                AllocNode obj = it.next();
                if (obj.getType() instanceof RefType) {
                    SootClass sc = ((RefType) obj.getType()).getSootClass();
                    if (defClass != sc) {
                        try {
                            SootMethod rt_func = typeHierarchy.resolveConcreteDispatch(sc, func);
                            if (rt_func != func) {
                                it.remove();
                                // Also preclude it from propagation again
                                pt_objs.put(obj, (PtInsIntervalManager) deadManager);
                            }
                        } catch (RuntimeException e) {
                        // If the input program has a wrong type cast, resolveConcreteDispatch fails and it goes here
                        // We simply ignore this error
                        }
                    }
                }
            }
        }
    }
}
Also used : RefType(soot.RefType) Hierarchy(soot.Hierarchy) AllocNode(soot.jimple.spark.pag.AllocNode) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode) StringConstantNode(soot.jimple.spark.pag.StringConstantNode) RectangleNode(soot.jimple.spark.geom.dataRep.RectangleNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) SootMethod(soot.SootMethod) SootClass(soot.SootClass) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Example 57 with Node

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

the class SparkLibraryHelper method caseArrayType.

/**
 * A new local array will be created and connected to
 * {@link SparkLibraryHelper#node} of type {@link ArrayType}. For this new
 * local an allocation edge to a new array of its declared type will be
 * added. If the {@link ArrayType#getElementType()} is still an array an
 * allocation to a new array of this element type will be made and stored
 * until the element type is a {@link RefType}. If this is the case an
 * allocation to {@link AnySubType} of {@link ArrayType#baseType} will be
 * made.
 */
@Override
public void caseArrayType(ArrayType type) {
    Node array = node;
    for (Type t = type; t instanceof ArrayType; t = ((ArrayType) t).getElementType()) {
        ArrayType at = (ArrayType) t;
        if (at.baseType instanceof RefType) {
            // var tmpArray;
            LocalVarNode localArray = pag.makeLocalVarNode(new Object(), t, method);
            // x = tmpArray;
            pag.addEdge(localArray, array);
            // new T[]
            AllocNode newArray = pag.makeAllocNode(new Object(), at, method);
            // tmpArray = new T[]
            pag.addEdge(newArray, localArray);
            // tmpArray[i]
            FieldRefNode arrayRef = pag.makeFieldRefNode(localArray, ArrayElement.v());
            // var tmp
            LocalVarNode local = pag.makeLocalVarNode(new Object(), at.getElementType(), method);
            // tmpArray[i] = tmp
            pag.addEdge(local, arrayRef);
            // x = tmp
            array = local;
            if (at.numDimensions == 1) {
                // new T()
                AllocNode alloc = pag.makeAllocNode(new Object(), AnySubType.v((RefType) at.baseType), method);
                // tmp = new T()
                pag.addEdge(alloc, local);
            }
        }
    }
}
Also used : ArrayType(soot.ArrayType) RefType(soot.RefType) RefType(soot.RefType) ArrayType(soot.ArrayType) AnySubType(soot.AnySubType) Type(soot.Type) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Example 58 with Node

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

the class TypeManager method makeTypeMask.

public final void makeTypeMask() {
    RefType.v("java.lang.Class");
    typeMask = new LargeNumberedMap<Type, BitVector>(Scene.v().getTypeNumberer());
    if (fh == null)
        return;
    int numTypes = Scene.v().getTypeNumberer().size();
    if (pag.getOpts().verbose())
        logger.debug("" + "Total types: " + numTypes);
    // **
    initClass2allocs();
    makeClassTypeMask(Scene.v().getSootClass("java.lang.Object"));
    BitVector visitedTypes = new BitVector();
    {
        Iterator<Type> it = typeMask.keyIterator();
        while (it.hasNext()) {
            Type t = it.next();
            visitedTypes.set(t.getNumber());
        }
    }
    // **
    ArrayNumberer<AllocNode> allocNodes = pag.getAllocNodeNumberer();
    for (Type t : Scene.v().getTypeNumberer()) {
        if (!(t instanceof RefLikeType))
            continue;
        if (t instanceof AnySubType)
            continue;
        if (isUnresolved(t))
            continue;
        // **
        if (t instanceof RefType && !t.equals(RefType.v("java.lang.Object")) && !t.equals(RefType.v("java.io.Serializable")) && !t.equals(RefType.v("java.lang.Cloneable"))) {
            SootClass sc = ((RefType) t).getSootClass();
            if (sc.isInterface()) {
                makeMaskOfInterface(sc);
            }
            if (!visitedTypes.get(t.getNumber()) && !((RefType) t).getSootClass().isPhantom()) {
                makeClassTypeMask(((RefType) t).getSootClass());
            }
            continue;
        }
        // **
        BitVector mask = new BitVector(allocNodes.size());
        for (Node n : allocNodes) {
            if (castNeverFails(n.getType(), t)) {
                mask.set(n.getNumber());
            }
        }
        typeMask.put(t, mask);
    }
    allocNodeListener = pag.allocNodeListener();
}
Also used : RefLikeType(soot.RefLikeType) RefType(soot.RefType) BitVector(soot.util.BitVector) RefType(soot.RefType) AnySubType(soot.AnySubType) NullType(soot.NullType) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) Iterator(java.util.Iterator) AnySubType(soot.AnySubType) SootClass(soot.SootClass)

Example 59 with Node

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

the class PtSensVisitor method hasNonEmptyIntersection.

/**
 * Tests if two containers have contain same things.
 * Can be used to answer the alias query.
 */
public boolean hasNonEmptyIntersection(PtSensVisitor<VarType> other) {
    // Using table view for comparison, that's faster
    for (Map.Entry<Node, List<VarType>> entry : tableView.entrySet()) {
        Node var = entry.getKey();
        List<VarType> list1 = entry.getValue();
        List<VarType> list2 = other.getCSList(var);
        if (list1.size() == 0 || list2.size() == 0)
            continue;
        for (VarType cv1 : list1) {
            for (VarType cv2 : list2) if (cv1.intersect(cv2))
                return true;
        }
    }
    return false;
}
Also used : Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 60 with Node

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

the class FullSensitiveNode method injectPts.

/**
 *  We transfer the SPARK results to current pointer if this pointer is not involved in the geometric analysis.
 *  Note that, the unreachable objects will not be inserted.
 */
@Override
public void injectPts() {
    final GeomPointsTo geomPTA = (GeomPointsTo) Scene.v().getPointsToAnalysis();
    pt_objs = new HashMap<AllocNode, GeometricManager>();
    me.getP2Set().forall(new P2SetVisitor() {

        @Override
        public void visit(Node n) {
            if (geomPTA.isValidGeometricNode(n))
                pt_objs.put((AllocNode) n, (GeometricManager) stubManager);
        }
    });
    new_pts = null;
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode) StringConstantNode(soot.jimple.spark.pag.StringConstantNode) RectangleNode(soot.jimple.spark.geom.dataRep.RectangleNode) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) AllocNode(soot.jimple.spark.pag.AllocNode) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Aggregations

Node (soot.jimple.spark.pag.Node)65 AllocNode (soot.jimple.spark.pag.AllocNode)62 VarNode (soot.jimple.spark.pag.VarNode)54 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)36 LocalVarNode (soot.jimple.spark.pag.LocalVarNode)36 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)25 P2SetVisitor (soot.jimple.spark.sets.P2SetVisitor)23 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)18 ClassConstantNode (soot.jimple.spark.pag.ClassConstantNode)17 NewInstanceNode (soot.jimple.spark.pag.NewInstanceNode)17 SparkField (soot.jimple.spark.pag.SparkField)17 SootMethod (soot.SootMethod)15 RefType (soot.RefType)12 Type (soot.Type)11 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)11 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)10 AllocDotField (soot.jimple.spark.pag.AllocDotField)10 HashSet (java.util.HashSet)9 SootClass (soot.SootClass)9 Value (soot.Value)6