forked from bigolol/JoanaKeyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSinkOrSource.java
69 lines (61 loc) · 2.63 KB
/
SinkOrSource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package joanakeygui;
/**
*
* @author holger
*/
public class SinkOrSource {
private String selectionMethod;
private String selection;
private int methodParam;
private String securityLevel;
public static SinkOrSource createMethod(String selection, String securityLevel) {
SinkOrSource sinkOrSource = new SinkOrSource();
sinkOrSource.selectionMethod = "callsToMethod";
sinkOrSource.securityLevel = securityLevel;
return addSelectionAndParamForMethod(sinkOrSource, selection);
}
private static SinkOrSource addSelectionAndParamForMethod(SinkOrSource sinkOrSource, String selection) {
if (selection.endsWith("this")) {
sinkOrSource.methodParam = 0;
sinkOrSource.selection = selection.substring(0, selection.length() - "this".length());
} else {
String[] split = selection.split("<param>");
int pos = Integer.valueOf(split[1].trim());
sinkOrSource.methodParam = pos;
sinkOrSource.selection = split[0];
}
return sinkOrSource;
}
public static SinkOrSource createProgramPart(String selection, String securityLevel) {
SinkOrSource sinkOrSource = new SinkOrSource();
sinkOrSource.selectionMethod = "programPart";
sinkOrSource.selection = selection;
sinkOrSource.securityLevel = securityLevel;
return sinkOrSource;
}
public String generateJson() {
String templateStr = "securityLevel : \"SEC_LEVEL\", description : {DESCR}";
String descrTemplateMethod = "from : \"callsToMethod\", method : \"METHOD\", paramPos : PARAMPOS";
String descrTemplateProgramPart = "from : \"programPart\", programPart : \"PROGRAMPART\"";
if (selectionMethod.equals("programPart")) {
String created = templateStr.replace("SEC_LEVEL", securityLevel);
String desc = descrTemplateProgramPart.replace("PROGRAMPART", selection);
return created.replace("DESCR", desc);
} else if (selectionMethod.equals("callsToMethod")) {
String created = templateStr.replace("SEC_LEVEL", securityLevel);
String desc = descrTemplateMethod.replace("METHOD", selection);
desc = desc.replace("PARAMPOS", String.valueOf(methodParam));
return created.replace("DESCR", desc);
}
return "";
}
@Override
public String toString() {
return selectionMethod + ": " + selection;
}
}