Search in sources :

Example 6 with DVirtualInvokeExpr

use of soot.dava.internal.javaRep.DVirtualInvokeExpr in project soot by Sable.

the class SuperFirstStmtHandler method createCallToSuper.

/*
	 * super( (CAST-TYPE)handler.get(0),
	 * ((CAST-TYPE)handler.get(1)).CONVERSION(), .......);
	 * 
	 * returns false if we cant create the call to super
	 */
private boolean createCallToSuper() {
    // check that whether this call is even to be made or not
    if (originalConstructorExpr == null) {
        // System.out.println("originalConstructorExpr is null");
        return false;
    }
    // System.out.println("ConstructorExpr is non null...call to super has
    // to be made");
    // find the parent class of the current method being decompiled
    SootClass parentClass = originalSootClass.getSuperclass();
    // super method
    if (!(parentClass.declaresMethod("<init>", argsTwoTypes))) {
        // this name and ParamTypes");
        return false;
    }
    SootMethod superConstructor = parentClass.getMethod("<init>", argsTwoTypes);
    // create InstanceInvokeExpr
    // need Value base: this??
    // need SootMethod Ref...make sootmethoref of the super constructor
    // found
    // need list of thisLocals.........try empty arrayList since it doesnt
    // seem to be used anywhere??
    List argsForConstructor = new ArrayList();
    int count = 0;
    // have to make arg as "handler.get(0)"
    // create new ReftType for DavaSuperHandler
    RefType type = (new SootClass("DavaSuperHandler")).getType();
    // make JimpleLocal to be used in each arg
    // takes care of
    Local jimpleLocal = new JimpleLocal("handler", type);
    // handler
    // make reference to a method of name get takes one int arg belongs to
    // DavaSuperHandler
    ArrayList tempList = new ArrayList();
    tempList.add(IntType.v());
    SootMethodRef getMethodRef = makeMethodRef("get", tempList);
    List tempArgList = null;
    Iterator typeIt = argsTwoTypes.iterator();
    while (typeIt.hasNext()) {
        Type tempType = (Type) typeIt.next();
        // takes care
        DIntConstant arg = DIntConstant.v(count, IntType.v());
        // of the
        // index
        count++;
        tempArgList = new ArrayList();
        tempArgList.add(arg);
        DVirtualInvokeExpr tempInvokeExpr = new DVirtualInvokeExpr(jimpleLocal, getMethodRef, tempArgList, new HashSet<Object>());
        // NECESASARY CASTING OR RETRIEVAL OF PRIM TYPES TO BE DONE HERE
        Value toAddExpr = getProperCasting(tempType, tempInvokeExpr);
        if (toAddExpr == null)
            throw new DecompilationException("UNABLE TO CREATE TOADDEXPR:" + tempType);
        // the above virtualInvokeExpr is one of the args for the
        // constructor
        argsForConstructor.add(toAddExpr);
    }
    mustInitializeIndex = count;
    // we are done with creating all necessary args to the virtualinvoke
    // expr constructor
    DVirtualInvokeExpr virtualInvoke = new DVirtualInvokeExpr(originalConstructorExpr.getBase(), superConstructor.makeRef(), argsForConstructor, new HashSet<Object>());
    // set the constructors constructorExpr
    newConstructorDavaBody.set_ConstructorExpr(virtualInvoke);
    // create Invoke Stmt with virtualInvoke as the expression
    GInvokeStmt s = new GInvokeStmt(virtualInvoke);
    newConstructorDavaBody.set_ConstructorUnit(s);
    // return true if super call created
    return true;
}
Also used : SootMethodRef(soot.SootMethodRef) ArrayList(java.util.ArrayList) JimpleLocal(soot.jimple.internal.JimpleLocal) Local(soot.Local) DecompilationException(soot.dava.DecompilationException) SootClass(soot.SootClass) JimpleLocal(soot.jimple.internal.JimpleLocal) RefType(soot.RefType) DVirtualInvokeExpr(soot.dava.internal.javaRep.DVirtualInvokeExpr) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) PrimType(soot.PrimType) VoidType(soot.VoidType) DIntConstant(soot.dava.internal.javaRep.DIntConstant) GInvokeStmt(soot.grimp.internal.GInvokeStmt) Iterator(java.util.Iterator) Value(soot.Value) SootMethod(soot.SootMethod) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with DVirtualInvokeExpr

use of soot.dava.internal.javaRep.DVirtualInvokeExpr in project soot by Sable.

the class MonitorConverter method convert.

public void convert(DavaBody body) {
    for (AugmentedStmt mas : body.get_MonitorFacts()) {
        MonitorStmt ms = (MonitorStmt) mas.get_Stmt();
        body.addToImportList("soot.dava.toolkits.base.DavaMonitor.DavaMonitor");
        ArrayList arg = new ArrayList();
        arg.add(ms.getOp());
        if (ms instanceof EnterMonitorStmt)
            mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), enter.makeRef(), arg, new HashSet<Object>())));
        else
            mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), exit.makeRef(), arg, new HashSet<Object>())));
    }
}
Also used : DVirtualInvokeExpr(soot.dava.internal.javaRep.DVirtualInvokeExpr) GInvokeStmt(soot.grimp.internal.GInvokeStmt) DStaticInvokeExpr(soot.dava.internal.javaRep.DStaticInvokeExpr) ArrayList(java.util.ArrayList) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) MonitorStmt(soot.jimple.MonitorStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) EnterMonitorStmt(soot.jimple.EnterMonitorStmt) HashSet(java.util.HashSet)

Aggregations

DVirtualInvokeExpr (soot.dava.internal.javaRep.DVirtualInvokeExpr)7 ArrayList (java.util.ArrayList)6 Value (soot.Value)5 RefType (soot.RefType)4 SootMethodRef (soot.SootMethodRef)4 GInvokeStmt (soot.grimp.internal.GInvokeStmt)4 List (java.util.List)3 PrimType (soot.PrimType)3 SootClass (soot.SootClass)3 DecompilationException (soot.dava.DecompilationException)3 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)3 DIntConstant (soot.dava.internal.javaRep.DIntConstant)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 BooleanType (soot.BooleanType)2 ByteType (soot.ByteType)2 CharType (soot.CharType)2 DoubleType (soot.DoubleType)2 FloatType (soot.FloatType)2 IntType (soot.IntType)2