Skip to content

Commit cafb7cd

Browse files
committed
Be more precise with the typing if possible
1 parent 04b50f1 commit cafb7cd

8 files changed

Lines changed: 90 additions & 87 deletions

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/AbstractAndroidEntryPointCreator.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Set;
66

77
import soot.Local;
8+
import soot.RefType;
89
import soot.SootClass;
910
import soot.SootMethod;
1011
import soot.jimple.Jimple;
@@ -33,14 +34,14 @@ public SootMethod createDummyMain() {
3334
return super.createDummyMain();
3435
}
3536

36-
protected Stmt searchAndBuildMethod(String subsignature, SootClass currentClass, Local classLocal) {
37-
return searchAndBuildMethod(subsignature, currentClass, classLocal, Collections.<SootClass>emptySet());
37+
protected Stmt searchAndBuildMethod(String subsignature, Local classLocal) {
38+
return searchAndBuildMethod(subsignature, classLocal, Collections.<SootClass>emptySet());
3839
}
3940

40-
protected Stmt searchAndBuildMethod(String subsignature, SootClass currentClass, Local classLocal,
41-
Set<SootClass> parentClasses) {
42-
if (currentClass == null || classLocal == null)
41+
protected Stmt searchAndBuildMethod(String subsignature, Local classLocal, Set<SootClass> parentClasses) {
42+
if (classLocal == null)
4343
return null;
44+
SootClass currentClass = ((RefType) classLocal.getType()).getSootClass();
4445

4546
SootMethod method = SootUtils.findMethod(currentClass, subsignature);
4647
if (method == null)
@@ -53,7 +54,8 @@ protected Stmt searchAndBuildMethod(String subsignature, SootClass currentClass,
5354
return null;
5455

5556
// If this method is part of the Android framework, we don't need to
56-
// call it, unless it was explicitly requested. Due to virtual method invocations
57+
// call it, unless it was explicitly requested. Due to virtual method
58+
// invocations
5759
// application code could be called!
5860
if (SystemClassHandler.v().isClassInSystemPackage(method.getDeclaringClass())
5961
&& currentClass.isApplicationClass())

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/AndroidEntryPointCreator.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public class AndroidEntryPointCreator extends AbstractAndroidEntryPointCreator i
127127

128128
private String getResultIntentName;
129129

130+
private String setResultIntentName;
131+
130132
private String getIntentName;
131133

132134
private String setIntentName;
@@ -136,6 +138,7 @@ public class AndroidEntryPointCreator extends AbstractAndroidEntryPointCreator i
136138
private SootClass componentDataExchangeInterface;
137139

138140
private SootMethod getResultIntentMethod;
141+
private SootMethod setResultIntentMethod;
139142
private SootMethod getIntentMethod;
140143
private SootMethod setIntentMethod;
141144

@@ -161,6 +164,7 @@ public AndroidEntryPointCreator(IManifestHandler manifest, Collection<SootClass>
161164
}
162165
}
163166
getResultIntentName = findUniqueMethodName("getResultIntent", allComponentClasses);
167+
setResultIntentName = findUniqueMethodName("setResultIntent", allComponentClasses);
164168
// just choose a different name other than "getIntent"
165169
getIntentName = findUniqueMethodName("getDataIntent", allComponentClasses);
166170
setIntentName = findUniqueMethodName("setDataIntent", allComponentClasses);
@@ -177,17 +181,20 @@ private ComponentExchangeInfo generateComponentDataExchangeInterface() {
177181

178182
RefType intent = RefType.v("android.content.Intent");
179183
Scene sc = Scene.v();
180-
getResultIntentMethod = sc.makeSootMethod(getResultIntentName, Collections.emptyList(), intent);
184+
getResultIntentMethod = sc.makeSootMethod(getResultIntentName, Collections.emptyList(), intent,
185+
Modifier.PUBLIC | Modifier.ABSTRACT);
181186
componentDataExchangeInterface.addMethod(getResultIntentMethod);
182-
getResultIntentMethod.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT);
183-
getIntentMethod = sc.makeSootMethod(getIntentName, Collections.emptyList(), intent);
184-
getIntentMethod.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT);
187+
getIntentMethod = sc.makeSootMethod(getIntentName, Collections.emptyList(), intent,
188+
Modifier.PUBLIC | Modifier.ABSTRACT);
185189
componentDataExchangeInterface.addMethod(getIntentMethod);
186-
setIntentMethod = sc.makeSootMethod(setIntentName, Arrays.asList(intent), VoidType.v());
187-
setIntentMethod.setModifiers(Modifier.PUBLIC | Modifier.ABSTRACT);
190+
setIntentMethod = sc.makeSootMethod(setIntentName, Arrays.asList(intent), VoidType.v(),
191+
Modifier.PUBLIC | Modifier.ABSTRACT);
188192
componentDataExchangeInterface.addMethod(setIntentMethod);
193+
setResultIntentMethod = sc.makeSootMethod(setResultIntentName, Arrays.asList(intent), VoidType.v(),
194+
Modifier.PUBLIC | Modifier.ABSTRACT);
195+
componentDataExchangeInterface.addMethod(setResultIntentMethod);
189196
ComponentExchangeInfo info = new ComponentExchangeInfo(componentDataExchangeInterface, getIntentMethod,
190-
setIntentMethod, getResultIntentMethod);
197+
setIntentMethod, getResultIntentMethod, setResultIntentMethod);
191198
componentToInfo.setComponentExchangeInfo(info);
192199
return info;
193200

@@ -214,9 +221,6 @@ protected SootMethod createDummyMainInternal() {
214221
// from previous runs
215222
reset();
216223

217-
for (SootClass s : allComponentClasses) {
218-
s.addInterface(componentDataExchangeInterface);
219-
}
220224
logger.info(String.format("Creating Android entry point for %d components...", components.size()));
221225

222226
// For some weird reason unknown to anyone except the flying spaghetti
@@ -237,7 +241,7 @@ protected SootMethod createDummyMainInternal() {
237241
// Conditionally call the onCreate method
238242
NopStmt thenStmt = Jimple.v().newNopStmt();
239243
createIfStmt(thenStmt);
240-
searchAndBuildMethod(AndroidEntryPointConstants.CONTENTPROVIDER_ONCREATE, currentClass, localVal);
244+
searchAndBuildMethod(AndroidEntryPointConstants.CONTENTPROVIDER_ONCREATE, localVal);
241245
body.getUnits().add(thenStmt);
242246
hasContentProviders = true;
243247
}
@@ -337,8 +341,7 @@ protected SootMethod createDummyMainInternal() {
337341
}
338342

339343
// Call the onCreate() method
340-
searchAndBuildMethod(AndroidEntryPointConstants.APPLICATION_ONCREATE, applicationClassUse,
341-
applicationLocal);
344+
searchAndBuildMethod(AndroidEntryPointConstants.APPLICATION_ONCREATE, applicationLocal);
342345

343346
//////////////
344347
// Initializes the ApplicationHolder static field with the
@@ -465,8 +468,7 @@ protected SootMethod createDummyMainInternal() {
465468

466469
// Add a call to application.onTerminate()
467470
if (applicationLocal != null)
468-
searchAndBuildMethod(AndroidEntryPointConstants.APPLICATION_ONTERMINATE, applicationClassUse,
469-
applicationLocal);
471+
searchAndBuildMethod(AndroidEntryPointConstants.APPLICATION_ONTERMINATE, applicationLocal);
470472

471473
body.getUnits().add(Jimple.v().newReturnVoidStmt());
472474

@@ -485,6 +487,7 @@ private void initializeComponentDataTransferMethods(ComponentExchangeInfo info)
485487

486488
for (SootClass s : allComponentClasses) {
487489

490+
s.addInterface(componentDataExchangeInterface);
488491
Scene sc = Scene.v();
489492
Jimple j = Jimple.v();
490493

@@ -500,7 +503,8 @@ private void initializeComponentDataTransferMethods(ComponentExchangeInfo info)
500503
resultIntentField.addTag(SimulatedCodeElementTag.TAG);
501504
s.addField(resultIntentField);
502505
SootMethod getResultIntentMethod = sc.makeSootMethod(info.getResultIntentMethod.getName(),
503-
info.getResultIntentMethod.getParameterTypes(), info.getResultIntentMethod.getReturnType());
506+
info.getResultIntentMethod.getParameterTypes(), info.getResultIntentMethod.getReturnType(),
507+
Modifier.PUBLIC);
504508
getResultIntentMethod.addTag(SimulatedCodeElementTag.TAG);
505509
JimpleBody jb = j.newBody(getResultIntentMethod);
506510
getResultIntentMethod.setActiveBody(jb);
@@ -525,20 +529,32 @@ private void initializeComponentDataTransferMethods(ComponentExchangeInfo info)
525529
intentField.addTag(SimulatedCodeElementTag.TAG);
526530
s.addField(intentField);
527531

532+
SootMethod setResultIntentMethod = sc.makeSootMethod(info.setResultIntentMethod.getName(),
533+
info.setResultIntentMethod.getParameterTypes(), info.setResultIntentMethod.getReturnType(),
534+
Modifier.PUBLIC);
535+
536+
jb = j.newBody(setResultIntentMethod);
537+
setResultIntentMethod.setActiveBody(jb);
538+
s.addMethod(setResultIntentMethod);
539+
setResultIntentMethod.addTag(SimulatedCodeElementTag.TAG);
540+
jb.insertIdentityStmts();
541+
jb.getUnits().add(j.newAssignStmt(j.newInstanceFieldRef(jb.getThisLocal(), resultIntentField.makeRef()),
542+
jb.getParameterLocal(0)));
543+
jb.getUnits().add(j.newReturnVoidStmt());
528544
SootMethod getIntentMethod = sc.makeSootMethod(info.getIntentMethod.getName(),
529-
info.getIntentMethod.getParameterTypes(), info.getIntentMethod.getReturnType());
545+
info.getIntentMethod.getParameterTypes(), info.getIntentMethod.getReturnType(), Modifier.PUBLIC);
530546
jb = j.newBody(getIntentMethod);
531547
getIntentMethod.addTag(SimulatedCodeElementTag.TAG);
532548
getIntentMethod.setActiveBody(jb);
533549
s.addMethod(getIntentMethod);
534550
jb.insertIdentityStmts();
535-
lcl = j.newLocal("ret", getIntentMethod.getReturnType());
551+
lcl = j.newLocal("retValue", getIntentMethod.getReturnType());
536552
jb.getLocals().add(lcl);
537553
jb.getUnits().add(j.newAssignStmt(lcl, j.newInstanceFieldRef(jb.getThisLocal(), intentField.makeRef())));
538554
jb.getUnits().add(j.newReturnStmt(lcl));
539555

540556
SootMethod setIntentMethod = sc.makeSootMethod(info.setIntentMethod.getName(),
541-
info.setIntentMethod.getParameterTypes(), info.setIntentMethod.getReturnType());
557+
info.setIntentMethod.getParameterTypes(), info.setIntentMethod.getReturnType(), Modifier.PUBLIC);
542558
jb = j.newBody(setIntentMethod);
543559
setIntentMethod.setActiveBody(jb);
544560
s.addMethod(setIntentMethod);
@@ -877,16 +893,6 @@ public MultiMap<SootClass, SootMethod> getCallbackFunctions() {
877893
public void reset() {
878894
super.reset();
879895

880-
for (SootClass sc : allComponentClasses) {
881-
for (String mn : new String[] { getIntentName, getResultIntentName }) {
882-
SootMethod m = sc.getMethodByNameUnsafe(mn);
883-
if (m != null && m.isDeclared())
884-
sc.removeMethod(m);
885-
}
886-
if (sc.getInterfaces().contains(componentDataExchangeInterface))
887-
sc.removeInterface(componentDataExchangeInterface);
888-
}
889-
890896
// Get rid of the generated component methods
891897
for (SootMethod sm : getAdditionalMethods()) {
892898
if (sm.isDeclared())

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/ComponentExchangeInfo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ public class ComponentExchangeInfo {
77

88
public final SootClass componentDataExchangeInterface;
99
public final SootMethod getResultIntentMethod;
10+
public final SootMethod setResultIntentMethod;
1011
public final SootMethod getIntentMethod;
1112
public final SootMethod setIntentMethod;
1213

1314
public ComponentExchangeInfo(SootClass componentDataExchangeInterface, SootMethod getIntentMethod,
14-
SootMethod setIntentMethod, SootMethod getResultIntentMethod) {
15+
SootMethod setIntentMethod, SootMethod getResultIntentMethod, SootMethod setResultIntentMethod) {
1516
this.componentDataExchangeInterface = componentDataExchangeInterface;
1617
this.getIntentMethod = getIntentMethod;
1718
this.setIntentMethod = setIntentMethod;
1819
this.getResultIntentMethod = getResultIntentMethod;
20+
this.setResultIntentMethod = setResultIntentMethod;
1921
}
2022

2123
}

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/components/ActivityEntryPointCreator.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ protected void generateComponentLifecycle() {
9797

9898
// 1. onCreate:
9999
{
100-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONCREATE, activityClass, thisLocal);
100+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONCREATE, thisLocal);
101101
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
102102
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYCREATED,
103-
callbackClass, localVarsForClasses.get(callbackClass), currentClassSet);
103+
localVarsForClasses.get(callbackClass), currentClassSet);
104104
}
105105
}
106106

