Skip to content

Commit 37ad1c0

Browse files
authored
Merge pull request #373 from stefanie-koss/parameterForSummaryGenerator
Introduce distinct parameters for loading and analyzing full JAR duri…
2 parents 6878d37 + ee597db commit 37ad1c0

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/Main.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Main {
3939

4040
private static final String OPTION_FORCE_OVERWRITE = "fo";
4141
private static final String OPTION_LOAD_FULL_JAR = "lf";
42+
private static final String OPTION_SUMMARIZE_FULL_JAR = "sf";
4243
private static final String OPTION_EXCLUDE = "e";
4344
private static final String OPTION_REPEAT = "r";
4445
private static final String OPTION_FLOW_TIMEOUT = "ft";
@@ -63,7 +64,9 @@ private void initializeCommandLineOptions() {
6364

6465
options.addOption(OPTION_FORCE_OVERWRITE, "forceoverwrite", false,
6566
"Silently overwrite summary files in output directory");
66-
options.addOption(OPTION_LOAD_FULL_JAR, "loadfulljar", false, "Summarizes all classes from the given JAR file");
67+
options.addOption(OPTION_LOAD_FULL_JAR, "loadfulljar", false, "Loads all classes from the given JAR file");
68+
options.addOption(OPTION_SUMMARIZE_FULL_JAR, "summarizefulljar", false,
69+
"Summarizes all classes from the given JAR file");
6770
options.addOption(OPTION_EXCLUDE, "exclude", true, "Excludes the given class(es)");
6871
options.addOption(OPTION_REPEAT, "repeat", true,
6972
"Repeats the summary generation multiple times. Useful for performance measurements.");
@@ -85,10 +88,11 @@ public void run(final String[] args) throws FileNotFoundException, XMLStreamExce
8588

8689
final boolean forceOverwrite = cmd.hasOption(OPTION_FORCE_OVERWRITE);
8790
boolean loadFullJAR = cmd.hasOption(OPTION_LOAD_FULL_JAR);
91+
boolean summarizeFullJAR = cmd.hasOption(OPTION_SUMMARIZE_FULL_JAR);
8892

8993
// We need proper parameters
9094
String[] extraArgs = cmd.getArgs();
91-
if (extraArgs.length < 2 || (extraArgs.length < 3 && !loadFullJAR)) {
95+
if (extraArgs.length < 2 || (extraArgs.length < 3 && !summarizeFullJAR)) {
9296
printHelpMessage();
9397
return;
9498
}
@@ -105,7 +109,7 @@ public void run(final String[] args) throws FileNotFoundException, XMLStreamExce
105109

106110
// Collect the classes to be analyzed from our command line
107111
List<String> classesToAnalyze = new ArrayList<>();
108-
if (!loadFullJAR) {
112+
if (!summarizeFullJAR) {
109113
for (int i = 2; i < extraArgs.length; i++) {
110114
if (extraArgs[i].startsWith("-")) {
111115
printHelpMessage();
@@ -122,6 +126,7 @@ public void run(final String[] args) throws FileNotFoundException, XMLStreamExce
122126
}
123127

124128
generator.getConfig().setLoadFullJAR(loadFullJAR);
129+
generator.getConfig().setSummarizeFullJAR(summarizeFullJAR);
125130
generator.getConfig().setExcludes(excludes);
126131

127132
// Set optional settings
@@ -227,7 +232,7 @@ private void printHelpMessage() {
227232
System.out.println();
228233

229234
final HelpFormatter formatter = new HelpFormatter();
230-
formatter.printHelp("soot-infoflow-cmd <JAR File> <Output Directory> <Classes...> [OPTIONS]", options);
235+
formatter.printHelp("soot-infoflow-summaries <JAR File> <Output Directory> <Classes...> [OPTIONS]", options);
231236
}
232237

233238
private static void createSummaries(SummaryGenerator generator, List<String> classesToAnalyze,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public ClassSummaries createMethodSummaries(String classpath, Collection<String>
268268
}
269269

270270
Options.v().set_output_format(Options.output_format_none);
271-
if (hasWildcard || config.getLoadFullJAR())
271+
if (hasWildcard || config.getLoadFullJAR() || config.getSummarizeFullJAR())
272272
Options.v().set_process_dir(Arrays.asList(classpath.split(File.pathSeparator)));
273273
else
274274
Options.v().set_soot_classpath(classpath);
@@ -289,7 +289,7 @@ public ClassSummaries createMethodSummaries(String classpath, Collection<String>
289289
Scene.v().loadNecessaryClasses();
290290

291291
Set<ClassAnalysisTask> realClasses = new HashSet<>(classNames.size());
292-
if (config.getLoadFullJAR()) {
292+
if (config.getSummarizeFullJAR()) {
293293
for (Iterator<SootClass> scIt = Scene.v().getApplicationClasses().snapshotIterator(); scIt.hasNext();) {
294294
SootClass sc = scIt.next();
295295
Scene.v().forceResolve(sc.getName(), SootClass.SIGNATURES);

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

+25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class SummaryGeneratorConfiguration extends InfoflowConfiguration {
1515

1616
protected boolean loadFullJAR = false;
17+
protected boolean summarizeFullJAR = false;
1718
protected String androidPlatformDir = "";
1819

1920
protected Set<String> excludes = null;
@@ -58,6 +59,7 @@ public void merge(InfoflowConfiguration config) {
5859
SummaryGeneratorConfiguration summaryConfig = (SummaryGeneratorConfiguration) config;
5960
this.androidPlatformDir = summaryConfig.androidPlatformDir;
6061
this.loadFullJAR = summaryConfig.loadFullJAR;
62+
this.summarizeFullJAR = summaryConfig.summarizeFullJAR;
6163

6264
this.excludes = summaryConfig.excludes == null || summaryConfig.excludes.isEmpty() ? null
6365
: new HashSet<>(summaryConfig.excludes);
@@ -127,6 +129,26 @@ public boolean getLoadFullJAR() {
127129
return this.loadFullJAR;
128130
}
129131

132+
/**
133+
* Sets whether all classes from the target JAR file shall be summarized.
134+
*
135+
* @param summarizeFullJAR True if all classes from the target JAR file shall be
136+
* summarized, otherwise false.
137+
*/
138+
public void setSummarizeFullJAR(boolean summarizeFullJAR) {
139+
this.summarizeFullJAR = summarizeFullJAR;
140+
}
141+
142+
/**
143+
* Gets whether all classes from the target JAR file shall be summarized.
144+
*
145+
* @return True if all classes from the target JAR file shall be summarized,
146+
* otherwise false.
147+
*/
148+
public boolean getSummarizeFullJAR() {
149+
return this.summarizeFullJAR;
150+
}
151+
130152
/**
131153
* Sets the set of classes to be excluded from the analysis. Use pkg.* to
132154
* exclude all classes in package "pkg"
@@ -315,6 +337,7 @@ public int hashCode() {
315337
result = prime * result + (int) (classSummaryTimeout ^ (classSummaryTimeout >>> 32));
316338
result = prime * result + ((excludes == null) ? 0 : excludes.hashCode());
317339
result = prime * result + (loadFullJAR ? 1231 : 1237);
340+
result = prime * result + (summarizeFullJAR ? 1231 : 1237);
318341
result = prime * result + repeatCount;
319342
result = prime * result + (summarizeHashCodeEquals ? 1231 : 1237);
320343
result = prime * result + (useDefaultSummaries ? 1231 : 1237);
@@ -352,6 +375,8 @@ public boolean equals(Object obj) {
352375
return false;
353376
if (loadFullJAR != other.loadFullJAR)
354377
return false;
378+
if (summarizeFullJAR != other.summarizeFullJAR)
379+
return false;
355380
if (repeatCount != other.repeatCount)
356381
return false;
357382
if (summarizeHashCodeEquals != other.summarizeHashCodeEquals)

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

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SummaryGeneratorFactory {
1313
private final boolean flowSensitiveAliasing = true;
1414
private final boolean useRecursiveAccessPaths = true;
1515
private final boolean loadFullJAR = true;
16+
private final boolean summarizeFullJAR = true;
1617

1718
/**
1819
* Initializes the summary generator object
@@ -28,6 +29,7 @@ public SummaryGenerator initSummaryGenerator() {
2829
enableImplicitFlows ? ImplicitFlowMode.AllImplicitFlows : ImplicitFlowMode.NoImplicitFlows);
2930
s.getConfig().setFlowSensitiveAliasing(flowSensitiveAliasing);
3031
s.getConfig().setLoadFullJAR(loadFullJAR);
32+
s.getConfig().setSummarizeFullJAR(summarizeFullJAR);
3133

3234
return s;
3335
}

soot-infoflow-summaries/test/soot/jimple/infoflow/test/methodSummary/junit/JDKTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ protected SummaryGenerator getSummary() {
168168
sg.getConfig().getAccessPathConfiguration().setAccessPathLength(4);
169169
sg.getConfig().getAccessPathConfiguration().setUseRecursiveAccessPaths(true);
170170
sg.getConfig().setLoadFullJAR(false);
171+
sg.getConfig().setSummarizeFullJAR(false);
171172
sg.getConfig().setEnableExceptionTracking(true);
172173
return sg;
173174
}

0 commit comments

Comments
 (0)