Search in sources :

Example 1 with MethodNodeFactory

use of soot.jimple.spark.builder.MethodNodeFactory in project soot by Sable.

the class PAG method addCallTarget.

/**
 * Adds method target as a possible target of the invoke expression in s. If
 * target is null, only creates the nodes for the call site, without actually
 * connecting them to any target method.
 */
public final void addCallTarget(MethodPAG srcmpag, MethodPAG tgtmpag, Stmt s, Context srcContext, Context tgtContext, Edge e) {
    MethodNodeFactory srcnf = srcmpag.nodeFactory();
    MethodNodeFactory tgtnf = tgtmpag.nodeFactory();
    InvokeExpr ie = s.getInvokeExpr();
    boolean virtualCall = callAssigns.containsKey(ie);
    int numArgs = ie.getArgCount();
    for (int i = 0; i < numArgs; i++) {
        Value arg = ie.getArg(i);
        if (!(arg.getType() instanceof RefLikeType))
            continue;
        if (arg instanceof NullConstant)
            continue;
        Node argNode = srcnf.getNode(arg);
        argNode = srcmpag.parameterize(argNode, srcContext);
        argNode = argNode.getReplacement();
        Node parm = tgtnf.caseParm(i);
        parm = tgtmpag.parameterize(parm, tgtContext);
        parm = parm.getReplacement();
        addEdge(argNode, parm);
        Pair<Node, Node> pval = addInterproceduralAssignment(argNode, parm, e);
        callAssigns.put(ie, pval);
        callToMethod.put(ie, srcmpag.getMethod());
    }
    if (ie instanceof InstanceInvokeExpr) {
        InstanceInvokeExpr iie = (InstanceInvokeExpr) ie;
        Node baseNode = srcnf.getNode(iie.getBase());
        baseNode = srcmpag.parameterize(baseNode, srcContext);
        baseNode = baseNode.getReplacement();
        Node thisRef = tgtnf.caseThis();
        thisRef = tgtmpag.parameterize(thisRef, tgtContext);
        thisRef = thisRef.getReplacement();
        addEdge(baseNode, thisRef);
        Pair<Node, Node> pval = addInterproceduralAssignment(baseNode, thisRef, e);
        callAssigns.put(ie, pval);
        callToMethod.put(ie, srcmpag.getMethod());
        if (virtualCall && !virtualCallsToReceivers.containsKey(ie)) {
            virtualCallsToReceivers.put(ie, baseNode);
        }
    }
    if (s instanceof AssignStmt) {
        Value dest = ((AssignStmt) s).getLeftOp();
        if (dest.getType() instanceof RefLikeType && !(dest instanceof NullConstant)) {
            Node destNode = srcnf.getNode(dest);
            destNode = srcmpag.parameterize(destNode, srcContext);
            destNode = destNode.getReplacement();
            Node retNode = tgtnf.caseRet();
            retNode = tgtmpag.parameterize(retNode, tgtContext);
            retNode = retNode.getReplacement();
            addEdge(retNode, destNode);
            Pair<Node, Node> pval = addInterproceduralAssignment(retNode, destNode, e);
            callAssigns.put(ie, pval);
            callToMethod.put(ie, srcmpag.getMethod());
        }
    }
}
Also used : RefLikeType(soot.RefLikeType) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) AssignStmt(soot.jimple.AssignStmt) Value(soot.Value) NullConstant(soot.jimple.NullConstant) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) MethodNodeFactory(soot.jimple.spark.builder.MethodNodeFactory)

Aggregations

RefLikeType (soot.RefLikeType)1 Value (soot.Value)1 AssignStmt (soot.jimple.AssignStmt)1 InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)1 InvokeExpr (soot.jimple.InvokeExpr)1 NullConstant (soot.jimple.NullConstant)1 VirtualInvokeExpr (soot.jimple.VirtualInvokeExpr)1 MethodNodeFactory (soot.jimple.spark.builder.MethodNodeFactory)1