Search in sources :

Example 16 with NullConstant

use of soot.jimple.NullConstant in project soot by Sable.

the class CollectConstants method addInitializingValue.

private void addInitializingValue(SootClass sc, SootField f, Constant constant) {
    if (constant instanceof NullConstant) {
        return;
    } else if (constant instanceof IntConstant) {
        if (((IntConstant) constant).value == 0)
            return;
    } else if (constant instanceof LongConstant) {
        if (((LongConstant) constant).value == 0)
            return;
    } else if (constant instanceof StringConstant) {
        if (((StringConstant) constant).value == null)
            return;
    } else if (constant instanceof DoubleConstant) {
        if (((DoubleConstant) constant).value == 0)
            return;
    } else if (constant instanceof FloatConstant) {
        if (((FloatConstant) constant).value == 0)
            return;
    }
    Body b;
    boolean newInit = false;
    if (!sc.declaresMethodByName(SootMethod.staticInitializerName)) {
        SootMethod m = Scene.v().makeSootMethod(SootMethod.staticInitializerName, emptyList(), VoidType.v(), Modifier.STATIC);
        sc.addMethod(m);
        b = Jimple.v().newBody(m);
        m.setActiveBody(b);
        newInit = true;
    } else {
        SootMethod m = sc.getMethodByName(SootMethod.staticInitializerName);
        if (!m.hasActiveBody()) {
            b = Jimple.v().newBody(m);
            m.setActiveBody(b);
            newInit = true;
        } else {
            b = m.getActiveBody();
        }
    }
    PatchingChain<Unit> units = b.getUnits();
    units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(f.makeRef()), constant));
    if (newInit)
        units.addLast(Jimple.v().newReturnVoidStmt());
}
Also used : LongConstant(soot.jimple.LongConstant) DoubleConstant(soot.jimple.DoubleConstant) FloatConstant(soot.jimple.FloatConstant) NullConstant(soot.jimple.NullConstant) IntConstant(soot.jimple.IntConstant) SootMethod(soot.SootMethod) StringConstant(soot.jimple.StringConstant) Unit(soot.Unit) Body(soot.Body)

Example 17 with NullConstant

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

NullConstant (soot.jimple.NullConstant)17 Value (soot.Value)15 Local (soot.Local)13 IntConstant (soot.jimple.IntConstant)13 LongConstant (soot.jimple.LongConstant)11 BinopExpr (soot.jimple.BinopExpr)10 StringConstant (soot.jimple.StringConstant)10 Type (soot.Type)9 DoubleConstant (soot.jimple.DoubleConstant)9 FloatConstant (soot.jimple.FloatConstant)9 NullType (soot.NullType)8 ClassConstant (soot.jimple.ClassConstant)8 ArrayType (soot.ArrayType)7 ArrayRef (soot.jimple.ArrayRef)7 CastExpr (soot.jimple.CastExpr)7 InvokeExpr (soot.jimple.InvokeExpr)7 NewArrayExpr (soot.jimple.NewArrayExpr)7 Unit (soot.Unit)6 EqExpr (soot.jimple.EqExpr)6 InstanceFieldRef (soot.jimple.InstanceFieldRef)6