Search in sources :

Example 6 with AnySubType

use of soot.AnySubType in project soot by Sable.

the class ThrowableSet method toAbbreviatedString.

/**
 * <p>
 * Utility method which prints the abbreviations of the elements in a passed
 * {@link Set} of exception types.
 * </p>
 *
 * @param s
 *            The exceptions to print.
 *
 * @param connector
 *            The character to insert between exceptions.
 *
 * @return An abbreviated representation of the exceptions.
 */
private String toAbbreviatedString(Set<? extends RefLikeType> s, char connector) {
    final String JAVA_LANG = "java.lang.";
    final String EXCEPTION = "Exception";
    Collection<RefLikeType> vmErrorThrowables = ThrowableSet.Manager.v().VM_ERRORS.exceptionsIncluded;
    boolean containsAllVmErrors = s.containsAll(vmErrorThrowables);
    StringBuffer buf = new StringBuffer();
    if (containsAllVmErrors) {
        buf.append(connector);
        buf.append("vmErrors");
    }
    for (Iterator<? extends RefLikeType> it = sortedThrowableIterator(s); it.hasNext(); ) {
        RefLikeType reflikeType = it.next();
        RefType baseType = null;
        if (reflikeType instanceof RefType) {
            baseType = (RefType) reflikeType;
            if (containsAllVmErrors && vmErrorThrowables.contains(baseType)) {
                // Already accounted for vmErrors.
                continue;
            } else {
                buf.append(connector);
            }
        } else if (reflikeType instanceof AnySubType) {
            buf.append(connector);
            buf.append('(');
            baseType = ((AnySubType) reflikeType).getBase();
        } else
            throw new RuntimeException("Unsupported type " + reflikeType.getClass().getName());
        String typeName = baseType.toString();
        int start = 0;
        int end = typeName.length();
        if (typeName.startsWith(JAVA_LANG)) {
            start += JAVA_LANG.length();
        }
        if (typeName.endsWith(EXCEPTION)) {
            end -= EXCEPTION.length();
        }
        buf.append(typeName, start, end);
        if (reflikeType instanceof AnySubType) {
            buf.append(')');
        }
    }
    return buf.toString();
}
Also used : RefLikeType(soot.RefLikeType) RefType(soot.RefType) AnySubType(soot.AnySubType)

Example 7 with AnySubType

use of soot.AnySubType in project soot by Sable.

the class EvalResults method test_1cfa_call_graph.

/**
 * We assess the quality of building the 1-cfa call graph with the geometric
 * points-to result.
 */
private void test_1cfa_call_graph(LocalVarNode vn, SootMethod caller, SootMethod callee_signature, Histogram ce_range) {
    long l, r;
    IVarAbstraction pn = ptsProvider.findInternalNode(vn);
    if (pn == null)
        return;
    pn = pn.getRepresentative();
    Set<SootMethod> tgts = new HashSet<SootMethod>();
    Set<AllocNode> set = pn.get_all_points_to_objects();
    LinkedList<CgEdge> list = ptsProvider.getCallEdgesInto(ptsProvider.getIDFromSootMethod(caller));
    FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();
    for (Iterator<CgEdge> it = list.iterator(); it.hasNext(); ) {
        CgEdge p = it.next();
        l = p.map_offset;
        r = l + ptsProvider.max_context_size_block[p.s];
        tgts.clear();
        for (AllocNode obj : set) {
            if (!pn.pointer_interval_points_to(l, r, obj))
                continue;
            Type t = obj.getType();
            if (t == null)
                continue;
            else if (t instanceof AnySubType)
                t = ((AnySubType) t).getBase();
            else if (t instanceof ArrayType)
                t = RefType.v("java.lang.Object");
            try {
                tgts.add(hierarchy.resolveConcreteDispatch(((RefType) t).getSootClass(), callee_signature));
            } catch (Exception e) {
            }
        }
        tgts.remove(null);
        ce_range.addNumber(tgts.size());
    }
}
Also used : CgEdge(soot.jimple.spark.geom.dataRep.CgEdge) ArrayType(soot.ArrayType) RefType(soot.RefType) FastHierarchy(soot.FastHierarchy) RefType(soot.RefType) AnySubType(soot.AnySubType) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) Type(soot.Type) AllocNode(soot.jimple.spark.pag.AllocNode) IVarAbstraction(soot.jimple.spark.geom.geomPA.IVarAbstraction) SootMethod(soot.SootMethod) AnySubType(soot.AnySubType) HashSet(java.util.HashSet)

Example 8 with AnySubType

use of soot.AnySubType in project soot by Sable.

the class DemandCSPointsTo method getCallTargetsForType.

protected Set<SootMethod> getCallTargetsForType(Type type, NumberedString methodStr, Type receiverType, Set<SootMethod> possibleTargets) {
    if (!pag.getTypeManager().castNeverFails(type, receiverType))
        return Collections.<SootMethod>emptySet();
    if (type instanceof AnySubType) {
        AnySubType any = (AnySubType) type;
        RefType refType = any.getBase();
        if (pag.getTypeManager().getFastHierarchy().canStoreType(receiverType, refType) || pag.getTypeManager().getFastHierarchy().canStoreType(refType, receiverType)) {
            return possibleTargets;
        } else {
            return Collections.<SootMethod>emptySet();
        }
    }
    if (type instanceof ArrayType) {
        // we'll invoke the java.lang.Object method in this
        // case
        // Assert.chk(varNodeType.toString().equals("java.lang.Object"));
        type = Scene.v().getSootClass("java.lang.Object").getType();
    }
    RefType refType = (RefType) type;
    SootMethod targetMethod = null;
    targetMethod = VirtualCalls.v().resolveNonSpecial(refType, methodStr);
    return Collections.<SootMethod>singleton(targetMethod);
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType) SootMethod(soot.SootMethod) AnySubType(soot.AnySubType)

Example 9 with AnySubType

use of soot.AnySubType 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 10 with AnySubType

use of soot.AnySubType 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

AnySubType (soot.AnySubType)11 RefType (soot.RefType)10 RefLikeType (soot.RefLikeType)9 ArrayType (soot.ArrayType)5 FastHierarchy (soot.FastHierarchy)5 HashSet (java.util.HashSet)4 Type (soot.Type)4 AllocNode (soot.jimple.spark.pag.AllocNode)4 Iterator (java.util.Iterator)2 NullType (soot.NullType)2 SootClass (soot.SootClass)2 SootMethod (soot.SootMethod)2 Node (soot.jimple.spark.pag.Node)2 BitVector (soot.util.BitVector)2 Set (java.util.Set)1 Test (org.junit.Test)1 Local (soot.Local)1 ArrayRef (soot.jimple.ArrayRef)1 IfStmt (soot.jimple.IfStmt)1 Stmt (soot.jimple.Stmt)1