Search in sources :

Example 56 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class MultiCalledMethods method byMCalledS0.

private void byMCalledS0(PegCallGraph pcg) {
    Iterator it = pcg.iterator();
    while (it.hasNext()) {
        SootMethod sm = (SootMethod) it.next();
        UnitGraph graph = new CompleteUnitGraph(sm.getActiveBody());
        CallGraph callGraph = Scene.v().getCallGraph();
        MultiRunStatementsFinder finder = new MultiRunStatementsFinder(graph, sm, multiCalledMethods, callGraph);
        FlowSet fs = finder.getMultiRunStatements();
    }
}
Also used : UnitGraph(soot.toolkits.graph.UnitGraph) CompleteUnitGraph(soot.toolkits.graph.CompleteUnitGraph) CallGraph(soot.jimple.toolkits.callgraph.CallGraph) PegCallGraph(soot.jimple.toolkits.thread.mhp.pegcallgraph.PegCallGraph) FlowSet(soot.toolkits.scalar.FlowSet) SootMethod(soot.SootMethod) CompleteUnitGraph(soot.toolkits.graph.CompleteUnitGraph)

Example 57 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class PtInsNode method get_all_context_sensitive_objects.

@Override
public void get_all_context_sensitive_objects(long l, long r, PtSensVisitor visitor) {
    if (parent != this) {
        getRepresentative().get_all_context_sensitive_objects(l, r, visitor);
        return;
    }
    GeomPointsTo geomPTA = (GeomPointsTo) Scene.v().getPointsToAnalysis();
    for (Map.Entry<AllocNode, PtInsIntervalManager> entry : pt_objs.entrySet()) {
        AllocNode obj = entry.getKey();
        PtInsIntervalManager im = entry.getValue();
        SegmentNode[] int_entry = im.getFigures();
        // We first get the 1-CFA contexts for the object
        SootMethod sm = obj.getMethod();
        int sm_int = 0;
        long n_contexts = 1;
        if (sm != null) {
            sm_int = geomPTA.getIDFromSootMethod(sm);
            n_contexts = geomPTA.context_size[sm_int];
        }
        // We search for all the pointers falling in the range [1, r) that may point to this object
        for (int i = 0; i < PtInsIntervalManager.Divisions; ++i) {
            SegmentNode p = int_entry[i];
            while (p != null) {
                long R = p.I1 + p.L;
                long objL = -1, objR = -1;
                // Now we compute which context sensitive objects are pointed to by this pointer
                if (i == PtInsIntervalManager.ALL_TO_MANY) {
                    // all-to-many figures
                    objL = p.I2;
                    objR = p.I2 + p.L;
                } else {
                    // We compute the intersection
                    if (l <= p.I1 && p.I1 < r) {
                        if (i != PtInsIntervalManager.MANY_TO_ALL) {
                            long d = r - p.I1;
                            if (d > p.L)
                                d = p.L;
                            objL = p.I2;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    } else if (p.I1 <= l && l < R) {
                        if (i != PtInsIntervalManager.MANY_TO_ALL) {
                            long d = R - l;
                            if (R > r)
                                d = r - l;
                            objL = p.I2 + l - p.I1;
                            objR = objL + d;
                        } else {
                            objL = 1;
                            objR = 1 + n_contexts;
                        }
                    }
                }
                // Now we test which context versions should this interval [objL, objR) maps to
                if (objL != -1 && objR != -1)
                    visitor.visit(obj, objL, objR, sm_int);
                p = p.next;
            }
        }
    }
}
Also used : AllocNode(soot.jimple.spark.pag.AllocNode) GeomPointsTo(soot.jimple.spark.geom.geomPA.GeomPointsTo) SootMethod(soot.SootMethod) HashMap(java.util.HashMap) Map(java.util.Map) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) SegmentNode(soot.jimple.spark.geom.dataRep.SegmentNode)

Example 58 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class SparkTransformer method addTags.

