Skip to content

Commit 550833d

Browse files
committed
Remove Soot classpath implementation from features
1 parent 62e42b0 commit 550833d

21 files changed

+2157
-2292
lines changed

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/code/CodeFeatureHandler.java

Lines changed: 1169 additions & 1244 deletions
Large diffs are not rendered by default.

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/code/type/IsThreadRunFeature.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,33 @@
77
* Feature that checks whether the current method is the run method of a thread
88
*
99
* @author Steven Arzt, Siegfried Rasthofer
10-
*
1110
*/
1211
public class IsThreadRunFeature extends AbstractSootFeature {
1312

14-
public IsThreadRunFeature(String cp) {
15-
super(cp);
16-
}
13+
public IsThreadRunFeature() {
14+
super();
15+
}
1716

18-
@Override
19-
public Type appliesInternal(Method method) {
20-
if (!method.getName().equals("run"))
21-
return Type.FALSE;
17+
@Override
18+
public Type appliesInternal(Method method) {
19+
if (!method.getName().equals("run"))
20+
return Type.FALSE;
2221

23-
SootMethod sm = getSootMethod(method);
24-
if (sm == null)
25-
return Type.NOT_SUPPORTED;
26-
try {
27-
if (this.isOfType(sm.getDeclaringClass().getType(), "java.lang.Runnable"))
28-
return Type.TRUE;
29-
else return Type.FALSE;
30-
} catch (Exception ex) {
31-
System.err.println("Something went wrong:");
32-
ex.printStackTrace();
33-
return Type.NOT_SUPPORTED;
22+
if (method.getSootMethod() == null)
23+
return Type.NOT_SUPPORTED;
24+
try {
25+
if (this.isOfType(method.getSootMethod().getDeclaringClass().getType(), "java.lang.Runnable"))
26+
return Type.TRUE;
27+
else return Type.FALSE;
28+
} catch (Exception ex) {
29+
System.err.println("Something went wrong:");
30+
ex.printStackTrace();
31+
return Type.NOT_SUPPORTED;
32+
}
3433
}
35-
}
36-
37-
@Override
38-
public String toString() {
39-
return "<Method is thread runner>";
40-
}
4134

35+
@Override
36+
public String toString() {
37+
return "<Method is thread runner>";
38+
}
4239
}

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/code/type/MethodBodyContainsObjectFeature.java

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,55 @@
22

33
import de.fraunhofer.iem.swan.data.Method;
44
import soot.Body;
5-
import soot.SootMethod;
65

76
/**
87
* Feature that checks if the body of a method contains a specific object.
9-
*
10-
* @author Siegfried Rasthofer
118
*
9+
* @author Siegfried Rasthofer
1210
*/
1311
public class MethodBodyContainsObjectFeature extends AbstractSootFeature {
14-
private final String objectName;
15-
16-
public MethodBodyContainsObjectFeature(String cp, String objectName) {
17-
super(cp);
18-
this.objectName = objectName.trim().toLowerCase();
19-
}
20-
21-
@Override
22-
public Type appliesInternal(Method method) {
23-
try {
24-
SootMethod sm = getSootMethod(method);
25-
if (sm == null) {
26-
return Type.NOT_SUPPORTED;
27-
}
28-
if (!sm.isConcrete()) return Type.NOT_SUPPORTED;
29-
30-
Body body = null;
31-
try {
32-
body = sm.retrieveActiveBody();
33-
} catch (Exception ex) {
34-
return Type.NOT_SUPPORTED;
35-
}
36-
37-
if (body.toString().toLowerCase().contains(objectName)) return Type.TRUE;
38-
39-
// for(Local local : sm.getActiveBody().getLocals())
40-
// if(local.getType().toString().trim().toLowerCase().contains(objectName)){
41-
// if(objectName.equals("android.location.LocationListener"))
42-
// System.out.println();
43-
// return Type.TRUE;
44-
// }
45-
46-
return Type.FALSE;
47-
} catch (Exception ex) {
48-
System.err.println("Something went wrong:");
49-
ex.printStackTrace();
50-
return Type.NOT_SUPPORTED;
12+
private final String objectName;
13+
14+
public MethodBodyContainsObjectFeature(String objectName) {
15+
super();
16+
this.objectName = objectName.trim().toLowerCase();
5117
}
52-
}
5318

54-
@Override
55-
public String toString() {
56-
return "Method-Body contains object '" + this.objectName;
57-
}
19+
@Override
20+
public Type appliesInternal(Method method) {
21+
try {
22+
23+
if (method.getSootMethod() == null) {
24+
return Type.NOT_SUPPORTED;
25+
}
26+
if (!method.getSootMethod().isConcrete()) return Type.NOT_SUPPORTED;
27+
28+
Body body;
29+
try {
30+
body = method.getSootMethod().retrieveActiveBody();
31+
} catch (Exception ex) {
32+
return Type.NOT_SUPPORTED;
33+
}
34+
35+
if (body.toString().toLowerCase().contains(objectName)) return Type.TRUE;
36+
37+
// for(Local local : sm.getActiveBody().getLocals())
38+
// if(local.getType().toString().trim().toLowerCase().contains(objectName)){
39+
// if(objectName.equals("android.location.LocationListener"))
40+
// System.out.println();
41+
// return Type.TRUE;
42+
// }
43+
44+
return Type.FALSE;
45+
} catch (Exception ex) {
46+
System.err.println("Something went wrong:");
47+
ex.printStackTrace();
48+
return Type.NOT_SUPPORTED;
49+
}
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "Method-Body contains object '" + this.objectName;
55+
}
5856
}

swan-pipeline/src/main/java/de/fraunhofer/iem/swan/features/code/type/MethodCallsMethodFeature.java

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -15,88 +15,84 @@
1515
* one
1616
*
1717
* @author Steven Arzt, Siegfried Rasthofer
18-
*
1918
*/
2019
public class MethodCallsMethodFeature extends AbstractSootFeature {
2120

22-
private final String className;
23-
private final String methodName;
24-
private final boolean substringMatch;
21+
private final String className;
22+
private final String methodName;
23+
private final boolean substringMatch;
2524

26-
public MethodCallsMethodFeature(String cp, String methodName) {
27-
this(cp, "", methodName);
28-
}
25+
public MethodCallsMethodFeature(String methodName) {
26+
this("", methodName);
27+
}
2928

30-
public MethodCallsMethodFeature(String cp, String className,
31-
String methodName) {
32-
this(cp, className, methodName, false);
33-
}
29+
public MethodCallsMethodFeature(String className, String methodName) {
30+
this(className, methodName, false);
31+
}
3432

35-
public MethodCallsMethodFeature(String cp, String className,
36-
String methodName, boolean substringMatch) {
37-
super(cp);
38-
this.className = className;
39-
this.methodName = methodName;
40-
this.substringMatch = substringMatch;
41-
}
33+
public MethodCallsMethodFeature(String className, String methodName, boolean substringMatch) {
34+
super();
35+
this.className = className;
36+
this.methodName = methodName;
37+
this.substringMatch = substringMatch;
38+
}
4239

43-
@Override
44-
public Type appliesInternal(Method method) {
45-
try {
46-
SootMethod sm = getSootMethod(method);
47-
if (sm == null) {
48-
return Type.NOT_SUPPORTED;
49-
}
50-
return checkMethod(sm, new ArrayList<SootMethod>());
51-
} catch (Exception ex) {
52-
System.err.println("Something went wrong:");
53-
ex.printStackTrace();
54-
return Type.NOT_SUPPORTED;
40+
@Override
41+
public Type appliesInternal(Method method) {
42+
try {
43+
44+
if (method.getSootMethod() == null) {
45+
return Type.NOT_SUPPORTED;
46+
}
47+
return checkMethod(method.getSootMethod(), new ArrayList<>());
48+
} catch (Exception ex) {
49+
System.err.println("Something went wrong:");
50+
ex.printStackTrace();
51+
return Type.NOT_SUPPORTED;
52+
}
5553
}
56-
}
5754

58-
public Type checkMethod(SootMethod method, List<SootMethod> doneList) {
59-
if (doneList.contains(method))
60-
return Type.NOT_SUPPORTED;
61-
if (!method.isConcrete())
62-
return Type.NOT_SUPPORTED;
63-
doneList.add(method);
55+
public Type checkMethod(SootMethod method, List<SootMethod> doneList) {
56+
if (doneList.contains(method))
57+
return Type.NOT_SUPPORTED;
58+
if (!method.isConcrete())
59+
return Type.NOT_SUPPORTED;
60+
doneList.add(method);
6461

65-
try {
66-
Body body = null;
67-
try {
68-
body = method.retrieveActiveBody();
69-
} catch (Exception ex) {
70-
return Type.NOT_SUPPORTED;
71-
}
62+
try {
63+
Body body;
64+
try {
65+
body = method.retrieveActiveBody();
66+
} catch (Exception ex) {
67+
return Type.NOT_SUPPORTED;
68+
}
7269

73-
for (Unit u : body.getUnits()) {
74-
if (!(u instanceof Stmt))
75-
continue;
76-
Stmt stmt = (Stmt) u;
77-
if (!stmt.containsInvokeExpr())
78-
continue;
70+
for (Unit u : body.getUnits()) {
71+
if (!(u instanceof Stmt))
72+
continue;
73+
Stmt stmt = (Stmt) u;
74+
if (!stmt.containsInvokeExpr())
75+
continue;
7976

80-
InvokeExpr inv = stmt.getInvokeExpr();
81-
if ((substringMatch
82-
&& inv.getMethod().getName().contains(this.methodName))
83-
|| inv.getMethod().getName().startsWith(this.methodName)) {
84-
if (this.className.isEmpty() || this.className
85-
.equals(inv.getMethod().getDeclaringClass().getName()))
86-
return Type.TRUE;
87-
} else if (checkMethod(inv.getMethod(), doneList) == Type.TRUE)
88-
return Type.TRUE;
89-
}
90-
return Type.FALSE;
91-
} catch (Exception ex) {
92-
System.err.println("Oops: " + ex);
93-
return Type.NOT_SUPPORTED;
77+
InvokeExpr inv = stmt.getInvokeExpr();
78+
if ((substringMatch
79+
&& inv.getMethod().getName().contains(this.methodName))
80+
|| inv.getMethod().getName().startsWith(this.methodName)) {
81+
if (this.className.isEmpty() || this.className
82+
.equals(inv.getMethod().getDeclaringClass().getName()))
83+
return Type.TRUE;
84+
} else if (checkMethod(inv.getMethod(), doneList) == Type.TRUE)
85+
return Type.TRUE;
86+
}
87+
return Type.FALSE;
88+
} catch (Exception ex) {
89+
System.err.println("Oops: " + ex);
90+
return Type.NOT_SUPPORTED;
91+
}
9492
}
95-
}
96-
97-
@Override
98-
public String toString() {
99-
return "Method starting with '" + this.methodName + "' invoked";
100-
}
10193

94+
@Override
95+
public String toString() {
96+
return "Method starting with '" + this.methodName + "' invoked";
97+
}
10298
}

0 commit comments

Comments
 (0)