@@ -121,10 +121,10 @@ protected void generateComponentLifecycle() {
121121
// 2. onStart:
122122
Stmt onStartStmt;
123123
{
124-
onStartStmt = searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSTART, activityClass, thisLocal);
124+
onStartStmt = searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSTART, thisLocal);
125125
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
126126
Stmt s = searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYSTARTED,
127-
callbackClass, localVarsForClasses.get(callbackClass), currentClassSet);
127+
localVarsForClasses.get(callbackClass), currentClassSet);
128128
if (onStartStmt == null)
129129
onStartStmt = s;
130130
}
@@ -141,23 +141,23 @@ protected void generateComponentLifecycle() {
141141
{
142142
Stmt afterOnRestore = Jimple.v().newNopStmt();
143143
createIfStmt(afterOnRestore);
144-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESTOREINSTANCESTATE, activityClass, thisLocal,
144+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESTOREINSTANCESTATE, thisLocal,
145145
currentClassSet);
146146
body.getUnits().add(afterOnRestore);
147147
}
148-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPOSTCREATE, activityClass, thisLocal);
148+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPOSTCREATE, thisLocal);
149149

150150
// 3. onResume:
151151
Stmt onResumeStmt = Jimple.v().newNopStmt();
152152
body.getUnits().add(onResumeStmt);
153153
{
154-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESUME, activityClass, thisLocal);
154+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESUME, thisLocal);
155155
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
156156
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYRESUMED,
157-
callbackClass, localVarsForClasses.get(callbackClass), currentClassSet);
157+
localVarsForClasses.get(callbackClass), currentClassSet);
158158
}
159159
}
160-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPOSTRESUME, activityClass, thisLocal);
160+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPOSTRESUME, thisLocal);
161161

