Skip to content

Commit 6fa77d5

Browse files
committed
Move methods from DefaultCallbackAnalyzer to AndroidEntryPointUtils
1 parent 3acac54 commit 6fa77d5

2 files changed

Lines changed: 79 additions & 75 deletions

File tree

soot-infoflow-android/src/soot/jimple/infoflow/android/callbacks/DefaultCallbackAnalyzer.java

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.io.IOException;
44
import java.util.ArrayList;
5-
import java.util.Collection;
6-
import java.util.Collections;
75
import java.util.HashSet;
86
import java.util.Iterator;
97
import java.util.List;
@@ -26,7 +24,6 @@
2624
import soot.jimple.infoflow.android.callbacks.filters.ICallbackFilter;
2725
import soot.jimple.infoflow.android.entryPointCreators.AndroidEntryPointConstants;
2826
import soot.jimple.infoflow.android.entryPointCreators.AndroidEntryPointUtils;
29-
import soot.jimple.infoflow.android.entryPointCreators.AndroidEntryPointUtils.ComponentType;
3027
import soot.jimple.infoflow.memory.IMemoryBoundedSolver;
3128
import soot.jimple.infoflow.memory.ISolverTerminationReason;
3229
import soot.jimple.infoflow.util.SystemClassHandler;
@@ -97,7 +94,7 @@ protected void internalTransform(String phaseName, @SuppressWarnings("rawtypes")
9794
break;
9895

9996
List<MethodOrMethodContext> methods = new ArrayList<MethodOrMethodContext>(
100-
getLifecycleMethods(sc));
97+
entryPointUtils.getLifecycleMethods(sc));
10198

10299
// Check for callbacks registered in the code
103100
analyzeRechableMethods(sc, methods);
@@ -155,77 +152,6 @@ protected void internalTransform(String phaseName, @SuppressWarnings("rawtypes")
155152
PackManager.v().getPack("wjtp").add(transform);
156153
}
157154

