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;
}
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);
}
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;
}
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>())));
}
}
Aggregations