Skip to content

Commit 4863f59

Browse files
committed
Change rigid category system to be flexible
1 parent d4484d6 commit 4863f59

File tree

9 files changed

+83
-256
lines changed

9 files changed

+83
-256
lines changed

soot-infoflow-android/src/soot/jimple/infoflow/android/config/XMLConfigurationParser.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import soot.jimple.infoflow.android.InfoflowAndroidConfiguration.IccConfiguration;
3434
import soot.jimple.infoflow.android.InfoflowAndroidConfiguration.SourceSinkConfiguration;
3535
import soot.jimple.infoflow.android.data.CategoryDefinition;
36-
import soot.jimple.infoflow.android.data.CategoryDefinition.CATEGORY;
3736
import soot.jimple.infoflow.android.source.parsers.xml.ResourceUtils;
3837

3938
/**
@@ -112,19 +111,17 @@ else if (qName.equals(XMLConstants.TAG_DATA_FLOW_CONFIGURATION))
112111
} else if (stackElement == XMLSection.SOURCES) {
113112
if (qName.equals(XMLConstants.TAG_CATEGORY)) {
114113
String strId = attributes.getValue(XMLConstants.ATTR_ID);
115-
String strCustomId = attributes.getValue(XMLConstants.ATTR_CUSTOM_ID);
116114
String strMode = attributes.getValue(XMLConstants.ATTR_MODE);
117115

118-
CategoryDefinition catDef = new CategoryDefinition(CATEGORY.valueOf(strId), strCustomId);
116+
CategoryDefinition catDef = new CategoryDefinition(strId);
119117
config.getSourceSinkConfig().addSourceCategory(catDef, CategoryMode.valueOf(strMode));
120118
}
121119
} else if (stackElement == XMLSection.SINKS) {
122120
if (qName.equals(XMLConstants.TAG_CATEGORY)) {
123121
String strId = attributes.getValue(XMLConstants.ATTR_ID);
124-
String strCustomId = attributes.getValue(XMLConstants.ATTR_CUSTOM_ID);
125122
String strMode = attributes.getValue(XMLConstants.ATTR_MODE);
126123

127-
CategoryDefinition catDef = new CategoryDefinition(CATEGORY.valueOf(strId), strCustomId);
124+
CategoryDefinition catDef = new CategoryDefinition(strId);
128125
config.getSourceSinkConfig().addSinkCategory(catDef, CategoryMode.valueOf(strMode));
129126
}
130127
}

soot-infoflow-android/src/soot/jimple/infoflow/android/config/XMLConfigurationWriter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,7 @@ private void writeCategoryConfig(Document document, Element parentElement,
242242
parentElement.appendChild(categoryTag);
243243

244244
// Write out the specification data
245-
categoryTag.setAttribute(XMLConstants.ATTR_ID, def.getSystemCategory().toString());
246-
if (def.getCustomCategory() != null && !def.getCustomCategory().isEmpty())
247-
categoryTag.setAttribute(XMLConstants.ATTR_CUSTOM_ID, def.getCustomCategory());
245+
categoryTag.setAttribute(XMLConstants.ATTR_ID, def.getCategoryId().toString());
248246
categoryTag.setAttribute(XMLConstants.ATTR_MODE, categorySpec.get(def).toString());
249247
}
250248
}

soot-infoflow-android/src/soot/jimple/infoflow/android/config/XMLConstants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class XMLConstants {
6363

6464
public static final String ATTR_DEFAULT_MODE = "defaultMode";
6565
public static final String ATTR_ID = "id";
66-
public static final String ATTR_CUSTOM_ID = "customId";
6766
public static final String ATTR_MODE = "mode";
6867

6968
}

soot-infoflow-android/src/soot/jimple/infoflow/android/data/CategoryDefinition.java

Lines changed: 30 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -10,126 +10,57 @@
1010
*/
1111
public class CategoryDefinition implements ISourceSinkCategory {
1212

13-
public static enum CATEGORY {
14-
// all categories
15-
ALL,
16-
17-
// SOURCES
18-
NO_CATEGORY, HARDWARE_INFO, UNIQUE_IDENTIFIER, LOCATION_INFORMATION, NETWORK_INFORMATION, ACCOUNT_INFORMATION,
19-
EMAIL_INFORMATION, FILE_INFORMATION, BLUETOOTH_INFORMATION, VOIP_INFORMATION, DATABASE_INFORMATION,
20-
PHONE_INFORMATION,
21-
22-
// SINKS
23-
PHONE_CONNECTION, INTER_APP_COMMUNICATION, VOIP, PHONE_STATE, EMAIL, BLUETOOTH, ACCOUNT_SETTINGS, VIDEO,
24-
SYNCHRONIZATION_DATA, NETWORK, EMAIL_SETTINGS, FILE, LOG,
25-
26-
// SHARED
27-
AUDIO, SMS_MMS, CONTACT_INFORMATION, CALENDAR_INFORMATION, SYSTEM_SETTINGS, IMAGE, BROWSER_INFORMATION, NFC
28-
}
29-
30-
private CATEGORY systemCategory = null;
31-
private String customCategory;
32-
private String customDescription;
33-
34-
public static final CategoryDefinition NO_CATEGORY = new CategoryDefinition(CATEGORY.NO_CATEGORY);
13+
public static final CategoryDefinition ALL_CATEGORIES = new CategoryDefinition("all");
14+
private String categoryId;
15+
private String humanReadableName;
3516

3617
/**
3718
* Creates a new instance of the {@link CategoryDefinition} class
3819
*
39-
* @param systemCategory The system-defined category
20+
* @param categoryId user-defined category ID
4021
*/
41-
public CategoryDefinition(CATEGORY systemCategory) {
42-
this(systemCategory, null);
22+
public CategoryDefinition(String categoryId) {
23+
this(categoryId, null);
4324
}
4425

4526
/**
4627
* Creates a new instance of the {@link CategoryDefinition} class
4728
*
48-
* @param systemCategory The system-defined category
49-
* @param customCategory A user-defined category ID. This parameter may only be
50-
* used if the system-defined category is set to
51-
* NO_CATEGORY.
52-
*/
53-
public CategoryDefinition(CATEGORY systemCategory, String customCategory) {
54-
this(systemCategory, customCategory, null);
55-
}
56-
57-
/**
58-
* Creates a new instance of the {@link CategoryDefinition} class
59-
*
60-
* @param systemCategory The system-defined category
61-
* @param customCategory A user-defined category ID. This parameter may only
62-
* be used if the system-defined category is set to
63-
* NO_CATEGORY.
64-
* @param customDescription An optional description for the custom category
65-
*/
66-
public CategoryDefinition(CATEGORY systemCategory, String customCategory, String customDescription) {
67-
this.systemCategory = systemCategory;
68-
this.customCategory = customCategory;
69-
this.customDescription = customDescription;
70-
}
71-
72-
/**
73-
* Gets the system-defined category name. If this value is NO_CATEGORY, there
74-
* may be a user-defined custom category name.
75-
*
76-
* @return The system-defined category name
29+
* @param customCategoryId A user-defined category ID
30+
* @param humanReadableNmae An optional human-readable name
7731
*/
78-
public CATEGORY getSystemCategory() {
79-
return systemCategory;
80-
}
81-
82-
public void setSystemCategory(CATEGORY systemCategory) {
83-
this.systemCategory = systemCategory;
32+
public CategoryDefinition(String customCategoryId, String humanReadableNmae) {
33+
this.categoryId = customCategoryId;
34+
this.humanReadableName = humanReadableNmae;
8435
}
8536

8637
/**
87-
* Gets the user-defined category name. User-defined categories must have a
88-
* system category of NO_CATEGORY.
38+
* Gets the user-defined category id.
8939
*
90-
* @return The user-defined category name
40+
* @return The user-defined category id
9141
*/
92-
public String getCustomCategory() {
93-
return customCategory;
42+
public String getCategoryId() {
43+
return categoryId;
9444
}
9545

9646
/**
9747
* Sets the user-defined category id. This is an identifier for the system. To
9848
* define a human-readable category description, use the setCustomDescription()
9949
* instead.
10050
*
101-
* @param customCategory The user-defined category id. Category identifiers must
51+
* @param id The user-defined category id. Category identifiers must
10252
* be unique.
10353
*/
104-
public void setCustomCategory(String customCategory) {
105-
this.customCategory = customCategory;
106-
}
107-
108-
/**
109-
* Gets the description of the user-defined category
110-
*
111-
* @return The description of the user-defined category
112-
*/
113-
public String getCustomDescription() {
114-
return customDescription;
115-
}
116-
117-
/**
118-
* Sets the description of the user-defined category
119-
*
120-
* @param customDescription The description of the user-defined category
121-
*/
122-
public void setCustomDescription(String customDescription) {
123-
this.customDescription = customDescription;
54+
public void setCategoryId(String id) {
55+
this.categoryId = id;
12456
}
12557

12658
@Override
12759
public int hashCode() {
12860
final int prime = 31;
12961
int result = 1;
130-
result = prime * result + ((customCategory == null) ? 0 : customCategory.hashCode());
131-
result = prime * result + ((customDescription == null) ? 0 : customDescription.hashCode());
132-
result = prime * result + ((systemCategory == null) ? 0 : systemCategory.hashCode());
62+
result = prime * result + ((categoryId == null) ? 0 : categoryId.hashCode());
63+
result = prime * result + ((humanReadableName == null) ? 0 : humanReadableName.hashCode());
13364
return result;
13465
}
13566

@@ -142,31 +73,22 @@ public boolean equals(Object obj) {
14273
if (getClass() != obj.getClass())
14374
return false;
14475
CategoryDefinition other = (CategoryDefinition) obj;
145-
if (customCategory == null) {
146-
if (other.customCategory != null)
76+
if (categoryId == null) {
77+
if (other.categoryId != null)
14778
return false;
148-
} else if (!customCategory.equals(other.customCategory))
79+
} else if (!categoryId.equals(other.categoryId))
14980
return false;
150-
if (customDescription == null) {
151-
if (other.customDescription != null)
81+
if (humanReadableName == null) {
82+
if (other.humanReadableName != null)
15283
return false;
153-
} else if (!customDescription.equals(other.customDescription))
154-
return false;
155-
if (systemCategory != other.systemCategory)
84+
} else if (!humanReadableName.equals(other.humanReadableName))
15685
return false;
15786
return true;
15887
}
15988

16089
@Override
16190
public String toString() {
162-
if (customCategory == null || customCategory.isEmpty()) {
163-
if (systemCategory != null)
164-
return systemCategory.toString();
165-
else
166-
return "<invalid>";
167-
} else {
168-
return customCategory;
169-
}
91+
return categoryId;
17092
}
17193

17294
/**
@@ -179,86 +101,7 @@ public String toString() {
179101
*/
180102
@Override
181103
public String getHumanReadableDescription() {
182-
if (customCategory != null && !customCategory.isEmpty()) {
183-
// Prefer the description text over the id
184-
if (customDescription != null && !customDescription.isEmpty())
185-
return customDescription;
186-
return customCategory;
187-
} else if (systemCategory != null) {
188-
switch (systemCategory) {
189-
case ALL:
190-
return "All Categories";
191-
case NO_CATEGORY:
192-
return "No Category";
193-
case HARDWARE_INFO:
194-
return "Hardware Information";
195-
case UNIQUE_IDENTIFIER:
196-
return "Unique Identifier";
197-
case LOCATION_INFORMATION:
198-
return "Location Information";
199-
case NETWORK_INFORMATION:
200-
return "Network Information";
201-
case ACCOUNT_INFORMATION:
202-
return "Account Information";
203-
case EMAIL_INFORMATION:
204-
return "E-Mail Information";
205-
case FILE_INFORMATION:
206-
return "File Information";
207-
case BLUETOOTH_INFORMATION:
208-
return "Bluetooth Information";
209-
case VOIP_INFORMATION:
210-
return "Voice-over-IP Information";
211-
case DATABASE_INFORMATION:
212-
return "Database Information";
213-
case PHONE_INFORMATION:
214-
return "Phone Information";
215-
case PHONE_CONNECTION:
216-
return "Phone (Line) Connection";
217-
case INTER_APP_COMMUNICATION:
218-
return "Inter-App Communication";
219-
case VOIP:
220-
return "Voice-over-IP";
221-
case PHONE_STATE:
222-
return "Phone State";
223-
case EMAIL:
224-
return "E-Mail";
225-
case BLUETOOTH:
226-
return "Bluetooth";
227-
case ACCOUNT_SETTINGS:
228-
return "Account Settings";
229-
case VIDEO:
230-
return "Video";
231-
case SYNCHRONIZATION_DATA:
232-
return "Synchronization Data";
233-
case NETWORK:
234-
return "Network";
235-
case EMAIL_SETTINGS:
236-
return "E-Mail Settings";
237-
case FILE:
238-
return "File";
239-
case LOG:
240-
return "Log Files";
241-
case AUDIO:
242-
return "Audio";
243-
case SMS_MMS:
244-
return "SMS / MMS";
245-
case CONTACT_INFORMATION:
246-
return "Contact Information";
247-
case CALENDAR_INFORMATION:
248-
return "Calendar Information";
249-
case SYSTEM_SETTINGS:
250-
return "System Settings";
251-
case IMAGE:
252-
return "Image";
253-
case BROWSER_INFORMATION:
254-
return "Browser Information";
255-
case NFC:
256-
return "NFC";
257-
default:
258-
return "<invalid system category>";
259-
}
260-
} else
261-
return "<invalid>";
104+
return humanReadableName;
262105
}
263106

264107
/**
@@ -270,14 +113,12 @@ public String getHumanReadableDescription() {
270113
* but not, e.g., descriptions
271114
*/
272115
public CategoryDefinition getIdOnlyDescription() {
273-
return new CategoryDefinition(systemCategory, customCategory);
116+
return new CategoryDefinition(categoryId);
274117
}
275118

276119
@Override
277120
public String getID() {
278-
if (systemCategory == null || systemCategory == CATEGORY.NO_CATEGORY)
279-
return customCategory;
280-
return systemCategory.name();
121+
return categoryId;
281122
}
282123

283124
}

soot-infoflow-android/src/soot/jimple/infoflow/android/data/parsers/CategorizedAndroidSourceSinkParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import soot.jimple.infoflow.android.data.AndroidMethod;
2525
import soot.jimple.infoflow.android.data.CategoryDefinition;
26-
import soot.jimple.infoflow.android.data.CategoryDefinition.CATEGORY;
2726
import soot.jimple.infoflow.sourcesSinks.definitions.ISourceSinkDefinition;
2827
import soot.jimple.infoflow.sourcesSinks.definitions.MethodSourceSinkDefinition;
2928
import soot.jimple.infoflow.sourcesSinks.definitions.SourceSinkType;
@@ -50,7 +49,7 @@ public CategorizedAndroidSourceSinkParser(Set<CategoryDefinition> categories, St
5049

5150
public Set<ISourceSinkDefinition> parse() throws IOException {
5251
Set<ISourceSinkDefinition> definitions = new HashSet<>();
53-
CategoryDefinition allCats = new CategoryDefinition(CATEGORY.ALL);
52+
CategoryDefinition allCats = CategoryDefinition.ALL_CATEGORIES;
5453
boolean loadAllCategories = categories.contains(allCats);
5554

5655
BufferedReader rdr = readFile();
@@ -63,7 +62,7 @@ public Set<ISourceSinkDefinition> parse() throws IOException {
6362
while ((line = rdr.readLine()) != null) {
6463
Matcher m = p.matcher(line);
6564
if (m.find()) {
66-
CATEGORY strCat = CATEGORY.valueOf(m.group(5));
65+
String strCat = m.group(5);
6766
CategoryDefinition cat = new CategoryDefinition(strCat);
6867

6968
if (loadAllCategories || categories.contains(cat)) {

0 commit comments

Comments
 (0)