158-
/**
159-
* Gets all lifecycle methods in the given entry point class
160-
*
161-
* @param sc The class in which to look for lifecycle methods
162-
* @return The set of lifecycle methods in the given class
163-
*/
164-
private Collection<? extends MethodOrMethodContext> getLifecycleMethods(SootClass sc) {
165-
return getLifecycleMethods(entryPointUtils.getComponentType(sc), sc);
166-
}
167-
168-
/**
169-
* Gets all lifecycle methods in the given entry point class
170-
*
171-
* @param componentType the component type
172-
* @param sc The class in which to look for lifecycle methods
173-
* @return The set of lifecycle methods in the given class
174-
*/
175-
public static Collection<? extends MethodOrMethodContext> getLifecycleMethods(ComponentType componentType,
176-
SootClass sc) {
177-
switch (componentType) {
178-
case Activity:
179-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getActivityLifecycleMethods());
180-
case Service:
181-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getServiceLifecycleMethods());
182-
case Application:
183-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getApplicationLifecycleMethods());
184-
case BroadcastReceiver:
185-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getBroadcastLifecycleMethods());
186-
case Fragment:
187-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getFragmentLifecycleMethods());
188-
case ContentProvider:
189-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getContentproviderLifecycleMethods());
190-
case GCMBaseIntentService:
191-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getGCMIntentServiceMethods());
192-
case GCMListenerService:
193-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getGCMListenerServiceMethods());
194-
case ServiceConnection:
195-
return getLifecycleMethods(sc, AndroidEntryPointConstants.getServiceConnectionMethods());
196-
case Plain:
197-
return Collections.emptySet();
198-
}
199-
return Collections.emptySet();
200-
}
201-
202-
/**
203-
* This method takes a lifecycle class and the list of lifecycle method
204-
* subsignatures. For each subsignature, it checks whether the given class or
205-
* one of its superclass overwrites the respective methods. All findings are
206-
* collected in a set and returned.
207-
*
208-
* @param sc The class in which to look for lifecycle method
209-
* implementations
210-
* @param methods The list of lifecycle method subsignatures for the type of
211-
* component that the given class corresponds to
212-
* @return The set of implemented lifecycle methods in the given class
213-
*/
214-
private static Collection<? extends MethodOrMethodContext> getLifecycleMethods(SootClass sc, List<String> methods) {
215-
Set<MethodOrMethodContext> lifecycleMethods = new HashSet<>();
216-
SootClass currentClass = sc;
217-
while (currentClass != null) {
218-
for (String sig : methods) {
219-
SootMethod sm = currentClass.getMethodUnsafe(sig);
220-
if (sm != null)
221-
if (!SystemClassHandler.v().isClassInSystemPackage(sm.getDeclaringClass().getName()))
222-
lifecycleMethods.add(sm);
223-
}
224-
currentClass = currentClass.hasSuperclass() ? currentClass.getSuperclass() : null;
225-
}
226-
return lifecycleMethods;
227-
}
228-
229155
private void analyzeRechableMethods(SootClass lifecycleElement, List<MethodOrMethodContext> methods) {
230156
// Make sure to exclude all other edges in the callgraph except for the
231157
// edges start in the lifecycle methods we explicitly pass in

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package soot.jimple.infoflow.android.entryPointCreators;
22

3+
import java.util.Collection;
4+
import java.util.Collections;
35
import java.util.HashMap;
6+
import java.util.HashSet;
7+
import java.util.List;
48
import java.util.Map;
9+
import java.util.Set;
510

611
import org.slf4j.Logger;
712
import org.slf4j.LoggerFactory;
813

914
import soot.FastHierarchy;
15+
import soot.MethodOrMethodContext;
1016
import soot.Scene;
1117
import soot.SootClass;
1218
import soot.SootMethod;
19+
import soot.jimple.infoflow.util.SystemClassHandler;
1320

1421
/**
1522
* Class containing common utility methods for dealing with Android entry points
@@ -184,4 +191,75 @@ public boolean isEntryPointMethod(SootMethod method) {
184191
return false;
185192
}
186193

194+
/**
195+
* Gets all lifecycle methods in the given entry point class
196+
*
197+
* @param sc The class in which to look for lifecycle methods
198+
* @return The set of lifecycle methods in the given class
199+
*/
200+
public Collection<? extends MethodOrMethodContext> getLifecycleMethods(SootClass sc) {
201+
return getLifecycleMethods(getComponentType(sc), sc);
202+
}
203+
204+
/**
205+
* Gets all lifecycle methods in the given entry point class
206+
*
207+
* @param componentType the component type
208+
* @param sc The class in which to look for lifecycle methods
209+
* @return The set of lifecycle methods in the given class
210+
*/
211+
public static Collection<? extends MethodOrMethodContext> getLifecycleMethods(ComponentType componentType,
212+
SootClass sc) {
213+
switch (componentType) {
214+
case Activity:
215+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getActivityLifecycleMethods());
216+
case Service:
217+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getServiceLifecycleMethods());
218+
case Application:
219+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getApplicationLifecycleMethods());
220+
case BroadcastReceiver:
221+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getBroadcastLifecycleMethods());
222+
case Fragment:
223+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getFragmentLifecycleMethods());
224+
case ContentProvider:
225+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getContentproviderLifecycleMethods());
226+
case GCMBaseIntentService:
227+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getGCMIntentServiceMethods());
228+
case GCMListenerService:
229+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getGCMListenerServiceMethods());
230+
case ServiceConnection:
231+
return getLifecycleMethods(sc, AndroidEntryPointConstants.getServiceConnectionMethods());
232+
case Plain:
233+
return Collections.emptySet();
234+
}
235+
return Collections.emptySet();
236+
}
237+
238+
/**
239+
* This method takes a lifecycle class and the list of lifecycle method
240+
* subsignatures. For each subsignature, it checks whether the given class or
241+
* one of its superclass overwrites the respective methods. All findings are
242+
* collected in a set and returned.
243+
*
244+
* @param sc The class in which to look for lifecycle method
245+
* implementations
246+
* @param methods The list of lifecycle method subsignatures for the type of
247+
* component that the given class corresponds to
248+
* @return The set of implemented lifecycle methods in the given class
249+
*/
250+
private static Collection<? extends MethodOrMethodContext> getLifecycleMethods(SootClass sc, List<String> methods) {
251+
Set<MethodOrMethodContext> lifecycleMethods = new HashSet<>();
252+
SootClass currentClass = sc;
253+
while (currentClass != null) {
254+
for (String sig : methods) {
255+
SootMethod sm = currentClass.getMethodUnsafe(sig);
256+
if (sm != null)
257+
if (!SystemClassHandler.v().isClassInSystemPackage(sm.getDeclaringClass().getName()))
258+
lifecycleMethods.add(sm);
259+
}
260+
currentClass = currentClass.hasSuperclass() ? currentClass.getSuperclass() : null;
261+
}
262+
return lifecycleMethods;
263+
}
264+
187265
}

0 commit comments

Comments
 (0)