Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
1bitbool committed Jul 24, 2023
2 parents 5d71db3 + 7a338f4 commit a1a9faa
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 180 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ replay_pid*
.idea/
*.iml

# MacOS
.DS_Store

# custom
.settings/
/CrashTracker/target/
Expand All @@ -48,3 +51,5 @@ ETSResults/
/result/
/results/
dependency-reduced-pom.xml
src/main/generated
CrashTracker.jar
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "soot-dev"]
path = soot-dev
url = https://github.com/LightningRS/soot-dev-iccbot.git
ignore = dirty
Binary file removed CrashTracker.jar
Binary file not shown.
24 changes: 15 additions & 9 deletions CrashTracker/src/main/java/com/iscas/crashtracker/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public static void startAnalyze() {
log.info("Analyzing " + MyConfig.getInstance().getAppName() + " Finish...\n");
log.info(MyConfig.getInstance().getClient() + " time = " + (endTime - startTime) / 1000 + " seconds");
log.info("Success! Please see files in the result folder "+ MyConfig.getInstance().getResultFolder());

if (MyConfig.getInstance().getOutputIR()) {
new IROutputClient().start();
}
}

/**
Expand Down Expand Up @@ -177,20 +181,22 @@ private static void analyzeArgs(CommandLine mCmd) {
MyConfig.getInstance().setExceptionFolderPath(mCmd.getOptionValue("exceptionInput","Files"));

MyConfig.getInstance().setResultFolder(mCmd.getOptionValue("outputDir", "outputDir") + File.separator);
if (mCmd.hasOption("sootOutput")) {
MyConfig.getInstance().setOutputIR(true);
}

if(mCmd.getOptionValue("frameworkVersion")!=null) {
MyConfig.getInstance().setAndroidOSVersion(mCmd.getOptionValue("frameworkVersion"));
String androidFolder = "";
String appName = MyConfig.getInstance().getAppName();
String exceptionFolder = MyConfig.getInstance().getResultFolder() + File.separator + appName + File.separator;
if(mCmd.getOptionValue("client").equals("ExceptionInfoClient")){
androidFolder = MyConfig.getInstance().getResultFolder() + File.separator + "android" + mCmd.getOptionValue("frameworkVersion") + File.separator;
MyConfig.getInstance().setPermissionFilePath(androidFolder + "Permission" + File.separator + "permission.txt");
MyConfig.getInstance().setExceptionFilePath(androidFolder + "exceptionInfo" + File.separator);
MyConfig.getInstance().setAndroidCGFilePath(androidFolder + "CallGraphInfo" + File.separator + "cg.txt");
MyConfig.getInstance().setPermissionFilePath(exceptionFolder + "Permission" + File.separator + "permission.txt");
MyConfig.getInstance().setExceptionFilePath(exceptionFolder + "exceptionInfo" + File.separator);
MyConfig.getInstance().setAndroidCGFilePath(exceptionFolder + "CallGraphInfo" + File.separator + "cg.txt");
}else {
androidFolder = MyConfig.getInstance().getExceptionFolderPath() + File.separator + "android" + mCmd.getOptionValue("frameworkVersion") + File.separator;
MyConfig.getInstance().setPermissionFilePath(mCmd.getOptionValue("permissionPath", androidFolder + "Permission" + File.separator + "permission.txt"));
MyConfig.getInstance().setExceptionFilePath(mCmd.getOptionValue("exceptionPath", androidFolder + "exceptionInfo" + File.separator));
MyConfig.getInstance().setAndroidCGFilePath(mCmd.getOptionValue("androidCGPath", androidFolder + "CallGraphInfo" + File.separator + "cg.txt"));
MyConfig.getInstance().setPermissionFilePath(mCmd.getOptionValue("permissionPath", exceptionFolder + "Permission" + File.separator + "permission.txt"));
MyConfig.getInstance().setExceptionFilePath(mCmd.getOptionValue("exceptionPath", exceptionFolder + "exceptionInfo" + File.separator));
MyConfig.getInstance().setAndroidCGFilePath(mCmd.getOptionValue("androidCGPath", exceptionFolder + "CallGraphInfo" + File.separator + "cg.txt"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class MyConfig {
private String AndroidOSVersion = null;

private String Strategy="";
private boolean outputIR = false;

private MyConfig() {
}
Expand Down Expand Up @@ -283,5 +284,11 @@ public void setPermissionFilePath(String permissionFilePath) {
PermissionFilePath = permissionFilePath;
}

public void setOutputIR(boolean outputIR) {
this.outputIR = outputIR;
}

public boolean getOutputIR() {
return outputIR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@
public abstract class BaseClient {

public void start() {

try {
clientAnalyze();
clientOutput();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
} catch (IOException | DocumentException e) {
e.printStackTrace();
}
// catch (RuntimeException e) {
// e.printStackTrace();
// System.err.println("The analysis is stopped, caused by "+ e.getMessage());
// System.exit(0);
// }
}

protected abstract void clientAnalyze();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,14 @@ private void addInvocationEdges(SootMethod sm, CallGraph callGraph) {
while (it.hasNext()) {
Unit u = it.next();
InvokeExpr exp = SootUtils.getInvokeExp(u);
if (exp == null)
continue;
InvokeExpr invoke = SootUtils.getSingleInvokedMethod(u);
if (invoke != null) { // u is invoke stmt
Set<SootMethod> targetSet = SootUtils.getInvokedMethodSet(sm, u);
for (SootMethod target : targetSet) {
try {
Edge e = new Edge(sm, (Stmt) u, target);
callGraph.addEdge(e);
}catch (Exception e){
if (exp == null) continue;
Set<SootMethod> targetSet = SootUtils.getInvokedMethodSet(sm, u);
for (SootMethod target : targetSet) {
try {
Edge e = new Edge(sm, (Stmt) u, target);
callGraph.addEdge(e);
}catch (Exception e){

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ public class CallGraphBuilder {
private static final CallGraph cg = Scene.v().getCallGraph();

static {
// filterEdges(cg);
log.info("filtered CG Edge Size ***** " + cg.size());
addEdgesByOurAnalyze(cg);
addEdgesByOurAnalyze();
log.info("enhanced CG Edge Size ***** " + cg.size());
}

private static void filterEdges(CallGraph cg) {
Set<Edge> res = new HashSet<>();
Iterator<Edge> it = cg.iterator();
while(it.hasNext()){
Edge e = it.next();
if(!e.getSrc().method().getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX) ||
!e.getTgt().method().getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX)){
for (Edge e : cg) {
if (!e.getSrc().method().getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX) ||
!e.getTgt().method().getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX)) {
res.add(e);
}
}
Expand All @@ -47,26 +44,25 @@ public static CallGraph getCallGraph() {
return cg;
}

private static void addEdgesByOurAnalyze(CallGraph callGraph) {
/**
* Add edge for all invoke statement to callGraph
*/
private static void addEdgesByOurAnalyze() {
for (SootClass sc : Scene.v().getApplicationClasses()) {
if(!sc.getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX)) continue;
ArrayList<SootMethod> methodList = new ArrayList<SootMethod>(sc.getMethods());
ArrayList<SootMethod> methodList = new ArrayList<>(sc.getMethods());
for (SootMethod sm : methodList) {
if (SootUtils.hasSootActiveBody(sm) == false)
if (!SootUtils.hasSootActiveBody(sm))
continue;
Iterator<Unit> it = SootUtils.getSootActiveBody(sm).getUnits().iterator();
while (it.hasNext()) {
Unit u = it.next();
for (Unit u : SootUtils.getSootActiveBody(sm).getUnits()) {
InvokeExpr exp = SootUtils.getInvokeExp(u);
if (exp == null) continue;
InvokeExpr invoke = SootUtils.getSingleInvokedMethod(u);
if (invoke != null) { // u is invoke stmt
Set<SootMethod> targetSet = SootUtils.getInvokedMethodSet(sm, u);
for (SootMethod target : targetSet) {
if(!target.getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX)) continue;
Edge e = new Edge(sm, (Stmt) u, target);
callGraph.addEdge(e);
}
if (exp == null) continue;
Set<SootMethod> targetSet = SootUtils.getInvokedMethodSet(sm, u);
for (SootMethod target : targetSet) {
if (!target.getDeclaringClass().getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX))
continue;
Edge e = new Edge(sm, (Stmt) u, target);
cg.addEdge(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @version 2.0
*/
@Slf4j
public class CallGraphofJavaClient extends BaseClient {
public class CallGraphJavaClient extends BaseClient {

@Override
protected void clientAnalyze() {
Expand All @@ -32,13 +32,11 @@ protected void clientAnalyze() {

@Override
public void clientOutput() {
/** call graph, if needed, open output**/
String summary_app_dir = MyConfig.getInstance().getResultFolder() + Global.v().getAppModel().getAppName()
+ File.separator;
FileUtils.createFolder(summary_app_dir + ConstantUtils.CGFOLDETR);
CgClientOutput.writeCG(summary_app_dir + ConstantUtils.CGFOLDETR,
Global.v().getAppModel().getAppName()+"_cg.txt", Global.v().getAppModel().getCg());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ private void addCallersOfCrashMethod(SootMethod sm, CrashInfo crashInfo, int dep
private void addPredCallersOfMethodsInStack(String last, SootMethod sm, CrashInfo crashInfo, JSONObject reason) {
if(!sm.hasActiveBody())return;
for(Unit u : sm.getActiveBody().getUnits()){
InvokeExpr invoke = SootUtils.getSingleInvokedMethod(u);
if (invoke != null) { // u is invoke stmt
String callee = invoke.getMethod().getDeclaringClass().getName()+ "." + invoke.getMethod().getName();
if(callee.equals(last)){
JSONObject newReason = reason.clone();
newReason.getJSONArray("Trace").add(callee);
addPredsOfUnit2ExtendedCG(u, sm, crashInfo,2, newReason,null);
}
InvokeExpr invoke = SootUtils.getInvokeExp(u);
if (invoke == null) continue;
String callee = invoke.getMethod().getDeclaringClass().getName()+ "." + invoke.getMethod().getName();
if(callee.equals(last)){
JSONObject newReason = reason.clone();
newReason.getJSONArray("Trace").add(callee);
addPredsOfUnit2ExtendedCG(u, sm, crashInfo,2, newReason,null);
}
}
}
Expand Down Expand Up @@ -1051,7 +1050,6 @@ public void getExceptionOfCrashInfo() {
targetMethodName = crashInfo.getSignaler();
}
String androidFolder = MyConfig.getInstance().getExceptionFolderPath()+File.separator+"android"+targetVer+File.separator;
MyConfig.getInstance().setExceptionFilePath(androidFolder+"exceptionInfo"+File.separator);
MyConfig.getInstance().setPermissionFilePath(androidFolder+"Permission"+File.separator+"permission.txt");
MyConfig.getInstance().setAndroidCGFilePath(androidFolder+"CallGraphInfo"+File.separator+"android"+targetVer+"_cg.txt");
log.info("target is "+ targetVer);
Expand Down Expand Up @@ -1101,7 +1099,6 @@ else if(overrideMissing >= parameterOnly && overrideMissing >= paraAndField && o
*/
private Pair<String,String> getExceptionWithGivenVersion(CrashInfo crashInfo, String version, boolean classFilter) {
String androidFolder = MyConfig.getInstance().getExceptionFolderPath()+File.separator+"android"+version+File.separator;
MyConfig.getInstance().setExceptionFilePath(androidFolder+"exceptionInfo"+File.separator);
MyConfig.getInstance().setPermissionFilePath(androidFolder+"Permission"+File.separator+"permission.txt");
MyConfig.getInstance().setAndroidCGFilePath(androidFolder+"CallGraphInfo"+File.separator+"android"+version+"_cg.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.iscas.crashtracker.base.Global;
import com.iscas.crashtracker.base.MyConfig;
import com.iscas.crashtracker.client.BaseClient;
import com.iscas.crashtracker.client.cg.cgJava.CallGraphofJavaClient;
import com.iscas.crashtracker.client.cg.cgJava.CallGraphJavaClient;
import com.iscas.crashtracker.client.soot.SootAnalyzer;
import com.iscas.crashtracker.utils.ConstantUtils;
import com.iscas.crashtracker.utils.FileUtils;
Expand All @@ -29,7 +29,7 @@ protected void clientAnalyze() {
}
if (!MyConfig.getInstance().isCallGraphAnalyzeFinish()) {
ConstantUtils.CGANALYSISPREFIX = Global.v().getAppModel().getPackageName();
new CallGraphofJavaClient().start();
new CallGraphJavaClient().start();
MyConfig.getInstance().setCallGraphAnalyzeFinish(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ private RelatedVarType getVarTypeFromExceptionSummary(CrashInfo crashInfo, Strin
*/
private Pair<String,String> getExceptionWithGivenVersion(CrashInfo crashInfo, String version, boolean classFilter) {
String androidFolder = MyConfig.getInstance().getExceptionFolderPath()+File.separator+"android"+version+File.separator;
MyConfig.getInstance().setExceptionFilePath(androidFolder+"exceptionInfo"+File.separator);
MyConfig.getInstance().setPermissionFilePath(androidFolder+"Permission"+File.separator+"permission.txt");
MyConfig.getInstance().setAndroidCGFilePath(androidFolder+"CallGraphInfo"+File.separator+"cg.txt");

Expand Down Expand Up @@ -229,7 +228,6 @@ private String getExceptionWithGivenVersion(CrashInfo crashInfo, String version)
wrapperObject = version2JsonStr.get(version);
}else {
String androidFolder = MyConfig.getInstance().getExceptionFolderPath()+File.separator+"android"+version+File.separator;
MyConfig.getInstance().setExceptionFilePath(androidFolder+"exceptionInfo"+File.separator);
MyConfig.getInstance().setPermissionFilePath(androidFolder+"Permission"+File.separator+"permission.txt");
MyConfig.getInstance().setAndroidCGFilePath(androidFolder+"CallGraphInfo"+File.separator+"cg.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import java.util.ArrayList;
import java.util.List;
/**
* @Author hanada
* @Date 2022/3/11 15:21
* @Version 1.0
* @author hanada
* @since 2022/3/11 15:21
* @version 1.0
*/
@Slf4j
public class ExceptionAnalyzer extends Analyzer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.iscas.crashtracker.base.Global;
import com.iscas.crashtracker.base.MyConfig;
import com.iscas.crashtracker.client.BaseClient;
import com.iscas.crashtracker.client.cg.cgJava.CallGraphofJavaClient;
import com.iscas.crashtracker.client.cg.cgJava.CallGraphJavaClient;
import com.iscas.crashtracker.client.soot.SootAnalyzer;
import com.iscas.crashtracker.utils.ConstantUtils;
import com.iscas.crashtracker.utils.FileUtils;
Expand All @@ -17,17 +17,15 @@
import java.io.IOException;

/**
* @Author hanada
* @Date 2022/3/11 15:03
* @Version 1.0
* @author hanada
* @version 1.0
* @since 2022/3/11 15:03
*/

@Slf4j
public class ExceptionInfoClient extends BaseClient {
/**
* analyze logic for single app
*
* @return
*/
@Override
protected void clientAnalyze() {
Expand All @@ -36,10 +34,11 @@ protected void clientAnalyze() {
SootAnalyzer sootAnalyzer = new SootAnalyzer();
sootAnalyzer.analyze();
}

if (!MyConfig.getInstance().isCallGraphAnalyzeFinish()) {
log.info("CallGraphofJavaClient start...");
ConstantUtils.CGANALYSISPREFIX = ConstantUtils.FRAMEWORKPREFIX;
new CallGraphofJavaClient().start();
new CallGraphJavaClient().start();
MyConfig.getInstance().setCallGraphAnalyzeFinish(true);
}

Expand Down
Loading

0 comments on commit a1a9faa

Please sign in to comment.