Search in sources :

Example 56 with AllocNode

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

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

the class SparkLibraryHelper method caseRefType.

/**
 * A new local will be created and connected to
 * {@link SparkLibraryHelper#node} of type {@link RefType}. For this new
 * local an allocation edge to {@link AnySubType} of its declared type will
 * be added.
 */
@Override
public void caseRefType(RefType t) {
    // var tmp;
    VarNode local = pag.makeLocalVarNode(new Object(), t, method);
    // new T();
    AllocNode alloc = pag.makeAllocNode(new Object(), AnySubType.v(t), method);
    // tmp = new T();
    pag.addAllocEdge(alloc, local);
    // x = tmp;
    pag.addEdge(local, node);
}
Also used : LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode)

Example 58 with AllocNode

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

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

the class TypeManager method makeClassTypeMask.

private final BitVector makeClassTypeMask(SootClass clazz) {
    {
        BitVector cachedMask = typeMask.get(clazz.getType());
        if (cachedMask != null) {
            return cachedMask;
        }
    }
    int nBits = pag.getAllocNodeNumberer().size();
    final BitVector mask = new BitVector(nBits);
    List<AllocNode> allocs = null;
    if (clazz.isConcrete()) {
        allocs = class2allocs.get(clazz);
    }
    if (allocs != null) {
        for (AllocNode an : allocs) {
            mask.set(an.getNumber());
        }
    }
    Collection<SootClass> subclasses = fh.getSubclassesOf(clazz);
    if (subclasses == Collections.EMPTY_LIST) {
        for (AllocNode an : anySubtypeAllocs) {
            mask.set(an.getNumber());
        }
        typeMask.put(clazz.getType(), mask);
        return mask;
    }
    for (SootClass subcl : subclasses) {
        mask.or(makeClassTypeMask(subcl));
    }
    typeMask.put(clazz.getType(), mask);
    return mask;
}
Also used : BitVector(soot.util.BitVector) AllocNode(soot.jimple.spark.pag.AllocNode) SootClass(soot.SootClass)

Example 60 with AllocNode

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

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