Skip to content

Commit 033b419

Browse files
committed
refactored categories & bug fixes
1 parent 845a6d0 commit 033b419

File tree

5 files changed

+363
-298
lines changed

5 files changed

+363
-298
lines changed

src/de/fraunhofer/iem/mois/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private void run(String[] args) throws IOException {
123123
writer.printResultsTXT(loader.methods(), tmpFiles, args[3] + File.separator + "txt" + File.separator + "output.txt");
124124
writer.writeResultsQWEL(loader.methods(), args[3] + File.separator + "qwel" + File.separator + "output.qwel");
125125
writer.writeResultsSoot(loader.methods(), args[3] + File.separator + "soot-qwel" + File.separator + "output.sqwel");
126-
writer.printResultsJSON(loader.methods(), tmpFiles, args[3] + File.separator + "json" + File.separator + "output.json" );
126+
writer.printResultsJSON(loader.methods(), args[3] + File.separator + "json" + File.separator + "output.json" );
127127
}
128128

129129
private void runClassifier(HashSet<Category> categories, boolean cweMode)

src/de/fraunhofer/iem/mois/Parser.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.List;
99
import java.util.Set;
1010

11+
import de.fraunhofer.iem.mois.data.RelevantPart;
1112
import org.json.simple.JSONArray;
1213
import org.json.simple.JSONObject;
1314
import org.json.simple.parser.*;
@@ -143,6 +144,11 @@ private void parse(String fileName) {
143144
}
144145
}
145146

147+
public Set<Method> parseFile(String fileName){
148+
parse(fileName);
149+
return methods;
150+
}
151+
146152
@SuppressWarnings("unchecked")
147153
private void loadMethodsFromJsonArray(JSONArray array, String type) {
148154

@@ -217,10 +223,10 @@ private void loadMethodsFromJsonArray(JSONArray array, String type) {
217223
securityLevel = Method.SecLevel.NEUTRAL;
218224
else {
219225
switch (secLevel) {
220-
case "high":
226+
case Constants.AUTH_SAFE:
221227
securityLevel = Method.SecLevel.HIGH;
222228
break;
223-
case "low":
229+
case Constants.AUTH_UNSAFE:
224230
securityLevel = Method.SecLevel.LOW;
225231
break;
226232
default:
@@ -261,16 +267,16 @@ private void loadMethodsFromJsonArray(JSONArray array, String type) {
261267
while (p.hasNext()) {
262268
String t = p.next().toString();
263269
switch (t) {
264-
case "source":
270+
case Constants.SOURCE:
265271
m.addCategoryTrained(Category.SOURCE);
266272
break;
267-
case "sink":
273+
case Constants.SINK:
268274
m.addCategoryTrained(Category.SINK);
269275
break;
270-
case "sanitizer":
276+
case Constants.SANITIZER:
271277
m.addCategoryTrained(Category.SANITIZER);
272278
break;
273-
case "authentication":
279+
case Constants.AUTHENTICATION:
274280
switch (securityLevel) {
275281
case HIGH:
276282
m.addCategoryTrained(Category.AUTHENTICATION_TO_HIGH);
@@ -321,4 +327,18 @@ public Set<String> cwe() {
321327
return cwes;
322328
}
323329

330+
private RelevantPart extractDataInOutObject(JSONObject dataObject) {
331+
332+
JSONArray parameterArray = (JSONArray) dataObject.get(Constants.PARAMETERS);
333+
334+
List<Integer> parameters = new ArrayList<>();
335+
336+
for (Object param : parameterArray) {
337+
338+
if (param instanceof Integer)
339+
parameters.add((Integer) param);
340+
}
341+
return new RelevantPart((boolean) dataObject.get(Constants.RETURN_TYPE), parameters);
342+
}
343+
324344
}

0 commit comments

Comments
 (0)