Skip to content

Commit ca8c2ca

Browse files
committed
added support for HostApduService
1 parent e8ac8bb commit ca8c2ca

File tree

5 files changed

+81
-40
lines changed

5 files changed

+81
-40
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class AndroidEntryPointConstants {
2626
public static final String SERVICECLASS = "android.app.Service";
2727
public static final String GCMBASEINTENTSERVICECLASS = "com.google.android.gcm.GCMBaseIntentService";
2828
public static final String GCMLISTENERSERVICECLASS = "com.google.android.gms.gcm.GcmListenerService";
29+
public static final String HOSTAPDUSERVICECLASS = "android.nfc.cardemulation.HostApduService";
2930
public static final String BROADCASTRECEIVERCLASS = "android.content.BroadcastReceiver";
3031
public static final String CONTENTPROVIDERCLASS = "android.content.ContentProvider";
3132
public static final String APPLICATIONCLASS = "android.app.Application";
@@ -73,6 +74,9 @@ public class AndroidEntryPointConstants {
7374
public static final String GCMLISTENERSERVICE_ONMESSAGESENT = "void onMessageSent(java.lang.String)";
7475
public static final String GCMLISTENERSERVICE_ONSENDERROR = "void onSendError(java.lang.String,java.lang.String)";
7576

77+
public static final String HOSTAPDUSERVICE_PROCESSCOMMANDAPDU = "byte[] processCommandApdu(byte[],android.os.Bundle)";
78+
public static final String HOSTAPDUSERVICE_ONDEACTIVATED = "void onDeactivated(int)";
79+
7680
public static final String FRAGMENT_ONCREATE = "void onCreate(android.os.Bundle)";
7781
public static final String FRAGMENT_ONATTACH = "void onAttach(android.app.Activity)";
7882
public static final String FRAGMENT_ONCREATEVIEW = "android.view.View onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)";
@@ -148,6 +152,10 @@ public class AndroidEntryPointConstants {
148152
GCMLISTENERSERVICE_ONMESSAGERECEIVED, GCMLISTENERSERVICE_ONMESSAGESENT, GCMLISTENERSERVICE_ONSENDERROR };
149153
private static final List<String> gcmListenerServiceMethodList = Arrays.asList(gcmListenerServiceMethods);
150154

155+
private static final String[] hostApduServiceMethods = { HOSTAPDUSERVICE_PROCESSCOMMANDAPDU,
156+
HOSTAPDUSERVICE_ONDEACTIVATED };
157+
private static final List<String> hostApduServiceMethodList = Arrays.asList(hostApduServiceMethods);
158+
151159
private static final String[] broadcastMethods = { BROADCAST_ONRECEIVE };
152160
private static final List<String> broadcastMethodList = Arrays.asList(broadcastMethods);
153161

@@ -198,6 +206,10 @@ public static List<String> getGCMListenerServiceMethods() {
198206
return gcmListenerServiceMethodList;
199207
}
200208

209+
public static List<String> getHostApduServiceMethods() {
210+
return hostApduServiceMethodList;
211+
}
212+
201213
public static List<String> getBroadcastLifecycleMethods() {
202214
return broadcastMethodList;
203215
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ protected SootMethod createDummyMainInternal() {
256256
case Service:
257257
case GCMBaseIntentService:
258258
case GCMListenerService:
259+
case HostApduService:
259260
componentCreator = new ServiceEntryPointCreator(currentClass, applicationClass, this.manifest);
260261
break;
261262
case ServiceConnection:

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

+36-24
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ public class AndroidEntryPointUtils {
4141
private SootClass osClassContentProvider;
4242
private SootClass osClassGCMBaseIntentService;
4343
private SootClass osClassGCMListenerService;
44+
private SootClass osClassHostApduService;
4445
private SootClass osInterfaceServiceConnection;
4546

4647
/**
4748
* Array containing all types of components supported in Android lifecycles
4849
*/
4950
public enum ComponentType {
5051
Application, Activity, Service, Fragment, BroadcastReceiver, ContentProvider, GCMBaseIntentService,
51-
GCMListenerService, ServiceConnection, Plain
52+
GCMListenerService, HostApduService, ServiceConnection, Plain
5253
}
5354

5455
/**
@@ -68,6 +69,7 @@ public AndroidEntryPointUtils() {
6869
osClassGCMBaseIntentService = Scene.v()
6970
.getSootClassUnsafe(AndroidEntryPointConstants.GCMBASEINTENTSERVICECLASS);
7071
osClassGCMListenerService = Scene.v().getSootClassUnsafe(AndroidEntryPointConstants.GCMLISTENERSERVICECLASS);
72+
osClassHostApduService = Scene.v().getSootClassUnsafe(AndroidEntryPointConstants.HOSTAPDUSERVICECLASS);
7173
osInterfaceServiceConnection = Scene.v()
7274
.getSootClassUnsafe(AndroidEntryPointConstants.SERVICECONNECTIONINTERFACE);
7375
osClassMapActivity = Scene.v().getSootClassUnsafe(AndroidEntryPointConstants.MAPACTIVITYCLASS);
@@ -88,17 +90,10 @@ public ComponentType getComponentType(SootClass currentClass) {
8890
FastHierarchy fh = Scene.v().getOrMakeFastHierarchy();
8991

9092
if (fh != null) {
91-
// (1) android.app.Application
92-
if (osClassApplication != null && fh.canStoreType(currentClass.getType(), osClassApplication.getType()))
93-
ctype = ComponentType.Application;
94-
// (2) android.app.Activity
95-
else if (osClassActivity != null && fh.canStoreType(currentClass.getType(), osClassActivity.getType()))
96-
ctype = ComponentType.Activity;
97-
// (3) android.app.Service
98-
else if (osClassService != null && fh.canStoreType(currentClass.getType(), osClassService.getType()))
99-
ctype = ComponentType.Service;
100-
// (4) android.app.BroadcastReceiver
101-
else if (osClassFragment != null && Scene.v().getOrMakeFastHierarchy().canStoreType(currentClass.getType(),
93+
// We first look for the specialized types
94+
95+
// (a1) android.app.Fragment
96+
if (osClassFragment != null && Scene.v().getOrMakeFastHierarchy().canStoreType(currentClass.getType(),
10297
osClassFragment.getType()))
10398
ctype = ComponentType.Fragment;
10499
else if (osClassSupportFragment != null
@@ -107,30 +102,47 @@ else if (osClassSupportFragment != null
107102
else if (osClassAndroidXFragment != null
108103
&& fh.canStoreType(currentClass.getType(), osClassAndroidXFragment.getType()))
109104
ctype = ComponentType.Fragment;
110-
// (5) android.app.BroadcastReceiver
111-
else if (osClassBroadcastReceiver != null
112-
&& fh.canStoreType(currentClass.getType(), osClassBroadcastReceiver.getType()))
113-
ctype = ComponentType.BroadcastReceiver;
114-
// (6) android.app.ContentProvider
115-
else if (osClassContentProvider != null
116-
&& fh.canStoreType(currentClass.getType(), osClassContentProvider.getType()))
117-
ctype = ComponentType.ContentProvider;
118-
// (7) com.google.android.gcm.GCMBaseIntentService
105+
// (a2) com.google.android.gcm.GCMBaseIntentService
119106
else if (osClassGCMBaseIntentService != null
120107
&& fh.canStoreType(currentClass.getType(), osClassGCMBaseIntentService.getType()))
121108
ctype = ComponentType.GCMBaseIntentService;
122-
// (8) com.google.android.gms.gcm.GcmListenerService
109+
// (a3) com.google.android.gms.gcm.GcmListenerService
123110
else if (osClassGCMListenerService != null
124111
&& fh.canStoreType(currentClass.getType(), osClassGCMListenerService.getType()))
125112
ctype = ComponentType.GCMListenerService;
126-
// (9) android.content.ServiceConnection
113+
// (a4) android.nfc.cardemulation.HostApduService
114+
else if (osClassHostApduService != null
115+
&& fh.canStoreType(currentClass.getType(), osClassHostApduService.getType()))
116+
ctype = ComponentType.HostApduService;
117+
// (a5) android.content.ServiceConnection
127118
else if (osInterfaceServiceConnection != null
128119
&& fh.canStoreType(currentClass.getType(), osInterfaceServiceConnection.getType()))
129120
ctype = ComponentType.ServiceConnection;
130-
// (10) com.google.android.maps.MapActivity
121+
// (a6) com.google.android.maps.MapActivity
131122
else if (osClassMapActivity != null
132123
&& fh.canStoreType(currentClass.getType(), osClassMapActivity.getType()))
133124
ctype = ComponentType.Activity;
125+
126+
// If the given class is not a specific type of component, we look upwards in
127+
// the hierarchy to see if we have something more generic
128+
// (b1) android.app.Application
129+
else if (osClassApplication != null
130+
&& fh.canStoreType(currentClass.getType(), osClassApplication.getType()))
131+
ctype = ComponentType.Application;
132+
// (b2) android.app.Service
133+
else if (osClassService != null && fh.canStoreType(currentClass.getType(), osClassService.getType()))
134+
ctype = ComponentType.Service;
135+
// (b3) android.app.Activity
136+
else if (osClassActivity != null && fh.canStoreType(currentClass.getType(), osClassActivity.getType()))
137+
ctype = ComponentType.Activity;
138+
// (b4) android.app.BroadcastReceiver
139+
else if (osClassBroadcastReceiver != null
140+
&& fh.canStoreType(currentClass.getType(), osClassBroadcastReceiver.getType()))
141+
ctype = ComponentType.BroadcastReceiver;
142+
// (b5) android.app.ContentProvider
143+
else if (osClassContentProvider != null
144+
&& fh.canStoreType(currentClass.getType(), osClassContentProvider.getType()))
145+
ctype = ComponentType.ContentProvider;
134146
} else
135147
logger.warn(String.format("No FastHierarchy, assuming %s is a plain class", currentClass.getName()));
136148

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

+32-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.reflect.Modifier;
44
import java.util.Collections;
5+
import java.util.List;
56

67
import soot.Local;
78
import soot.RefType;
@@ -64,21 +65,17 @@ protected void generateComponentLifecycle() {
6465
ComponentType componentType = entryPointUtils.getComponentType(component);
6566
boolean hasAdditionalMethods = false;
6667
if (componentType == ComponentType.GCMBaseIntentService) {
67-
for (String sig : AndroidEntryPointConstants.getGCMIntentServiceMethods()) {
68-
SootMethod sm = findMethod(component, sig);
69-
if (sm != null && !sm.getDeclaringClass().getName()
70-
.equals(AndroidEntryPointConstants.GCMBASEINTENTSERVICECLASS))
71-
if (createPlainMethodCall(thisLocal, sm))
72-
hasAdditionalMethods = true;
73-
}
68+
hasAdditionalMethods |= createSpecialServiceMethodCalls(
69+
AndroidEntryPointConstants.getGCMIntentServiceMethods(),
70+
AndroidEntryPointConstants.GCMBASEINTENTSERVICECLASS);
7471
} else if (componentType == ComponentType.GCMListenerService) {
75-
for (String sig : AndroidEntryPointConstants.getGCMListenerServiceMethods()) {
76-
SootMethod sm = findMethod(component, sig);
77-
if (sm != null
78-
&& !sm.getDeclaringClass().getName().equals(AndroidEntryPointConstants.GCMLISTENERSERVICECLASS))
79-
if (createPlainMethodCall(thisLocal, sm))
80-
hasAdditionalMethods = true;
81-
}
72+
hasAdditionalMethods |= createSpecialServiceMethodCalls(
73+
AndroidEntryPointConstants.getGCMListenerServiceMethods(),
74+
AndroidEntryPointConstants.GCMLISTENERSERVICECLASS);
75+
} else if (componentType == ComponentType.HostApduService) {
76+
hasAdditionalMethods |= createSpecialServiceMethodCalls(
77+
AndroidEntryPointConstants.getHostApduServiceMethods(),
78+
AndroidEntryPointConstants.HOSTAPDUSERVICECLASS);
8279
}
8380
addCallbackMethods();
8481
body.getUnits().add(endWhileStmt);
@@ -126,6 +123,27 @@ protected void generateComponentLifecycle() {
126123
searchAndBuildMethod(AndroidEntryPointConstants.SERVICE_ONDESTROY, component, thisLocal);
127124
}
128125

126+
/**
127+
* Creates invocations to the handler methods of special-purpose services in
128+
* Android
129+
*
130+
* @param methodSigs The signatures of the methods for which to create
131+
* invocations
132+
* @param parentClass The name of the parent class in the SDK that contains the
133+
* service interface
134+
* @return True if at least one method invocation was created, false otherwise
135+
*/
136+
protected boolean createSpecialServiceMethodCalls(List<String> methodSigs, String parentClass) {
137+
boolean hasAdditionalMethods = false;
138+
for (String sig : methodSigs) {
139+
SootMethod sm = findMethod(component, sig);
140+
if (sm != null && !sm.getDeclaringClass().getName().equals(parentClass))
141+
if (createPlainMethodCall(thisLocal, sm))
142+
hasAdditionalMethods = true;
143+
}
144+
return hasAdditionalMethods;
145+
}
146+
129147
@Override
130148
protected void createAdditionalFields() {
131149
super.createAdditionalFields();

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/xml/SummaryReader.java

-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ private boolean isReturn(Map<String, String> attributes) {
353353
private boolean isField(Map<String, String> attributes) {
354354
if (attributes != null) {
355355
String attr = attributes.get(ATTRIBUTE_FLOWTYPE);
356-
if (attr == null)
357-
System.out.println("x");
358356
return attr != null && attr.equals(SourceSinkType.Field.toString());
359357
}
360358
return false;

0 commit comments

Comments
 (0)