Search in sources :

Example 1 with GInvokeStmt

use of soot.grimp.internal.GInvokeStmt 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 2 with GInvokeStmt

use of soot.grimp.internal.GInvokeStmt in project soot by Sable.

the class SuperFirstStmtHandler method createAugmentedStmtToAdd.

private AugmentedStmt createAugmentedStmtToAdd(Local newLocal, SootMethodRef getMethodRef, Value tempVal) {
    ArrayList tempArgList = new ArrayList();
    tempArgList.add(tempVal);
    DVirtualInvokeExpr tempInvokeExpr = new DVirtualInvokeExpr(newLocal, getMethodRef, tempArgList, new HashSet<Object>());
    // create Invoke Stmt with virtualInvoke as the expression
    GInvokeStmt s = new GInvokeStmt(tempInvokeExpr);
    return new AugmentedStmt(s);
}
Also used : DVirtualInvokeExpr(soot.dava.internal.javaRep.DVirtualInvokeExpr) GInvokeStmt(soot.grimp.internal.GInvokeStmt) ArrayList(java.util.ArrayList) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt)

Example 3 with GInvokeStmt

use of soot.grimp.internal.GInvokeStmt 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 4 with GInvokeStmt

use of soot.grimp.internal.GInvokeStmt 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

ArrayList (java.util.ArrayList)4 GInvokeStmt (soot.grimp.internal.GInvokeStmt)4 DVirtualInvokeExpr (soot.dava.internal.javaRep.DVirtualInvokeExpr)3 List (java.util.List)2 AugmentedStmt (soot.dava.internal.asg.AugmentedStmt)2 DStaticInvokeExpr (soot.dava.internal.javaRep.DStaticInvokeExpr)2 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 BooleanType (soot.BooleanType)1 ByteType (soot.ByteType)1 CharType (soot.CharType)1 DoubleType (soot.DoubleType)1 FloatType (soot.FloatType)1 IntType (soot.IntType)1 Local (soot.Local)1 LongType (soot.LongType)1 PrimType (soot.PrimType)1 RefType (soot.RefType)1 ShortType (soot.ShortType)1 SootClass (soot.SootClass)1