Search in sources :

Example 21 with LocalVarNode

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

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

the class FullSensitiveNode method do_before_propagation.

@Override
public void do_before_propagation() {
    // We first perform the geometric merging
    do_pts_interval_merge();
    do_flow_edge_interval_merge();
    /*
		 * The following code eliminates the spurious points-to relation for THIS pointer.
		 * For example we have two classes A and B, B is a child class of A.
		 * We have a virtual function foo defined in both A and B.
		 * We have a pointer p in type A.
		 * pts(p) = { o1, o2 }, where o1 is in type A and o2 is in type B.
		 * Therefore, the call p.foo() will be resolved to call both A::foo and B::foo.
		 * Then, in the points-to analysis, we have two assignments: p -> A::foo.THIS, p -> B::foo.THIS
		 * At this time, obviously, although with the type filter, A::foo.THIS will receive the object o2, which is definitely a fake.
		 * Thus, we need a new filter to guarantee that A::foo.THIS only points to o1.
		 * We call this filter "this pointer filter".
		 */
    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, (GeometricManager) 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) ClassConstantNode(soot.jimple.spark.pag.ClassConstantNode) 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)

Aggregations

LocalVarNode (soot.jimple.spark.pag.LocalVarNode)22 SootMethod (soot.SootMethod)16 AllocNode (soot.jimple.spark.pag.AllocNode)15 Node (soot.jimple.spark.pag.Node)13 VarNode (soot.jimple.spark.pag.VarNode)11 FieldRefNode (soot.jimple.spark.pag.FieldRefNode)8 PointsToSetInternal (soot.jimple.spark.sets.PointsToSetInternal)6 RefType (soot.RefType)5 GlobalVarNode (soot.jimple.spark.pag.GlobalVarNode)5 SootClass (soot.SootClass)4 CgEdge (soot.jimple.spark.geom.dataRep.CgEdge)4 PlainConstraint (soot.jimple.spark.geom.dataRep.PlainConstraint)4 AssignEdge (soot.jimple.spark.ondemand.pautil.AssignEdge)4 ContextVarNode (soot.jimple.spark.pag.ContextVarNode)4 SparkField (soot.jimple.spark.pag.SparkField)4 StringConstantNode (soot.jimple.spark.pag.StringConstantNode)4 HashSet (java.util.HashSet)3 Hierarchy (soot.Hierarchy)3 Unit (soot.Unit)3 AssignStmt (soot.jimple.AssignStmt)3