Skip to content

Commit 8f488ff

Browse files
committed
Adding JavaDoc
1 parent a09342a commit 8f488ff

5 files changed

Lines changed: 90 additions & 4 deletions

File tree

soot-infoflow-android/src/soot/jimple/infoflow/android/AndroidLibraryClassPatcher.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import soot.jimple.toolkits.scalar.NopEliminator;
2727
import soot.util.Chain;
2828

29-
//The generated implementations of this class are semantically equivalent to the AppComponentFactory in Android:
30-
//https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/app/AppComponentFactory.java
29+
/**
30+
* In addition to the normal JVM library classes, this class also patches
31+
* certain Android library classes.
32+
*/
3133
public class AndroidLibraryClassPatcher extends LibraryClassPatcher {
3234

3335
@Override
@@ -37,6 +39,10 @@ public void patchLibraries() {
3739
patchComponentFactory();
3840
}
3941

42+
/**
43+
* The generated implementation of this method are semantically equivalent to the AppComponentFactory in Android.
44+
* @see https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/app/AppComponentFactory.java
45+
*/
4046
protected void patchComponentFactory() {
4147
SootClass sc = Scene.v().forceResolve(AndroidEntryPointConstants.APPCOMPONENTFACTORYCLASS,
4248
SootClass.SIGNATURES);
@@ -54,6 +60,11 @@ protected void patchComponentFactory() {
5460

5561
}
5662

63+
/**
64+
* Patches the instantiate classloader class.
65+
* It returns the default class loader unmodified.
66+
* @param sc the class of the app component factory
67+
*/
5768
private void patchInstantiateClassLoader(SootClass sc) {
5869
SootMethod smInstantiate = getOrCreateMethod(sc,
5970
AndroidEntryPointConstants.APPCOMPONENTFACTORY_INSTANTIATECLASSLOADER);
@@ -64,6 +75,12 @@ private void patchInstantiateClassLoader(SootClass sc) {
6475

6576
}
6677

78+
/**
79+
* Returns all class names that could be instantiated when
80+
* instantiating a class with the given class name, i.e. all subclasses/implementers.
81+
* @param className the class name (could also represent an interface)
82+
* @return a string array of all possible names.
83+
*/
6784
protected String[] getAllNames(String className) {
6885
List<String> names = new ArrayList<>();
6986
SootClass sc = Scene.v().getSootClassUnsafe(className);
@@ -84,6 +101,28 @@ protected String[] getAllNames(String className) {
84101
return names.toArray(new String[names.size()]);
85102
}
86103

104+
/**
105+
* Patches an instantiate method. Generates code equivalent to the following:
106+
*
107+
* <code>
108+
* public void instantiateActivity(ClassLoader cl, String className, Intent intent)
109+
* {
110+
*
111+
* if (className.equals("foo.bar.MainActivity"))
112+
* return new foo.bar.MainActivity(); //(1)
113+
* if (className.equals("foo.bar.FooActivity"))
114+
* return new foo.bar.FooActivity(); //(2)
115+
* return cl.loadClass(className).newInstance(); //(3)
116+
*
117+
* }
118+
* </code>
119+
* The instantiation statements (1) and (2) are used to help SPARK and other static algorithms to find
120+
* allocation sites. (3) is the fallback that would normally be the implementation when using Android's default
121+
* app component factory.
122+
* @param sc the class of the app component factory
123+
* @param subsig the sub signature of the method, in our example case instantiateActivity
124+
* @param names the names for each possible class instantiation, in our example case "foo.bar.MainActivity", "foo.bar.FooActivity"
125+
*/
87126
protected void patchInstantiate(SootClass sc, String subsig, String... names) {
88127

89128
if (!sc.isLibraryClass())
@@ -154,6 +193,12 @@ protected void patchInstantiate(SootClass sc, String subsig, String... names) {
154193

155194
}
156195

196+
/**
197+
* Creates a method if it doesn't exist. Otherwise, it returns the existing method
198+
* @param sc the class where the method is being looked for
199+
* @param subsig the sub signature of the method
200+
* @return the method
201+
*/
157202
private static SootMethod getOrCreateMethod(SootClass sc, String subsig) {
158203
SootMethod p = sc.getMethodUnsafe(subsig);
159204
if (p != null)

soot-infoflow-android/src/soot/jimple/infoflow/android/callbacks/filters/ApplicationCallbackFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ public boolean accepts(SootClass component, SootMethod callback) {
110110
return true;
111111

112112
String subSig = callback.getSubSignature();
113-
String name = callback.getName();
114113
final FastHierarchy fh = Scene.v().getOrMakeFastHierarchy();
115114
final RefType callbackType = callback.getDeclaringClass().getType();
116115
if (AndroidEntryPointConstants.getActivityLifecycleCallbackMethods().contains(subSig))
117116
return fh.canStoreType(callbackType, this.activityLifecycleCallbacks);
118117
if (AndroidEntryPointConstants.getComponentCallbackMethods().contains(subSig))
119118
return fh.canStoreType(callbackType, this.componentCallbacks);
120-
119+
if (AndroidEntryPointConstants.getComponentCallback2Methods().contains(subSig))
120+
return fh.canStoreType(callbackType, this.componentCallbacks2);
121121
return true;
122122
}
123123

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ protected SootMethod createDummyMainInternal() {
510510
return mainMethod;
511511
}
512512

513+
/**
514+
* Initializes the methods intended for transferring data (usually intents) between components.
515+
* @param info contains information about the commonly used method names for the interface methods
516+
*/
513517
private void initializeComponentDataTransferMethods(ComponentExchangeInfo info) {
514518

515519
for (SootClass s : allComponentClasses) {

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

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

3+
import java.util.Objects;
4+
35
import soot.SootClass;
46
import soot.SootMethod;
57

8+
/**
9+
* Contains information used for data transfers between arbitrary components.
10+
* These components implement common interface methods for setting and retrieving an intent.
11+
* In the case of activities, there are also methods to save and retrieve an result intent.
12+
*/
613
public class ComponentExchangeInfo {
714

815
public final SootClass componentDataExchangeInterface;
@@ -11,6 +18,28 @@ public class ComponentExchangeInfo {
1118
public final SootMethod getIntentMethod;
1219
public final SootMethod setIntentMethod;
1320

21+
@Override
22+
public int hashCode() {
23+
return Objects.hash(componentDataExchangeInterface, getIntentMethod, getResultIntentMethod, setIntentMethod,
24+
setResultIntentMethod);
25+
}
26+
27+
@Override
28+
public boolean equals(Object obj) {
29+
if (this == obj)
30+
return true;
31+
if (obj == null)
32+
return false;
33+
if (getClass() != obj.getClass())
34+
return false;
35+
ComponentExchangeInfo other = (ComponentExchangeInfo) obj;
36+
return Objects.equals(componentDataExchangeInterface, other.componentDataExchangeInterface)
37+
&& Objects.equals(getIntentMethod, other.getIntentMethod)
38+
&& Objects.equals(getResultIntentMethod, other.getResultIntentMethod)
39+
&& Objects.equals(setIntentMethod, other.setIntentMethod)
40+
&& Objects.equals(setResultIntentMethod, other.setResultIntentMethod);
41+
}
42+
1443
public ComponentExchangeInfo(SootClass componentDataExchangeInterface, SootMethod getIntentMethod,
1544
SootMethod setIntentMethod, SootMethod getResultIntentMethod, SootMethod setResultIntentMethod) {
1645
this.componentDataExchangeInterface = componentDataExchangeInterface;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,14 @@ protected void createGetIntentMethod() {
501501
b.getUnits().add(Jimple.v().newReturnStmt(lcIntent));
502502
}
503503

504+
/**
505+
* Returns a local that will contain a new instance of a given class using an instantiator/factory.
506+
*
507+
* @param createdClass the class/type that should be created
508+
* @param creatorMethodSubset the subsignature of the factory class that instantiates the desired instance type
509+
* @param values the values to pass on to the <i>creatorMethodSubset</i> method of the factory class
510+
* @return the local (might be new or reused)
511+
*/
504512
public Local generateInstantiator(SootClass createdClass, String creatorMethodSubset, Value... values) {
505513

506514
// If we already have a class local of that type, we re-use it

0 commit comments

Comments
 (0)