protected void addTags(PAG pag) {
    final Tag unknown = new StringTag("Untagged Spark node");
    final Map<Node, Tag> nodeToTag = pag.getNodeTags();
    for (final SootClass c : Scene.v().getClasses()) {
        for (final SootMethod m : c.getMethods()) {
            if (!m.isConcrete())
                continue;
            if (!m.hasActiveBody())
                continue;
            for (final Unit u : m.getActiveBody().getUnits()) {
                final Stmt s = (Stmt) u;
                if (s instanceof DefinitionStmt) {
                    Value lhs = ((DefinitionStmt) s).getLeftOp();
                    VarNode v = null;
                    if (lhs instanceof Local) {
                        v = pag.findLocalVarNode(lhs);
                    } else if (lhs instanceof FieldRef) {
                        v = pag.findGlobalVarNode(((FieldRef) lhs).getField());
                    }
                    if (v != null) {
                        PointsToSetInternal p2set = v.getP2Set();
                        p2set.forall(new P2SetVisitor() {

                            public final void visit(Node n) {
                                addTag(s, n, nodeToTag, unknown);
                            }
                        });
                        Node[] simpleSources = pag.simpleInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.allocInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                        simpleSources = pag.loadInvLookup(v);
                        for (Node element : simpleSources) {
                            addTag(s, element, nodeToTag, unknown);
                        }
                    }
                }
            }
        }
    }
}
Also used : StringTag(soot.tagkit.StringTag) VarNode(soot.jimple.spark.pag.VarNode) FieldRef(soot.jimple.FieldRef) PointsToSetInternal(soot.jimple.spark.sets.PointsToSetInternal) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Local(soot.Local) SootClass(soot.SootClass) Unit(soot.Unit) Stmt(soot.jimple.Stmt) DefinitionStmt(soot.jimple.DefinitionStmt) Value(soot.Value) SootMethod(soot.SootMethod) Tag(soot.tagkit.Tag) StringTag(soot.tagkit.StringTag) DefinitionStmt(soot.jimple.DefinitionStmt) P2SetVisitor(soot.jimple.spark.sets.P2SetVisitor)

Example 59 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class GeomQueries method kCFA.

/**
 * Standard K-CFA querying for arbitrary K.
 *
 * @param callEdgeChain: last K call edges leading to the method that contains l. callEdgeChain[0] is the farthest call edge in the chain.
 * @param l: the querying pointer
 * @param visitor: the querying result container
 * @return false, l does not have points-to information under the given context
 */
@SuppressWarnings("rawtypes")
public boolean kCFA(Edge[] callEdgeChain, Local l, PtSensVisitor visitor) {
    // Prepare for initial contexts
    SootMethod firstMethod = callEdgeChain[0].src();
    int firstMethodID = geomPTA.getIDFromSootMethod(firstMethod);
    if (firstMethodID == -1)
        return false;
    // Obtain the internal representation for querying pointer
    LocalVarNode vn = geomPTA.findLocalVarNode(l);
    if (vn == null) {
        // Normally this could not happen, perhaps it's a bug
        return false;
    }
    IVarAbstraction pn = geomPTA.findInternalNode(vn);
    if (pn == null) {
        // This pointer is no longer reachable
        return false;
    }
    pn = pn.getRepresentative();
    if (!pn.hasPTResult())
        return false;
    SootMethod sm = vn.getMethod();
    if (geomPTA.getIDFromSootMethod(sm) == -1)
        return false;
    // Iterate the call edges and compute the contexts mapping iteratively
    visitor.prepare();
    long L = 1;
    for (int i = 0; i < callEdgeChain.length; ++i) {
        Edge sootEdge = callEdgeChain[i];
        CgEdge ctxt = geomPTA.getInternalEdgeFromSootEdge(sootEdge);
        if (ctxt == null || ctxt.is_obsoleted == true)
            return false;
        // Following searching procedure works for both methods in SCC and out of SCC
        // with blocking scheme or without blocking scheme
        int caller = geomPTA.getIDFromSootMethod(sootEdge.src());
        // We obtain the block that contains current offset L
        long block_size = max_context_size_block[rep_cg[caller]];
        long in_block_offset = (L - 1) % block_size;
        // Transfer to the target block with the same in-block offset
        L = ctxt.map_offset + in_block_offset;
    }
    long ctxtLength = max_context_size_block[rep_cg[firstMethodID]];
    long R = L + ctxtLength;
    pn.get_all_context_sensitive_objects(L, R, visitor);
    visitor.finish();
    return visitor.numOfDiffObjects() != 0;
}
Also used : CgEdge(soot.jimple.spark.geom.dataRep.CgEdge) SootMethod(soot.SootMethod) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) CgEdge(soot.jimple.spark.geom.dataRep.CgEdge) Edge(soot.jimple.toolkits.callgraph.Edge)