162162
// Scan for other entryPoints of this class:
163163
if (this.callbacks != null && !this.callbacks.isEmpty()) {
@@ -174,16 +174,16 @@ protected void generateComponentLifecycle() {
174174
}
175175

176176
// 4. onPause:
177-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPAUSE, activityClass, thisLocal);
177+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONPAUSE, thisLocal);
178178
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
179-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYPAUSED, callbackClass,
179+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYPAUSED,
180180
localVarsForClasses.get(callbackClass), currentClassSet);
181181
}
182-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONCREATEDESCRIPTION, activityClass, thisLocal);
183-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSAVEINSTANCESTATE, activityClass, thisLocal);
182+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONCREATEDESCRIPTION, thisLocal);
183+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSAVEINSTANCESTATE, thisLocal);
184184
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
185185
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYSAVEINSTANCESTATE,
186-
callbackClass, localVarsForClasses.get(callbackClass), currentClassSet);
186+
localVarsForClasses.get(callbackClass), currentClassSet);
187187
}
188188

189189
// goTo Stop, Resume or Create:
@@ -192,11 +192,11 @@ protected void generateComponentLifecycle() {
192192
// createIfStmt(onCreateStmt); // no, the process gets killed in between
193193

194194
// 5. onStop:
195-
Stmt onStop = searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSTOP, activityClass, thisLocal);
195+
Stmt onStop = searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONSTOP, thisLocal);
196196
boolean hasAppOnStop = false;
197197
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
198198
Stmt onActStoppedStmt = searchAndBuildMethod(
199-
AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYSTOPPED, callbackClass,
199+
AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYSTOPPED,
200200
localVarsForClasses.get(callbackClass), currentClassSet);
201201
hasAppOnStop |= onActStoppedStmt != null;
202202
}
@@ -210,15 +210,15 @@ protected void generateComponentLifecycle() {
210210
// createIfStmt(onCreateStmt); // no, the process gets killed in between
211211

212212
// 6. onRestart:
213-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESTART, activityClass, thisLocal);
213+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONRESTART, thisLocal);
214214
body.getUnits().add(Jimple.v().newGotoStmt(onStartStmt)); // jump to onStart()
215215

