|
1 | 1 | package soot.jimple.infoflow.river; |
2 | 2 |
|
| 3 | +import java.util.HashSet; |
| 4 | +import java.util.Set; |
| 5 | + |
3 | 6 | import org.slf4j.Logger; |
4 | 7 | import org.slf4j.LoggerFactory; |
| 8 | + |
5 | 9 | import soot.jimple.infoflow.InfoflowManager; |
6 | 10 | import soot.jimple.infoflow.handlers.PostAnalysisHandler; |
7 | 11 | import soot.jimple.infoflow.results.DataFlowResult; |
|
10 | 14 | import soot.jimple.infoflow.solver.cfg.IInfoflowCFG; |
11 | 15 | import soot.jimple.infoflow.sourcesSinks.definitions.SourceSinkCondition; |
12 | 16 |
|
13 | | -import java.util.Collections; |
14 | | -import java.util.HashSet; |
15 | | -import java.util.Set; |
16 | | - |
17 | 17 | /** |
18 | | - * Checks whether conditional sinks met their condition and filter those which did not. |
| 18 | + * Checks whether conditional sinks met their condition and filter those which |
| 19 | + * did not. |
19 | 20 | * |
20 | 21 | * @author Tim Lange |
21 | 22 | */ |
22 | 23 | public class ConditionalFlowPostProcessor implements PostAnalysisHandler { |
23 | | - protected final Logger logger = LoggerFactory.getLogger(getClass()); |
| 24 | + protected final Logger logger = LoggerFactory.getLogger(getClass()); |
24 | 25 |
|
25 | | - InfoflowManager manager; |
| 26 | + InfoflowManager manager; |
26 | 27 |
|
27 | | - public ConditionalFlowPostProcessor(InfoflowManager manager) { |
28 | | - this.manager = manager; |
29 | | - } |
| 28 | + public ConditionalFlowPostProcessor(InfoflowManager manager) { |
| 29 | + this.manager = manager; |
| 30 | + } |
30 | 31 |
|
31 | | - @Override |
32 | | - public InfoflowResults onResultsAvailable(InfoflowResults results, IInfoflowCFG cfg) { |
33 | | - if (results.size() == 0) |
34 | | - return results; |
| 32 | + @Override |
| 33 | + public InfoflowResults onResultsAvailable(InfoflowResults results, IInfoflowCFG cfg) { |
| 34 | + if (results.size() == 0) |
| 35 | + return results; |
35 | 36 |
|
36 | | - logger.info("Filtering conditional flows..."); |
37 | | - HashSet<ResultSinkInfo> tbr = new HashSet<>(); |
| 37 | + logger.info("Filtering conditional flows, starting with {} flows...", results.numConnections()); |
| 38 | + HashSet<ResultSinkInfo> tbr = new HashSet<>(); |
38 | 39 |
|
39 | | - for (DataFlowResult dfRes : results.getResultSet()) { |
40 | | - Set<SourceSinkCondition> conditions = dfRes.getSink().getDefinition().getConditions(); |
41 | | - // One of the conditions must match. Within both, a class name and a signature must match. |
42 | | - if (conditions != null && !conditions.isEmpty() |
43 | | - && conditions.stream().noneMatch(cond -> cond.evaluate(dfRes, results))) |
44 | | - tbr.add(dfRes.getSink()); |
45 | | - } |
| 40 | + for (DataFlowResult dfRes : results.getResultSet()) { |
| 41 | + Set<SourceSinkCondition> conditions = dfRes.getSink().getDefinition().getConditions(); |
| 42 | + // One of the conditions must match. Within both, a class name and a signature |
| 43 | + // must match. |
| 44 | + if (conditions != null && !conditions.isEmpty() |
| 45 | + && conditions.stream().noneMatch(cond -> cond.evaluate(dfRes, results))) |
| 46 | + tbr.add(dfRes.getSink()); |
| 47 | + } |
46 | 48 |
|
47 | | - logger.info(String.format("Removed %d flows not meeting their conditions", tbr.size())); |
48 | | - results.removeAll(tbr); |
| 49 | + logger.info(String.format("Removed %d flows not meeting their conditions", tbr.size())); |
| 50 | + results.removeAll(tbr); |
49 | 51 |
|
50 | | - return results; |
51 | | - } |
| 52 | + return results; |
| 53 | + } |
52 | 54 | } |
0 commit comments