Example 60 with SootMethod

use of soot.SootMethod in project soot by Sable.

the class GeomQueries method contextsGoBy.

/**
 * Answer contexts-go-by query.
 *
 * Usually, users specify the last K paths as the context. We call it k-CFA context.
 * However, k-CFA is too restrictive.
 * In contexts-go-by query, user specifies arbitrary call edge in the call graph.
 * The query searches for all contexts induced by the specified call edge and collect points-to results under these contexts.
 *
 * @param sootEdge: the specified context edge in soot edge format
 * @param l: the querying pointer
 * @param visitor: container for querying result
 * @return false, l does not have points-to information under the contexts induced by the given call edge
 */
@SuppressWarnings("rawtypes")
public boolean contextsGoBy(Edge sootEdge, Local l, PtSensVisitor visitor) {
    // Obtain the internal representation of specified context
    CgEdge ctxt = geomPTA.getInternalEdgeFromSootEdge(sootEdge);
    if (ctxt == null || ctxt.is_obsoleted == true)
        return false;
    // Obtain the internal representation for querying pointer
    LocalVarNode vn = geomPTA.findLocalVarNode(l);
    if (vn == null) {
        // Normally this could not happen, perhaps it's a bug
        return false;
    }
    IVarAbstraction pn = geomPTA.findInternalNode(vn);
    if (pn == null) {
        // This pointer is no longer reachable
        return false;
    }
    pn = pn.getRepresentative();
    if (!pn.hasPTResult())
        return false;
    // Obtain the internal representation of the method that encloses the querying pointer
    SootMethod sm = vn.getMethod();
    int target = geomPTA.getIDFromSootMethod(sm);
    if (target == -1)
        return false;
    // Start call graph traversal
    long L = ctxt.map_offset;
    long R = L + max_context_size_block[rep_cg[ctxt.s]];
    assert L < R;
    visitor.prepare();
    prepareIntervalPropagations();
    if (propagateIntervals(ctxt.t, L, R, target)) {
        // We calculate the points-to results
        ContextsCollector targetContexts = contextsForMethods[target];
        for (SimpleInterval si : targetContexts.bars) {
            assert si.L < si.R;
            pn.get_all_context_sensitive_objects(si.L, si.R, visitor);
        }
        // Reset
        targetContexts.clear();
    }
    visitor.finish();
    return visitor.numOfDiffObjects() != 0;
}
Also used : CgEdge(soot.jimple.spark.geom.dataRep.CgEdge) SootMethod(soot.SootMethod) SimpleInterval(soot.jimple.spark.geom.dataRep.SimpleInterval) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) ContextsCollector(soot.jimple.spark.geom.dataMgr.ContextsCollector)

Aggregations

SootMethod (soot.SootMethod)237 SootClass (soot.SootClass)95 RefType (soot.RefType)56 ArrayList (java.util.ArrayList)49 Type (soot.Type)47 Unit (soot.Unit)47 Value (soot.Value)36 Stmt (soot.jimple.Stmt)35 Test (org.junit.Test)34 Local (soot.Local)34 Body (soot.Body)32 VoidType (soot.VoidType)31 PrimType (soot.PrimType)28 SootField (soot.SootField)28 BooleanType (soot.BooleanType)26 Iterator (java.util.Iterator)23 DoubleType (soot.DoubleType)23 FloatType (soot.FloatType)23 LongType (soot.LongType)23 InvokeExpr (soot.jimple.InvokeExpr)23