Skip to content

Commit

Permalink
Add: conditionLimit command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
1bitbool committed Aug 11, 2023
1 parent 67dcffe commit 62b3e17
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 23 deletions.
58 changes: 40 additions & 18 deletions CrashTracker/src/main/java/com/iscas/crashtracker/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.iscas.crashtracker.client.cg.cgApk.CallGraphofApkClient;
import com.iscas.crashtracker.client.crash.ApkCrashAnalysisClient;
import com.iscas.crashtracker.client.crash.JarCrashAnalysisClient;
import com.iscas.crashtracker.client.exception.ConditionTracker;
import com.iscas.crashtracker.client.exception.ExceptionInfoClient;
import com.iscas.crashtracker.client.manifest.ManifestClient;
import com.iscas.crashtracker.client.soot.IROutputClient;
Expand Down Expand Up @@ -117,23 +118,23 @@ private static BaseClient getClient() {
private static Options getOptions() {
Options options = new Options();

options.addOption("h", false, "-h: Show the help information.");
options.addOption("h", false, "Show the help information.");

/** input **/
options.addOption("name", true, "-name: Set the name of the apk under analysis.");
options.addOption("path", true, "-path: Set the path to the apk under analysis.");
options.addOption("androidJar", true, "-androidJar: Set the path of android.jar.");
options.addOption("crashPath", true, "-crashPath: crash information file.");
options.addOption("frameworkVersion", true, "-frameworkVersion: The version of framework under analysis");
options.addOption("strategy", true, "-strategy: effectiveness of strategy m");
options.addOption("name", true, "Set the name of the apk under analysis.");
options.addOption("path", true, "Set the path to the apk under analysis.");
options.addOption("androidJar", true, "Set the path of android.jar.");
options.addOption("crashPath", true, "crash information file.");
options.addOption("frameworkVersion", true, "The version of framework under analysis");
options.addOption("strategy", true, "effectiveness of strategy m");

options.addOption("exceptionPath", true, "-exceptionPath: exception file folder [optional].");
options.addOption("androidCGPath", true, "-androidCGPath: Android CallGraph file [optional.");
options.addOption("permissionPath", true, "-permissionPath: Android permissionPath file [optional.");
options.addOption("exceptionPath", true, "exception file folder [optional].");
options.addOption("androidCGPath", true, "Android CallGraph file [optional.");
options.addOption("permissionPath", true, "Android permissionPath file [optional.");


/** analysis config **/
options.addOption("client", true, "-client "
options.addOption("client", true, "client used.\n"
+ "ExceptionInfoClient: Extract exception information from Android framework.\n"
+ "CrashAnalysisClient: Analysis the crash information for an apk.\n"
+ "JarCrashAnalysisClient: Analysis the crash information for an third party SDK.\n"
Expand All @@ -142,14 +143,17 @@ private static Options getOptions() {
+ "IROutputClient: Output soot IR files.\n"
);
/** analysis config **/
options.addOption("time", true, "-time [default:90]: Set the max running time (min).");
options.addOption("callgraphAlgorithm", true, "-callgraphAlgorithm [default:SPARK]: Set algorithm for CG, CHA or SPARK.");
options.addOption("time", true, "[default:90]: Set the max running time (min).");
options.addOption("callgraphAlgorithm", true, "[default:SPARK]: Set algorithm for CG, CHA or SPARK.");
/** output **/
options.addOption("outputDir", true, "-outputDir: Set the output folder of the apk.");
options.addOption("sootOutput", false, "-sootOutput: Output the sootOutput");
options.addOption("crashInput", true, "-crashInput: crashInfo.json file path");
options.addOption("exceptionInput", true, "-exceptionInput: exception file folder");
// options.addOption("callgraphAlgorithm", false, "-callgraphAlgorithm: callgraphAlgorithm");
options.addOption("outputDir", true, "Set the output folder of the apk.");
options.addOption("sootOutput", false, "Output the sootOutput");
options.addOption("crashInput", true, "crashInfo.json file path");
options.addOption("exceptionInput", true, "exception file folder");
options.addOption("conditionLimit", true, "the number of conditions to be retained.\n" +
"all: keep all\n" +
"one: keep one condition\n" +
"three: keep three condition");

return options;
}
Expand Down Expand Up @@ -200,6 +204,24 @@ private static void analyzeArgs(CommandLine mCmd) {
}
}

String limit = mCmd.getOptionValue("conditionLimit");
if (limit != null) {
switch(limit) {
case("all"):
MyConfig.getInstance().setConditionLimit(ConditionTracker.All);
break;
case("one"):
MyConfig.getInstance().setConditionLimit(ConditionTracker.One);
break;
case("three"):
MyConfig.getInstance().setConditionLimit(ConditionTracker.Three);
break;
default:
log.error("Invalid condition limit!");
System.exit(0);
}
}

MyConfig.getInstance().setStrategy(mCmd.getOptionValue("strategy", ""));
log.info("###The strategy is #" + MyConfig.getInstance().getStrategy()+"#");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.iscas.crashtracker.base;

import com.iscas.crashtracker.client.exception.ConditionTracker;
import com.iscas.crashtracker.utils.FileUtils;
import soot.options.Options;

Expand Down Expand Up @@ -34,6 +35,7 @@ public class MyConfig {
private String PermissionFilePath;
private String AndroidCGFilePath ;
private String AndroidOSVersion = null;
private ConditionTracker conditionLimit = ConditionTracker.All;

private String Strategy="";
private boolean outputIR = false;
Expand Down Expand Up @@ -281,4 +283,12 @@ public void setOutputIR(boolean outputIR) {
public boolean getOutputIR() {
return outputIR;
}

public void setConditionLimit(ConditionTracker limit) {
conditionLimit = limit;
}

public ConditionTracker getConditionLimit() {
return conditionLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private boolean conditionCheck(ExceptionInfo exceptionInfo, SootMethod sootMetho
*/
private void getExceptionCondition(SootMethod sootMethod, Unit unit, ExceptionInfo exceptionInfo,
Set<Unit> getCondHistory, boolean fromThrow, Unit lastGoto) {
ConditionTracker conditionTracker = ConditionTracker.All;
ConditionTracker conditionTracker = MyConfig.getInstance().getConditionLimit();
if(getCondHistory.contains(unit) || getCondHistory.size()> ConstantUtils.CONDITIONHISTORYSIZE) return;// if defUnit is not a pred of unit
getCondHistory.add(unit);
Body body = sootMethod.getActiveBody();
Expand All @@ -540,6 +540,16 @@ private void getExceptionCondition(SootMethod sootMethod, Unit unit, ExceptionIn
boolean ifMeetTryCatch = false;
for (Unit predUnit : predsOf) {
if (predUnit instanceof IfStmt) {
//direct condition or multiple condition
if(conditionTracker == ConditionTracker.One){
if(exceptionInfo.getConditionUnits().size()>0) continue;
} else if(conditionTracker == ConditionTracker.Three){
if(exceptionInfo.getConditionUnits().size()>=3) continue;
}else if(conditionTracker == ConditionTracker.SmallBlock) {
// && ((IfStmt) predUnit).getTarget() != lastGoto
if (exceptionInfo.getConditionUnits().size() > 0 && lastGoto != null)
continue;
}
exceptionInfo.getTracedUnits().add(predUnit);
IfStmt ifStmt = (IfStmt) predUnit;
lastGoto = ifStmt.getTarget();
Expand Down Expand Up @@ -579,6 +589,14 @@ private void getExceptionCondition(SootMethod sootMethod, Unit unit, ExceptionIn
}
}
if(ifMeetTryCatch) continue;
if(conditionTracker == ConditionTracker.One){
if(fromThrow && exceptionInfo.getConditions().size()>0 ) continue;
} else if(conditionTracker == ConditionTracker.Three){
if(fromThrow && exceptionInfo.getConditionUnits().size()>=3) continue;
}else if(conditionTracker == ConditionTracker.SmallBlock) {
if(fromThrow && exceptionInfo.getConditions().size()>0 && gotoTargets.contains(predUnit))
continue;
}
getExceptionCondition(sootMethod, predUnit, exceptionInfo,getCondHistory, fromThrow, lastGoto);
}
}
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Extracting exception-thrown summary (ETS) for that framework is required before

```
# Use the following commands to analyze your framework files.
python scripts/runCrashTracker-framework.py [framework code path] [framework code folder name] [version] [outputDir]
python scripts/runCrashTracker-framework.py [framework code path] [framework code folder name] [version] [conditionLimit] [outputDir]
For example, if the sturcture of your files is as follows:
+-- CrashTrackerTool
Expand All @@ -137,7 +137,7 @@ For example, if the sturcture of your files is as follows:
version. Also, you can download from https://github.com/hanada31/AndroidFrameworkImpl and unzip files)
run:
python scripts/runCrashTracker-framework.py M_framework android2.3 2.3 ETSResults
python scripts/runCrashTracker-framework.py M_framework android2.3 2.3 all ETSResults
```

## CrashTracker.jar -h Arguments
Expand All @@ -154,6 +154,10 @@ usage: java -jar CrashTracker.jar [options] [-path] [-name] [-androidJar] [-outp
CallGraphClient: Output call graph files.
ManifestClient: Output manifest.xml file.
IROutputClient: Output soot IR files.
-conditionLimit <arg> -conditionLimit: the number of conditions to be retained.
all: keep all
one: keep one condition
three: keep three condition
-name <arg> -name: Set the name of the apk under analysis.
-path <arg> -path: Set the path to the apk under analysis.
-crashPath <arg> -crashInput: crash information file.
Expand Down
6 changes: 4 additions & 2 deletions scripts/runCrashTracker-framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def execute_cmd(cmd):
path = sys.argv[1]
name = sys.argv[2]
version = sys.argv[3]
output = sys.argv[4]
limit = sys.argv[4]
output = sys.argv[5]

command = "java -jar " + jarFile + " -path " + path + " -name " + name + " -androidJar " + sdk + \
" -client ExceptionInfoClient" + " -outputDir " + output + " -frameworkVersion " + version
" -client ExceptionInfoClient" + " -outputDir " + output + " -frameworkVersion " + version + \
" -conditionLimit " + limit
print("Start command")
execute_cmd(command)
print("Execute over!")

0 comments on commit 62b3e17

Please sign in to comment.