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