Skip to content

Commit eee57b2

Browse files
committed
added some logging and methods for obtaining referenced classes even before the Soot scene is loaded
1 parent 257032a commit eee57b2

4 files changed

Lines changed: 73 additions & 38 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import java.util.stream.Collectors;
1717
import java.util.stream.Stream;
1818

19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
1922
import heros.solver.Pair;
2023
import heros.solver.PathEdge;
2124
import soot.ArrayType;
@@ -101,6 +104,8 @@
101104
*/
102105
public class SummaryTaintWrapper implements IReversibleTaintWrapper, ICollectionsSupport {
103106

107+
private final Logger logger = LoggerFactory.getLogger(getClass());
108+
104109
protected InfoflowManager manager;
105110
private AtomicInteger wrapperHits = new AtomicInteger();
106111
private AtomicInteger wrapperMisses = new AtomicInteger();
@@ -362,12 +367,14 @@ private AccessPathPropagator getOriginalCallSite(AccessPathPropagator propagator
362367
*/
363368
public SummaryTaintWrapper(IMethodSummaryProvider flows) {
364369
this.flows = flows;
370+
logger.info("Initializing summary taint wrapper with summaries for {} classes...",
371+
flows.getAllClassesWithSummaries().size());
365372
setContainerStrategyFactory(new DefaultConfigContainerStrategyFactory());
366373
}
367374

368375
/**
369-
* Creates a new instance of the {@link SummaryTaintWrapper} class.
370-
* Uses summaries present within the StubDroid JAR file.
376+
* Creates a new instance of the {@link SummaryTaintWrapper} class. Uses
377+
* summaries present within the StubDroid JAR file.
371378
*/
372379
public SummaryTaintWrapper() throws URISyntaxException, IOException {
373380
this(new EagerSummaryProvider());

soot-infoflow/src/soot/jimple/infoflow/river/conditions/SignatureFlowCondition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
import java.util.Collections;
44
import java.util.HashSet;
55
import java.util.Set;
6+
import java.util.stream.Collectors;
67

78
import heros.solver.Pair;
89
import soot.Scene;
910
import soot.SootClass;
1011
import soot.SootMethod;
1112
import soot.Type;
1213
import soot.jimple.Stmt;
14+
import soot.jimple.infoflow.data.SootMethodAndClass;
1315
import soot.jimple.infoflow.results.DataFlowResult;
1416
import soot.jimple.infoflow.results.InfoflowResults;
1517
import soot.jimple.infoflow.results.ResultSinkInfo;
1618
import soot.jimple.infoflow.results.ResultSourceInfo;
1719
import soot.jimple.infoflow.river.ConditionalSecondarySourceDefinition;
1820
import soot.jimple.infoflow.sourcesSinks.definitions.SourceSinkCondition;
21+
import soot.jimple.infoflow.util.SootMethodRepresentationParser;
1922
import soot.util.MultiMap;
2023

2124
/**
@@ -314,4 +317,10 @@ public String toString() {
314317
return "AdditionalFlowCondition: " + "classNamesOnPath=" + classNamesOnPath + ", signaturesOnPath="
315318
+ signaturesOnPath + ", excludedClasses=" + excludedClassNames;
316319
}
320+
321+
@Override
322+
public Set<SootMethodAndClass> getReferencedMethodDefs() {
323+
final SootMethodRepresentationParser rep = SootMethodRepresentationParser.v();
324+
return signaturesOnPath.stream().map(s -> rep.parseSootMethodString(s)).collect(Collectors.toSet());
325+
}
317326
}

soot-infoflow/src/soot/jimple/infoflow/sourcesSinks/definitions/SourceSinkCondition.java

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import java.util.Collections;
44
import java.util.Set;
5+
import java.util.stream.Collectors;
56

7+
import soot.Scene;
68
import soot.SootClass;
79
import soot.SootMethod;
10+
import soot.jimple.infoflow.data.SootMethodAndClass;
811
import soot.jimple.infoflow.results.DataFlowResult;
912
import soot.jimple.infoflow.results.InfoflowResults;
1013

@@ -17,40 +20,49 @@
1720
*/
1821
public abstract class SourceSinkCondition {
1922

20-
/**
21-
* Evaluates the condition on the given data flow result
22-
*
23-
* @param result The data flow result
24-
* @param results All results of this data flow analysis
25-
* @return True if the given data flow result matches the condition, otherwise
26-
* false
27-
*/
28-
public abstract boolean evaluate(DataFlowResult result, InfoflowResults results);
29-
30-
/**
31-
* Gets all methods referenced by this condition
32-
*
33-
* @return The methods referenced by this condition
34-
*/
35-
public Set<SootMethod> getReferencedMethods() {
36-
return Collections.emptySet();
37-
}
38-
39-
/**
40-
* Gets all classes referenced by this condition
41-
*
42-
* @return The classes referenced by this condition
43-
*/
44-
public Set<SootClass> getReferencedClasses() {
45-
return Collections.emptySet();
46-
}
47-
48-
/**
49-
* Gets all classes excluded by this condition
50-
*
51-
* @return The classes excluded by this condition
52-
*/
53-
public Set<SootClass> getExcludedClasses() {
54-
return Collections.emptySet();
55-
}
23+
/**
24+
* Evaluates the condition on the given data flow result
25+
*
26+
* @param result The data flow result
27+
* @param results All results of this data flow analysis
28+
* @return True if the given data flow result matches the condition, otherwise
29+
* false
30+
*/
31+
public abstract boolean evaluate(DataFlowResult result, InfoflowResults results);
32+
33+
/**
34+
* Gets all methods referenced by this condition
35+
*
36+
* @return The methods referenced by this condition
37+
*/
38+
public Set<SootMethod> getReferencedMethods() {
39+
Set<SootMethodAndClass> refs = getReferencedMethodDefs();
40+
return refs == null || refs.isEmpty() ? Collections.emptySet()
41+
: refs.stream().map(d -> Scene.v().grabMethod(d.getSignature())).collect(Collectors.toSet());
42+
}
43+
44+
/**
45+
* Gets all definitions of methods referenced by this condition
46+
*
47+
* @return All definitions of methods referenced by this condition
48+
*/
49+
public abstract Set<SootMethodAndClass> getReferencedMethodDefs();
50+
51+
/**
52+
* Gets all classes referenced by this condition
53+
*
54+
* @return The classes referenced by this condition
55+
*/
56+
public Set<SootClass> getReferencedClasses() {
57+
return Collections.emptySet();
58+
}
59+
60+
/**
61+
* Gets all classes excluded by this condition
62+
*
63+
* @return The classes excluded by this condition
64+
*/
65+
public Set<SootClass> getExcludedClasses() {
66+
return Collections.emptySet();
67+
}
5668
}

soot-infoflow/src/soot/jimple/infoflow/sourcesSinks/manager/BaseSourceSinkManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,14 @@ public SourceInfo getSourceInfo(Stmt sCallSite, InfoflowManager manager) {
434434
if (sCallSite.hasTag(SimulatedCodeElementTag.TAG_NAME))
435435
return null;
436436

437+
// Look up the source definition
437438
Collection<ISourceSinkDefinition> defs = getSource(sCallSite, manager.getICFG());
439+
if (defs == null || defs.isEmpty())
440+
return null;
441+
442+
// We seem to have a source for this statement. Create the detailed
443+
// specification object. Note that subsequent filtering may still invalidate the
444+
// source.
438445
Collection<Pair<AccessPath, ISourceSinkDefinition>> pairs = createSourceInfoPairs(sCallSite, manager, defs);
439446
return pairs.size() > 0 ? new SourceInfo(pairs) : null;
440447
}

0 commit comments

Comments
 (0)