Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
linghuiluo committed Sep 25, 2020
1 parent 4e4705f commit 24f197f
Show file tree
Hide file tree
Showing 183 changed files with 5,273 additions and 6,435 deletions.
13 changes: 13 additions & 0 deletions cova/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
104 changes: 65 additions & 39 deletions cova/src/main/java/cova/Main.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
/**
* Copyright (C) 2019 Linghui Luo
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Copyright (C) 2019 Linghui Luo
*
* <p>This library is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version
* 2.1 of the License, or (at your option) any later version.
*
* <p>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*/
package cova;
import java.io.IOException;

import cova.runner.AndroidApkAnalyzer;
import cova.runner.JavaAppAnalyzer;
import java.io.IOException;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import cova.runner.AndroidApkAnalyzer;
import cova.runner.JavaAppAnalyzer;

public class Main {

public static void main(String[] args) throws ParseException, IOException {
Expand All @@ -36,53 +32,84 @@ public static void main(String[] args) throws ParseException, IOException {
options.addOption("t", "timeout", true, "COVA analysis timout duration in minutes.");

options.addOption("android", false, "Analyze Android APK");
options.addOption("p", "platform", true,
"Android: The location of the android platform jars.");
options.addOption("apk", "apkLocation", true,
options.addOption("p", "platform", true, "Android: The location of the android platform jars.");
options.addOption(
"apk",
"apkLocation",
true,
"Android: The location of the APK file and it can an be a single Apk file or a directory.");
options.addOption("s", "standalone", true,
options.addOption(
"s",
"standalone",
true,
"Android: <arg> = true, if runs cova in standalone mode. <arg> = false, if runs flowdroid and cova afterwards. The default value is false");
options.addOption("expr", false,
"Enable experimentation mode.");
options.addOption("expr", false, "Enable experimentation mode.");
options.addOption("output_csv", false, "Android: Print results in CSV files.");

options.addOption("java", false, "Analyze Java application");
options.addOption("app", true, "Java: The name of the Java application.");
options.addOption("main", true, "Java: The main class of the Java application.");
options.addOption("lib", true, "Java: The location of rt.jar");
options.addOption("cp", true, "Java: The class path of the Java application.");
options.addOption("config", true,
options.addOption(
"config",
true,
"The path of config files specified for your application: at least one of Configuration_APIs.txt, IO_APIs.txt and UICallback_APIs.txt.");

// options for analysis
options.addOption("ITaint", "impreciseTaintCreation", true,
options.addOption(
"ITaint",
"impreciseTaintCreation",
true,
"<arg> = true, if enables ImpreciseTaintCreationRule.");
options.addOption("CTaint", "concreteTaintCreation", true,
options.addOption(
"CTaint",
"concreteTaintCreation",
true,
"<arg> = true, if enables ConcreteTaintCreationRule.");
options.addOption("CTA", "concreteTaintAtAssignStmt", true,
options.addOption(
"CTA",
"concreteTaintAtAssignStmt",
true,
"<arg> = true, if creates concrete taint at assign statement");
options.addOption("CTR", "concreteTaintAtReturnStmt", true,
options.addOption(
"CTR",
"concreteTaintAtReturnStmt",
true,
"<arg> = true, if creates concrete taint at return statement");
options.addOption("CTC", "concreteTaintAtCalleeOn", true,
options.addOption(
"CTC",
"concreteTaintAtCalleeOn",
true,
"<arg> = true, if creates concrete taint for parameters passing to method");
options.addOption("ITP", "impreciseTaintPropagation", true,
options.addOption(
"ITP",
"impreciseTaintPropagation",
true,
"<arg> = true, if enables ImprecisePropagationRule.");
options.addOption("STP", "staticFieldPropagation", true,
options.addOption(
"STP",
"staticFieldPropagation",
true,
"<arg> = true, if enables StaticFieldPropagationRule.");
options.addOption("all", false,
options.addOption(
"all",
false,
"Enables all propagation rules. When this is enabled, options to turn on single rule will be ignored. This is the most precise configuration of the analysis.");

// options for output files
options.addOption("output_html", true,
options.addOption(
"output_html",
true,
"Print results in HTML files, this option should be followed by the java source code path of your application.");
options.addOption("output_jimple", false, "Print results in Jimple files.");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
HelpFormatter helper = new HelpFormatter();
String cmdLineSyntax
= "\nAnalyze Android APK: -android -config <config files path> -p <android platform jar> -apk <apk file>\n"
String cmdLineSyntax =
"\nAnalyze Android APK: -android -config <config files path> -p <android platform jar> -apk <apk file>\n"
+ "\nAnalyze Java Application: -java -config <config files path> -app <app name> -cp <class path>"
+ "\n_________________________________________________________________________\n";
+ "\n_________________________________________________________________________\n";
if (cmd.hasOption('h')) {
helper.printHelp(cmdLineSyntax, options);
return;
Expand All @@ -96,7 +123,7 @@ public static void main(String[] args) throws ParseException, IOException {
helper.printHelp(cmdLineSyntax, options);
return;
} else {
AndroidApkAnalyzer.main(args);
AndroidApkAnalyzer.main(args);
}
}
if (cmd.hasOption("java")) {
Expand All @@ -109,5 +136,4 @@ public static void main(String[] args) throws ParseException, IOException {
}
}
}

}
128 changes: 59 additions & 69 deletions cova/src/main/java/cova/core/Aliasing.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
/**
* Copyright (C) 2019 Linghui Luo
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Copyright (C) 2019 Linghui Luo
*
* <p>This library is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version
* 2.1 of the License, or (at your option) any later version.
*
* <p>This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*/
package cova.core;

import boomerang.BackwardQuery;
import boomerang.Boomerang;
import boomerang.BoomerangTimeoutException;
import boomerang.DefaultBoomerangOptions;
import boomerang.jimple.Field;
import boomerang.jimple.Statement;
import boomerang.jimple.Val;
import boomerang.util.AccessPath;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import soot.Local;
import soot.PrimType;
import soot.SootMethod;
Expand All @@ -34,15 +37,6 @@
import soot.jimple.Stmt;
import soot.jimple.toolkits.ide.icfg.BiDiInterproceduralCFG;

import boomerang.BackwardQuery;
import boomerang.Boomerang;
import boomerang.BoomerangTimeoutException;
import boomerang.DefaultBoomerangOptions;
import boomerang.jimple.Field;
import boomerang.jimple.Statement;
import boomerang.jimple.Val;
import boomerang.util.AccessPath;

public class Aliasing {
private final boolean turnoff = false;
private static int notAnswered = 0;
Expand All @@ -55,45 +49,46 @@ public Aliasing(BiDiInterproceduralCFG<Unit, SootMethod> icfg) {
notAnswered = 0;
total = 0;
// Create a Boomerang solver.
solver = new Boomerang(new DefaultBoomerangOptions() {
@Override
public boolean onTheFlyCallGraph() {
// Must be turned of if no SeedFactory is specified.
return false;
};

@Override
public int analysisTimeoutMS() {
return 300;
}

}) {
@Override
public BiDiInterproceduralCFG<Unit, SootMethod> icfg() {
return icfg;
}

};

queryCache = CacheBuilder.newBuilder().build(new CacheLoader<BackwardQuery, Set<AccessPath>>() {
@Override
public Set<AccessPath> load(BackwardQuery query) throws Exception {
Set<AccessPath> aliases = queryCache.getIfPresent(query);
if (aliases == null) {
aliases = runBoomerang(query);
queryCache.put(query, aliases);
}
return aliases;
}

});
solver =
new Boomerang(
new DefaultBoomerangOptions() {
@Override
public boolean onTheFlyCallGraph() {
// Must be turned of if no SeedFactory is specified.
return false;
};

@Override
public int analysisTimeoutMS() {
return 300;
}
}) {
@Override
public BiDiInterproceduralCFG<Unit, SootMethod> icfg() {
return icfg;
}
};

queryCache =
CacheBuilder.newBuilder()
.build(
new CacheLoader<BackwardQuery, Set<AccessPath>>() {
@Override
public Set<AccessPath> load(BackwardQuery query) throws Exception {
Set<AccessPath> aliases = queryCache.getIfPresent(query);
if (aliases == null) {
aliases = runBoomerang(query);
queryCache.put(query, aliases);
}
return aliases;
}
});
}

/**
* If the queried value is a local primitive type, it can not be queried by boomerang.
*
* @param value
* the value
* @param value the value
* @return true, if successful
*/
public static boolean canBeQueried(Value value) {
Expand All @@ -114,15 +109,11 @@ private BackwardQuery createQuery(Stmt stmt, SootMethod method, Value value) {
/**
* This method starts a boomerang query at the given statement for searching aliases of the given
* value. It returns all aliases of the value, including the value itself.
*
* @param value
* queried value
* @param stmt
* the statement where the query starts
* @param method
* the method contains the statement
*
* @param value queried value
* @param stmt the statement where the query starts
* @param method the method contains the statement
* @return all aliases of the given value
*
*/
public Set<AccessPath> findAliasAtStmt(Value value, Stmt stmt, SootMethod method) {
Set<AccessPath> aliases = new HashSet<AccessPath>(1);
Expand Down Expand Up @@ -159,8 +150,7 @@ public Set<AccessPath> findAliasAtStmt(Value value, Stmt stmt, SootMethod method
/**
* Run boomerang with the given query.
*
* @param query
* the query
* @param query the query
* @return the set of aliases found by boomerang
*/
private Set<AccessPath> runBoomerang(BackwardQuery query) {
Expand Down
Loading

0 comments on commit 24f197f

Please sign in to comment.