Skip to content

Commit d76250a

Browse files
committed
Merge branch 'develop' of github.com:secure-software-engineering/FlowDroid into develop
2 parents 093a2b2 + b44346b commit d76250a

20 files changed

Lines changed: 294 additions & 73 deletions

soot-infoflow-android/src/soot/jimple/infoflow/android/InfoflowAndroidConfiguration.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ public static enum CallbackAnalyzer {
698698
private final AnalysisFileConfiguration analysisFileConfig = new AnalysisFileConfiguration();
699699

700700
private boolean mergeDexFiles = false;
701+
private static boolean createActivityEntryMethods = true;
701702

702703
public InfoflowAndroidConfiguration() {
703704
// We need to adapt some of the defaults. Most people don't care about
@@ -722,6 +723,7 @@ public void merge(InfoflowConfiguration config) {
722723
this.analysisFileConfig.merge(androidConfig.analysisFileConfig);
723724

724725
this.mergeDexFiles = androidConfig.mergeDexFiles;
726+
this.createActivityEntryMethods = androidConfig.createActivityEntryMethods;
725727
}
726728
}
727729

@@ -806,6 +808,27 @@ public void setMergeDexFiles(boolean mergeDexFiles) {
806808
this.mergeDexFiles = mergeDexFiles;
807809
}
808810

811+
/**
812+
* Gets if Flowdroid should create new Methods when creating the Activity Entry
813+
* point
814+
*
815+
* @return true/false
816+
*/
817+
public static boolean getCreateActivityEntryMethods() {
818+
return createActivityEntryMethods;
819+
}
820+
821+
/**
822+
* Sets if Flow Flowdroid should create new Methods when creating the Activity
823+
* Entry point
824+
*
825+
* @param createActivityEntryMethods boolean that is true if Methods should be
826+
* created
827+
*/
828+
public static void setCreateActivityEntryMethods(boolean createActivityEntryMethods) {
829+
InfoflowAndroidConfiguration.createActivityEntryMethods = createActivityEntryMethods;
830+
}
831+
809832
@Override
810833
public int hashCode() {
811834
final int prime = 31;

soot-infoflow-android/src/soot/jimple/infoflow/android/SetupApplication.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import soot.PackManager;
3636
import soot.Scene;
3737
import soot.SootClass;
38+
import soot.SootField;
3839
import soot.SootMethod;
3940
import soot.Unit;
4041
import soot.jimple.Stmt;
@@ -80,6 +81,7 @@
8081
import soot.jimple.infoflow.config.IInfoflowConfig;
8182
import soot.jimple.infoflow.data.Abstraction;
8283
import soot.jimple.infoflow.data.FlowDroidMemoryManager.PathDataErasureMode;
84+
import soot.jimple.infoflow.entryPointCreators.SimulatedCodeElementTag;
8385
import soot.jimple.infoflow.handlers.PostAnalysisHandler;
8486
import soot.jimple.infoflow.handlers.PreAnalysisHandler;
8587
import soot.jimple.infoflow.handlers.ResultsAvailableHandler;
@@ -1897,4 +1899,28 @@ public void setValueProvider(IValueProvider valueProvider) {
18971899
this.valueProvider = valueProvider;
18981900
}
18991901

1902+
/**
1903+
* Removes all simulated code elements generated during entry point creation and
1904+
* ICC instrumentation from the Soot Scene
1905+
*/
1906+
public void removeSimulatedCodeElements() {
1907+
for (Iterator<SootClass> scIt = Scene.v().getClasses().iterator(); scIt.hasNext();) {
1908+
SootClass sc = scIt.next();
1909+
if (sc.hasTag(SimulatedCodeElementTag.TAG_NAME))
1910+
scIt.remove();
1911+
else {
1912+
for (Iterator<SootMethod> smIt = sc.getMethods().iterator(); smIt.hasNext();) {
1913+
SootMethod sm = smIt.next();
1914+
if (sm.hasTag(SimulatedCodeElementTag.TAG_NAME))
1915+
smIt.remove();
1916+
}
1917+
for (Iterator<SootField> sfIt = sc.getFields().iterator(); sfIt.hasNext();) {
1918+
SootField sf = sfIt.next();
1919+
if (sf.hasTag(SimulatedCodeElementTag.TAG_NAME))
1920+
sfIt.remove();
1921+
}
1922+
}
1923+
}
1924+
}
1925+
19001926
}

soot-infoflow-android/src/soot/jimple/infoflow/android/callbacks/filters/ApplicationCallbackFilter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class ApplicationCallbackFilter extends AbstractCallbackFilter {
2525
/**
2626
* Creates a new instance of the {@link ApplicationCallbackFilter} class
2727
*
28-
* @param entrypoints
29-
* The set of entry points into the app
28+
* @param entrypoints The set of entry points into the app
3029
*/
3130
public ApplicationCallbackFilter(Set<SootClass> entrypoints) {
3231
this(getApplicationClass(entrypoints));
@@ -35,14 +34,14 @@ public ApplicationCallbackFilter(Set<SootClass> entrypoints) {
3534
/**
3635
* Scans through the list of entry points and finds the application class
3736
*
38-
* @param entrypoints
39-
* A set containing all entry points in the current app
37+
* @param entrypoints A set containing all entry points in the current app
4038
* @return The name of the application class if one exists, otherwise null
4139
*/
4240
private static String getApplicationClass(Set<SootClass> entrypoints) {
4341
SootClass scApplication = Scene.v().getSootClassUnsafe("android.app.Application");
4442
for (SootClass sc : entrypoints) {
45-
if (sc != null && Scene.v().getOrMakeFastHierarchy().canStoreType(sc.getType(), scApplication.getType())) {
43+
if (sc != null && scApplication != null
44+
&& Scene.v().getOrMakeFastHierarchy().canStoreType(sc.getType(), scApplication.getType())) {
4645
return sc.getName();
4746
}
4847
}
@@ -52,8 +51,7 @@ private static String getApplicationClass(Set<SootClass> entrypoints) {
5251
/**
5352
* Creates a new instance of the {@link ApplicationCallbackFilter} class
5453
*
55-
* @param applicationClass
56-
* The class extending android.app.Application
54+
* @param applicationClass The class extending android.app.Application
5755
*/
5856
public ApplicationCallbackFilter(String applicationClass) {
5957
super();

soot-infoflow-android/src/soot/jimple/infoflow/android/entryPointCreators/components/ActivityEntryPointCreator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import soot.jimple.JimpleBody;
2424
import soot.jimple.NopStmt;
2525
import soot.jimple.Stmt;
26+
import soot.jimple.infoflow.android.InfoflowAndroidConfiguration;
2627
import soot.jimple.infoflow.android.entryPointCreators.AndroidEntryPointConstants;
2728
import soot.jimple.infoflow.android.manifest.IManifestHandler;
2829
import soot.jimple.infoflow.cfg.LibraryClassPatcher;
@@ -228,9 +229,12 @@ protected void createAdditionalFields() {
228229

229230
@Override
230231
protected void createAdditionalMethods() {
231-
createGetIntentMethod();
232-
createSetIntentMethod();
233-
createSetResultMethod();
232+
if (InfoflowAndroidConfiguration.getCreateActivityEntryMethods()) {
233+
234+
createGetIntentMethod();
235+
createSetIntentMethod();
236+
createSetResultMethod();
237+
}
234238
}
235239

236240
/**

soot-infoflow-android/src/soot/jimple/infoflow/android/manifest/IManifestHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.HashSet;
77
import java.util.List;
88
import java.util.Set;
9+
import java.util.stream.Collectors;
910

1011
import soot.jimple.infoflow.util.SystemClassHandler;
1112

@@ -104,6 +105,12 @@ public default Set<String> getEntryPointClasses() {
104105
for (IAndroidComponent node : getAllComponents())
105106
checkAndAddComponent(entryPoints, node);
106107

108+
if (entryPoints.isEmpty()){
109+
//if no entry point is detected at all, the app is likely be malware, add all components
110+
List<IAndroidComponent> allEnabled = getAllComponents().stream().filter(c -> c.isEnabled()).collect(Collectors.toList());
111+
allEnabled.forEach(e->entryPoints.add(e.getNameString()));
112+
}
113+
107114
if (app != null) {
108115
String appName = app.getName();
109116
if (appName != null && !appName.isEmpty())

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/generator/SummaryGenerationTaintWrapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public Set<Abstraction> getTaintsForMethod(Stmt stmt, Abstraction d1, Abstractio
8181

8282
// Do create the gap
8383
GapDefinition gap = gapManager.getOrCreateGapForCall(summaries, stmt);
84+
if (gap == null)
85+
return Collections.singleton(taintedPath);
8486

8587
// Produce a continuation
8688
res = new HashSet<Abstraction>();

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/generator/SummaryGenerator.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,7 @@ protected MethodSummaries createMethodSummary(String classpath, final String met
613613
logger.info(String.format("Computing method summary for %s...", methodSig));
614614
long nanosBeforeMethod = System.nanoTime();
615615

616-
final SourceSinkFactory sourceSinkFactory = new SourceSinkFactory(
617-
config.getAccessPathConfiguration().getAccessPathLength());
618-
final SummarySourceSinkManager sourceSinkManager = new SummarySourceSinkManager(methodSig, parentClass,
619-
sourceSinkFactory);
616+
final SummarySourceSinkManager sourceSinkManager = createSourceSinkManager(methodSig, parentClass);
620617
final MethodSummaries summaries = new MethodSummaries();
621618

622619
final SummaryInfoflow infoflow = initInfoflow(summaries, gapManager);
@@ -644,10 +641,10 @@ public void onResultsAvailable(IInfoflowCFG cfg, InfoflowResults results) {
644641
InfoflowResultPostProcessor processor;
645642
if (infoflow.getManager() != null)
646643
processor = new InfoflowResultPostProcessor(listener.getResult(), infoflow.getManager(), methodSig,
647-
sourceSinkFactory, gapManager);
644+
sourceSinkManager.getSourceSinkFactory(), gapManager);
648645
else
649646
processor = new InfoflowResultPostProcessor(listener.getResult(), infoflow.getConfig(), methodSig,
650-
sourceSinkFactory, gapManager);
647+
sourceSinkManager.getSourceSinkFactory(), gapManager);
651648
processor.postProcess(summaries);
652649

653650
if (resultHandler != null)
@@ -669,6 +666,21 @@ public void onResultsAvailable(IInfoflowCFG cfg, InfoflowResults results) {
669666
return summaries;
670667
}
671668

669+
/**
670+
* Creates the source/sink manager for introducing new sources and sinks into
671+
* the taint analysis
672+
*
673+
* @param methodSig The signature of the method for which to create sources
674+
* and sinks, i.e., the method to be summarized
675+
* @param parentClass The class that contains the method to summarize
676+
* @return The new {@link SummarySourceSinkManager}
677+
*/
678+
protected SummarySourceSinkManager createSourceSinkManager(final String methodSig, final String parentClass) {
679+
final SourceSinkFactory sourceSinkFactory = new SourceSinkFactory(
680+
config.getAccessPathConfiguration().getAccessPathLength());
681+
return new SummarySourceSinkManager(methodSig, parentClass, sourceSinkFactory);
682+
}
683+
672684
private BaseEntryPointCreator createEntryPoint(Collection<String> entryPoints, String parentClass) {
673685
SequentialEntryPointCreator dEntryPointCreater = new SequentialEntryPointCreator(entryPoints);
674686

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package soot.jimple.infoflow.methodSummary.generator.gaps;
2+
3+
import java.util.Collection;
4+
import java.util.Set;
5+
6+
import soot.Local;
7+
import soot.jimple.Stmt;
8+
import soot.jimple.infoflow.data.Abstraction;
9+
import soot.jimple.infoflow.methodSummary.data.summary.GapDefinition;
10+
import soot.jimple.infoflow.methodSummary.data.summary.MethodSummaries;
11+
import soot.jimple.infoflow.solver.cfg.IInfoflowCFG;
12+
13+
/**
14+
* A pseudo gap manager that never creates any gaps
15+
*
16+
* @author Steven Arzt
17+
*
18+
*/
19+
public class NullGapManager implements IGapManager {
20+
21+
@Override
22+
public GapDefinition getOrCreateGapForCall(MethodSummaries flows, Stmt gapCall) {
23+
return null;
24+
}
25+
26+
@Override
27+
public GapDefinition getGapForCall(Stmt gapCall) {
28+
return null;
29+
}
30+
31+
@Override
32+
public boolean isLocalReferencedInGap(Local local) {
33+
return false;
34+
}
35+
36+
@Override
37+
public Set<GapDefinition> getGapDefinitionsForLocalUse(Local local) {
38+
return null;
39+
}
40+
41+
@Override
42+
public Set<GapDefinition> getGapDefinitionsForLocalDef(Local local) {
43+
return null;
44+
}
45+
46+
@Override
47+
public boolean needsGapConstruction(Stmt stmt, Abstraction abs, IInfoflowCFG icfg) {
48+
return false;
49+
}
50+
51+
@Override
52+
public Collection<Stmt> getAllGapStmts() {
53+
return null;
54+
}
55+
56+
}

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/postProcessor/InfoflowResultPostProcessor.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ public Thread newThread(Runnable r) {
161161
// Reconstruct the sources
162162
for (Stmt stmt : collectedAbstractions.get(a)) {
163163
abstractionCount++;
164-
165-
// If this abstraction is directly the source abstraction,
166-
// we do not
167-
// need to construct paths
168-
if (a.getSourceContext() != null) {
169-
continue;
170-
}
171-
172164
for (SummaryResultInfo si : pathBuilder.getResultInfos()) {
173165
final AccessPath sourceAP = si.getSourceInfo().getAccessPath();
174166
final AccessPath sinkAP = si.getSinkInfo().getAccessPath();

0 commit comments

Comments
 (0)