Skip to content

Commit 95415f5

Browse files
committed
Add option to report missing methods as well
1 parent 8d4297d commit 95415f5

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/taintWrappers/ReportMissingSummaryWrapper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.util.Comparator;
6+
import java.util.HashMap;
67
import java.util.Map;
78
import java.util.Map.Entry;
89
import java.util.TreeMap;
@@ -33,15 +34,19 @@ public ReportMissingSummaryWrapper(IMethodSummaryProvider flows) {
3334
}
3435

3536
private ConcurrentHashMap<SootClass, AtomicInteger> classSummariesMissing = new ConcurrentHashMap<>();
37+
private ConcurrentHashMap<SootMethod, AtomicInteger> methodSummariesMissing = new ConcurrentHashMap<>();
3638
private boolean prettyPrint = false;
3739
private boolean showAppClasses = false;
40+
private boolean countMethods = false;
3841

3942
@Override
4043
protected void reportMissingMethod(SootMethod method) {
4144
SootClass decl = method.getDeclaringClass();
4245
if (!showAppClasses && decl.isApplicationClass())
4346
return;
4447
count(decl, classSummariesMissing);
48+
if (countMethods)
49+
count(method, methodSummariesMissing);
4550
}
4651

4752
private static <T> void count(T item, Map<T, AtomicInteger> map) {
@@ -71,6 +76,14 @@ public boolean isShowingApplicationClasses() {
7176
return showAppClasses;
7277
}
7378

79+
public boolean isCountMethods() {
80+
return countMethods;
81+
}
82+
83+
public void setCountMethods(boolean countMethods) {
84+
this.countMethods = countMethods;
85+
}
86+
7487
public void writeResults(File file) throws IOException, ParserConfigurationException, TransformerException {
7588
Map<SootClass, Integer> sortedClassSummariesMissing = sortMap(classSummariesMissing);
7689
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
@@ -87,6 +100,23 @@ public void writeResults(File file) throws IOException, ParserConfigurationExcep
87100
Element clazz = doc.createElement("Class");
88101
clazz.setAttribute("Name", i.getKey().getName());
89102
clazz.setAttribute("Count", String.valueOf(i.getValue()));
103+
if (countMethods) {
104+
SootClass c = i.getKey();
105+
Map<SootMethod, AtomicInteger> methods = new HashMap<>(c.getMethods().size());
106+
for (SootMethod m : c.getMethods()) {
107+
AtomicInteger v = methodSummariesMissing.get(m);
108+
if (v != null) {
109+
methods.put(m, v);
110+
}
111+
}
112+
sortMap(methods);
113+
for (Entry<SootMethod, AtomicInteger> m : methods.entrySet()) {
114+
Element method = doc.createElement("Method");
115+
method.setAttribute("Name", m.getKey().getSubSignature());
116+
method.setAttribute("Count", String.valueOf(m.getValue()));
117+
clazz.appendChild(method);
118+
}
119+
}
90120
classes.appendChild(clazz);
91121
}
92122
rootElement.appendChild(classes);

0 commit comments

Comments
 (0)