216216
// 7. onDestroy
217217
body.getUnits().add(stopToDestroyStmt);
218-
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONDESTROY, activityClass, thisLocal);
218+
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITY_ONDESTROY, thisLocal);
219219
for (SootClass callbackClass : this.activityLifecycleCallbacks.keySet()) {
220220
searchAndBuildMethod(AndroidEntryPointConstants.ACTIVITYLIFECYCLECALLBACK_ONACTIVITYDESTROYED,
221-
callbackClass, localVarsForClasses.get(callbackClass), currentClassSet);
221+
localVarsForClasses.get(callbackClass), currentClassSet);
222222
}
223223
}
224224

@@ -283,7 +283,7 @@ private void createSetResultMethod() {
283283

284284
Local lcIntent = b.getParameterLocal(1);
285285
b.getUnits().add(Jimple.v().newInvokeStmt(Jimple.v().newInterfaceInvokeExpr(b.getThisLocal(),
286-
componentExchangeInfo.setIntentMethod.makeRef(), Arrays.asList(lcIntent))));
286+
componentExchangeInfo.setResultIntentMethod.makeRef(), Arrays.asList(lcIntent))));
287287
b.getUnits().add(Jimple.v().newReturnVoidStmt());
288288

289289
// Activity.setResult() is final. We need to change that

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/components/BroadcastReceiverEntryPointCreator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ protected Local generateClassConstructor(SootClass createdClass) {
3636

3737
@Override
3838
protected void generateComponentLifecycle() {
39-
SootClass broadCastClass = getModelledClass();
40-
Stmt onReceiveStmt = searchAndBuildMethod(AndroidEntryPointConstants.BROADCAST_ONRECEIVE, broadCastClass,
41-
thisLocal);
39+
Stmt onReceiveStmt = searchAndBuildMethod(AndroidEntryPointConstants.BROADCAST_ONRECEIVE, thisLocal);
4240

4341
// methods
4442
NopStmt startWhileStmt = Jimple.v().newNopStmt();

0 commit comments

Comments
 (0)