Search in sources :

Example 21 with InstanceInvokeExpr

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

the class SuperFirstStmtHandler method changeOriginalAST.

/*
	 * Remove the entire body and replace with the statement this(args1,
	 * B.preInit(args1));
	 */
public boolean changeOriginalAST() {
    // argsOne followed by a method call to preInit
    if (originalConstructorExpr == null) {
        // System.out.println("originalConstructorExpr is null");
        return false;
    }
    List thisArgList = new ArrayList();
    thisArgList.addAll(argsOneValues);
    DStaticInvokeExpr newInvokeExpr = new DStaticInvokeExpr(newSootPreInitMethod.makeRef(), argsOneValues);
    thisArgList.add(newInvokeExpr);
    // the methodRef of themethod to be called is the new constructor we
    // created
    InstanceInvokeExpr tempExpr = new DSpecialInvokeExpr(originalConstructorExpr.getBase(), newConstructor.makeRef(), thisArgList);
    originalDavaBody.set_ConstructorExpr(tempExpr);
    // create Invoke Stmt with tempExpr as the expression
    GInvokeStmt s = new GInvokeStmt(tempExpr);
    originalDavaBody.set_ConstructorUnit(s);
    // originalASTMethod has to be made empty
    originalASTMethod.setDeclarations(new ASTStatementSequenceNode(new ArrayList<AugmentedStmt>()));
    originalASTMethod.replaceBody(new ArrayList<Object>());
    return true;
}
Also used : DSpecialInvokeExpr(soot.dava.internal.javaRep.DSpecialInvokeExpr) DStaticInvokeExpr(soot.dava.internal.javaRep.DStaticInvokeExpr) GInvokeStmt(soot.grimp.internal.GInvokeStmt) ArrayList(java.util.ArrayList) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) List(java.util.List) ArrayList(java.util.ArrayList) ASTStatementSequenceNode(soot.dava.internal.AST.ASTStatementSequenceNode)

Example 22 with InstanceInvokeExpr

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

the class DalvikTyper method setInvokeType.

protected void setInvokeType(InvokeExpr invokeExpr) {
    for (int i = 0; i < invokeExpr.getArgCount(); i++) {
        Value v = invokeExpr.getArg(i);
        if (!(v instanceof Local))
            continue;
        Type t = invokeExpr.getMethodRef().parameterType(i);
        DalvikTyper.v().setType(invokeExpr.getArgBox(i), t, true);
    }
    if (invokeExpr instanceof StaticInvokeExpr) {
    // nothing to do
    } else if (invokeExpr instanceof InstanceInvokeExpr) {
        InstanceInvokeExpr iie = (InstanceInvokeExpr) invokeExpr;
        DalvikTyper.v().setType(iie.getBaseBox(), RefType.v("java.lang.Object"), true);
    } else if (invokeExpr instanceof DynamicInvokeExpr) {
        DynamicInvokeExpr die = (DynamicInvokeExpr) invokeExpr;
    // ?
    } else {
        throw new RuntimeException("error: unhandled invoke expression: " + invokeExpr + " " + invokeExpr.getClass());
    }
}
Also used : StaticInvokeExpr(soot.jimple.StaticInvokeExpr) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) ArrayType(soot.ArrayType) PrimType(soot.PrimType) Value(soot.Value) Local(soot.Local) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) DynamicInvokeExpr(soot.jimple.DynamicInvokeExpr)

Example 23 with InstanceInvokeExpr

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

the class LibraryMethodWrappersBuilder method internalTransform.

