Skip to content

Commit 5dbe46d

Browse files
authored
Merge pull request #707 from MarcMil/extensibility
Fix ICC redirect for content providers
2 parents 15db1f2 + 5ffe931 commit 5dbe46d

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

soot-infoflow-android/src/soot/jimple/infoflow/android/iccta/IccRedirectionCreator.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import soot.Value;
2626
import soot.ValueBox;
2727
import soot.VoidType;
28+
import soot.jimple.AssignStmt;
2829
import soot.jimple.InstanceInvokeExpr;
2930
import soot.jimple.IntConstant;
3031
import soot.jimple.InvokeExpr;
@@ -362,7 +363,8 @@ protected SootMethod generateRedirectMethodForBindService(SootClass serviceConne
362363
return newSM;
363364
}
364365

365-
protected SootMethod generateRedirectMethodForContentProvider(Stmt iccStmt, SootClass destProvider) {
366+
protected SootMethod generateRedirectMethodForContentProvider(Stmt iccStmt, SootMethod destCPMethod) {
367+
final SootClass destCPClass = destCPMethod.getDeclaringClass();
366368
SootMethod iccMethod = iccStmt.getInvokeExpr().getMethod();
367369
String newSM_name = "redirector" + num++;
368370
SootMethod newSM = Scene.v().makeSootMethod(newSM_name, iccMethod.getParameterTypes(),
@@ -384,21 +386,21 @@ protected SootMethod generateRedirectMethodForContentProvider(Stmt iccStmt, Soot
384386
}
385387

386388
// new
387-
Local al = lg.generateLocal(destProvider.getType());
388-
b.getUnits().add(Jimple.v().newAssignStmt(al, Jimple.v().newNewExpr(destProvider.getType())));
389+
Local al = lg.generateLocal(destCPClass.getType());
390+
b.getUnits().add(Jimple.v().newAssignStmt(al, Jimple.v().newNewExpr(destCPClass.getType())));
389391

390392
// init
391393
List<Type> parameters = new ArrayList<Type>();
392394
List<Value> args = new ArrayList<Value>();
393-
SootMethod method = destProvider.getMethod("<init>", parameters, VoidType.v());
395+
SootMethod method = destCPClass.getMethod("<init>", parameters, VoidType.v());
394396
b.getUnits().add(Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args)));
395397

396398
Local rtLocal = lg.generateLocal(iccMethod.getReturnType());
397399

398400
// call related method and assign the result to return local, may
399401
// optimize it to dummyMain method as well
400402
parameters = iccMethod.getParameterTypes();
401-
method = destProvider.getMethodByName(iccMethod.getName());
403+
method = destCPMethod;
402404
InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef(), locals);
403405
b.getUnits().add(Jimple.v().newAssignStmt(rtLocal, invoke));
404406

@@ -447,19 +449,9 @@ protected void insertRedirectMethodCallAfterIccMethod(IccLink link, SootMethod r
447449
return;
448450
}
449451

450-
Stmt redirectCallU = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(redirectMethod.makeRef(), args));
452+
final Body body = addICCRedirectCall(link, redirectMethod, args);
451453

452-
final Body body = link.getFromSM().retrieveActiveBody();
453454
final PatchingChain<Unit> units = body.getUnits();
454-
455-
copyTags(link.getFromU(), redirectCallU);
456-
redirectCallU.addTag(SimulatedCodeElementTag.TAG);
457-
units.insertAfter(redirectCallU, link.getFromU());
458-
instrumentedUnits.put(body, redirectCallU);
459-
if (instrumentationCallback != null) {
460-
instrumentationCallback.onRedirectorCallInserted(link, redirectCallU, redirectMethod);
461-
}
462-
463455
// remove the real ICC methods call stmt
464456
// link.getFromSM().retrieveActiveBody().getUnits().remove(link.getFromU());
465457
// Please refer to AndroidIPCManager.postProcess() for this removing
@@ -488,6 +480,27 @@ protected void insertRedirectMethodCallAfterIccMethod(IccLink link, SootMethod r
488480
}
489481
}
490482

483+
protected Body addICCRedirectCall(IccLink link, SootMethod redirectMethod, List<Value> args) {
484+
Stmt redirectCallU;
485+
Jimple jimp = Jimple.v();
486+
if (link.getFromU() instanceof AssignStmt)
487+
redirectCallU = jimp.newAssignStmt(((AssignStmt) link.getFromU()).getLeftOp(),
488+
Jimple.v().newStaticInvokeExpr(redirectMethod.makeRef(), args));
489+
else
490+
redirectCallU = jimp.newInvokeStmt(Jimple.v().newStaticInvokeExpr(redirectMethod.makeRef(), args));
491+
492+
final Body body = link.getFromSM().retrieveActiveBody();
493+
494+
copyTags(link.getFromU(), redirectCallU);
495+
redirectCallU.addTag(SimulatedCodeElementTag.TAG);
496+
body.getUnits().insertAfter(redirectCallU, link.getFromU());
497+
instrumentedUnits.put(body, redirectCallU);
498+
if (instrumentationCallback != null) {
499+
instrumentationCallback.onRedirectorCallInserted(link, redirectCallU, redirectMethod);
500+
}
501+
return body;
502+
}
503+
491504
/**
492505
* Copy all the tags of {from} to {to}, if {to} already contain the copied tag,
493506
* then overwrite it.

0 commit comments

Comments
 (0)