protected void internalTransform(String phaseName, Map<String, String> options) {
    if (isVerbose()) {
        logger.info("Building Library Wrapper Methods...");
    }
    BodyBuilder.retrieveAllBodies();
    // iterate through application classes to find library calls
    final Iterator<SootClass> applicationClassesIterator = Scene.v().getApplicationClasses().snapshotIterator();
    while (applicationClassesIterator.hasNext()) {
        final SootClass applicationClass = applicationClassesIterator.next();
        if (isVerbose()) {
            logger.info("\tProcessing class {}", applicationClass.getName());
        }
        // create local copy to prevent java.util.ConcurrentModificationException
        final List<SootMethod> methods = new ArrayList<>(applicationClass.getMethods());
        for (SootMethod method : methods) {
            if (!method.isConcrete() || builtByMe.contains(method)) {
                continue;
            }
            final Body body = getBodySafely(method);
            if (body == null) {
                continue;
            }
            int localName = 0;
            final Unit first = getFirstNotIdentityStmt(body);
            final Iterator<Unit> unitIterator = body.getUnits().snapshotIterator();
            while (unitIterator.hasNext()) {
                final Unit unit = unitIterator.next();
                for (ValueBox valueBox : unit.getUseBoxes()) {
                    final Value value = valueBox.getValue();
                    // outside (this is prohibited on language level as that would violate encapsulation)
                    if (!(value instanceof InvokeExpr) || value instanceof SpecialInvokeExpr) {
                        continue;
                    }
                    final InvokeExpr invokeExpr = (InvokeExpr) value;
                    final SootMethod invokedMethod = getMethodSafely(invokeExpr);
                    if (invokedMethod == null) {
                        continue;
                    }
                    SootMethodRef invokedMethodRef = getNewMethodRef(invokedMethod);
                    if (invokedMethodRef == null) {
                        invokedMethodRef = buildNewMethod(applicationClass, invokedMethod, invokeExpr);
                        setNewMethodRef(invokedMethod, invokedMethodRef);
                        newmethods++;
                    }
                    if (isVerbose()) {
                        logger.info("\t\t\tChanging {} to {}\tUnit: ", invokedMethod.getSignature(), invokedMethodRef.getSignature(), unit);
                    }
                    List<Value> args = invokeExpr.getArgs();
                    List<Type> parameterTypes = invokedMethodRef.parameterTypes();
                    int argsCount = args.size();
                    int paramCount = parameterTypes.size();
                    if (invokeExpr instanceof InstanceInvokeExpr || invokeExpr instanceof StaticInvokeExpr) {
                        if (invokeExpr instanceof InstanceInvokeExpr) {
                            argsCount++;
                            args.add(((InstanceInvokeExpr) invokeExpr).getBase());
                        }
                        while (argsCount < paramCount) {
                            Type pType = parameterTypes.get(argsCount);
                            Local newLocal = Jimple.v().newLocal("newLocal" + localName++, pType);
                            body.getLocals().add(newLocal);
                            body.getUnits().insertBeforeNoRedirect(Jimple.v().newAssignStmt(newLocal, getConstantType(pType)), first);
                            args.add(newLocal);
                            argsCount++;
                        }
                        valueBox.setValue(Jimple.v().newStaticInvokeExpr(invokedMethodRef, args));
                    }
                    methodcalls++;
                }
            }
        }
    }
    Scene.v().releaseActiveHierarchy();
    Scene.v().setFastHierarchy(new FastHierarchy());
}
Also used : SootMethodRef(soot.SootMethodRef) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) ArrayList(java.util.ArrayList) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) Local(soot.Local) SootClass(soot.SootClass) Unit(soot.Unit) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) VoidType(soot.VoidType) FastHierarchy(soot.FastHierarchy) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) InterfaceInvokeExpr(soot.jimple.InterfaceInvokeExpr) SpecialInvokeExpr(soot.jimple.SpecialInvokeExpr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) InvokeExpr(soot.jimple.InvokeExpr) ValueBox(soot.ValueBox) Value(soot.Value) SootMethod(soot.SootMethod) Body(soot.Body) JimpleBody(soot.jimple.JimpleBody)

Example 24 with InstanceInvokeExpr

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

the class OfflineProcessor method defaultFeedPtsRoutines.

public void defaultFeedPtsRoutines() {
    switch(Parameters.seedPts) {
        case Constants.seedPts_allUser:
            setAllUserCodeVariablesUseful();
            break;
        case Constants.seedPts_all:
            // All pointers will be processed
            for (int i = 0; i < n_var; ++i) {
                IVarAbstraction pn = int2var.get(i);
                if (pn != null && pn.getRepresentative() == pn)
                    pn.willUpdate = true;
            }
            return;
    }
    // We always refine the callsites that have multiple call targets
    Set<Node> multiBaseptrs = new HashSet<Node>();
    for (Stmt callsite : geomPTA.multiCallsites) {
        InstanceInvokeExpr iie = (InstanceInvokeExpr) callsite.getInvokeExpr();
        VarNode vn = geomPTA.findLocalVarNode(iie.getBase());
        multiBaseptrs.add(vn);
    }
    addUserDefPts(multiBaseptrs);
}
Also used : GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) VarNode(soot.jimple.spark.pag.VarNode) GlobalVarNode(soot.jimple.spark.pag.GlobalVarNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) InstanceInvokeExpr(soot.jimple.InstanceInvokeExpr) PlainConstraint(soot.jimple.spark.geom.dataRep.PlainConstraint) HashSet(java.util.HashSet) Stmt(soot.jimple.Stmt) AssignStmt(soot.jimple.AssignStmt)

Example 25 with InstanceInvokeExpr

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

InstanceInvokeExpr (soot.jimple.InstanceInvokeExpr)25 Value (soot.Value)13 InvokeExpr (soot.jimple.InvokeExpr)13 Stmt (soot.jimple.Stmt)12 Local (soot.Local)11 RefType (soot.RefType)11 SootMethod (soot.SootMethod)10 Type (soot.Type)9 StaticInvokeExpr (soot.jimple.StaticInvokeExpr)9 ArrayList (java.util.ArrayList)8 SootClass (soot.SootClass)8 Unit (soot.Unit)8 AssignStmt (soot.jimple.AssignStmt)8 VirtualInvokeExpr (soot.jimple.VirtualInvokeExpr)8 SpecialInvokeExpr (soot.jimple.SpecialInvokeExpr)7 ValueBox (soot.ValueBox)6 InvokeStmt (soot.jimple.InvokeStmt)6 Iterator (java.util.Iterator)5 SootMethodRef (soot.SootMethodRef)5 InterfaceInvokeExpr (soot.jimple.InterfaceInvokeExpr)5