Skip to content

Commit

Permalink
analyze the try-catch blocks to track relatedValues
Browse files Browse the repository at this point in the history
  • Loading branch information
hanada committed Aug 10, 2023
1 parent 753fe2b commit 7d901aa
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import com.iscas.crashtracker.base.Global;
import com.iscas.crashtracker.client.exception.ExceptionInfo;
import com.iscas.crashtracker.client.exception.RelatedCondType;
Expand Down Expand Up @@ -303,7 +302,7 @@ public void setExceptionInfo(ExceptionInfo exceptionInfo) {

this.exceptionInfo.getRelatedParamValues().addAll(exceptionInfo.getRelatedParamValues());
this.exceptionInfo.getRelatedFieldValues().addAll(exceptionInfo.getRelatedFieldValues());
this.exceptionInfo.getCaughtedValues().addAll(exceptionInfo.getCaughtedValues());
this.exceptionInfo.getCaughtValues().addAll(exceptionInfo.getCaughtValues());
this.exceptionInfo.getRelatedValueIndex().addAll(exceptionInfo.getRelatedValueIndex());
this.exceptionInfo.getRelatedFieldValuesInStr().addAll(exceptionInfo.getRelatedFieldValuesInStr());
this.exceptionInfo.getRelatedParamValuesInStr().addAll(exceptionInfo.getRelatedParamValuesInStr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ private void getExceptionList() {
for (SootClass sootClass : applicationClasses) {
if(!sootClass.getPackageName().startsWith(ConstantUtils.CGANALYSISPREFIX)) continue;
exceptionInfoList = new ArrayList<>();
for (SootMethod sootMethod : sootClass.getMethods()) {
HashSet<SootMethod> methodsInTheClass = new HashSet<>(sootClass.getMethods());
for (SootMethod sootMethod : methodsInTheClass) {
if (!sootMethod.hasActiveBody()) continue;
try {
Map<SootMethod, Map<Unit,Local>> method2unit2Value = getThrowUnitWithValue(sootMethod);
Expand Down Expand Up @@ -559,8 +560,14 @@ private void getExceptionCondition(SootMethod sootMethod, Unit unit, ExceptionIn
}else if (predUnit instanceof JIdentityStmt ) {
JIdentityStmt stmt = (JIdentityStmt) predUnit;
if(stmt.getRightOp() instanceof CaughtExceptionRef){
exceptionInfo.addCaughtedValues(stmt.getRightOp());
//analyzed try-catch contents
exceptionInfo.addCaughtValues(stmt.getRightOp());
//analyze the try-catch block of this exception
List<Unit> caughtUnits = getTryCatchUnits(sootMethod, predUnit);
for(Unit caughtUnit: caughtUnits) {
for (ValueBox vb : caughtUnit.getUseBoxes()) {
extendRelatedValues(sootMethod,SootUtils.getUnitListFromMethod(sootMethod), exceptionInfo, caughtUnit, vb.getValue(), new ArrayList<>(), getCondHistory, fromThrow);
}
}
}
}
getExceptionCondition(sootMethod, predUnit, exceptionInfo,getCondHistory, fromThrow, lastGoto);
Expand Down Expand Up @@ -597,7 +604,14 @@ private String extendRelatedValues(SootMethod sootMethod, List<Unit> allPreds, E
exceptionInfo.addCallerOfSingnlar2SourceVar(sootMethod.getSignature(), id);
return "ParameterRef";
}else if(identityStmt.getRightOp() instanceof CaughtExceptionRef){
exceptionInfo.addCaughtedValues(identityStmt.getRightOp());
exceptionInfo.addCaughtValues(identityStmt.getRightOp());
//analyze the try-catch block of this exception
List<Unit> caughtUnits = getTryCatchUnits(sootMethod, defUnit);
for(Unit caughtUnit: caughtUnits) {
for (ValueBox vb : caughtUnit.getUseBoxes()) {
extendRelatedValues(sootMethod, SootUtils.getUnitListFromMethod(sootMethod), exceptionInfo, caughtUnit, vb.getValue(), valueHistory, getCondHistory, fromThrow);
}
}
return "CaughtExceptionRef";
}else if(identityStmt.getRightOp() instanceof ThisRef){
return "ThisRef";
Expand All @@ -619,7 +633,6 @@ private String extendRelatedValues(SootMethod sootMethod, List<Unit> allPreds, E
extendRelatedValues(sootMethod, allPreds, exceptionInfo, defUnit, rv, valueHistory, getCondHistory, fromThrow);
}
exceptionInfo.addRelatedFieldValues(field);

}
} else if (rightOp instanceof Expr) {
if (rightOp instanceof InvokeExpr) {
Expand Down Expand Up @@ -663,6 +676,29 @@ private String extendRelatedValues(SootMethod sootMethod, List<Unit> allPreds, E
return "";
}

private List getTryCatchUnits(SootMethod sootMethod, Unit defUnit) {
List<Unit> tryCatchUnits = new ArrayList<>();
for (Trap trap : sootMethod.getActiveBody().getTraps()) {
if(trap.getHandlerUnit() == defUnit){
Unit begin = trap.getBeginUnit();
Unit end = trap.getEndUnit();
boolean startRec = false;
for(Unit temp: SootUtils.getUnitListFromMethod(sootMethod)){
if(temp == begin){
startRec = true;
}
if(temp == end){
startRec = false;
}
if(startRec) {
tryCatchUnits.add(temp);
}
}
}
}
return tryCatchUnits;
}

private void traceCallerOfParamValue(SootMethod sootMethod,ExceptionInfo exceptionInfo, int id, int depth) {
if(depth>ConstantUtils.SIGNLARCALLERDEPTH) return;
//get the caller of sootMethod, and trace the usage of param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ public void addRelatedParamValue(Value v) {
relatedParamValues.add(v);
}

public List<Value> getCaughtedValues() {
public List<Value> getCaughtValues() {
return caughtedValues;
}
public void addCaughtedValues(Value v) {
public void addCaughtValues(Value v) {
if(!caughtedValues.contains(v))
caughtedValues.add(v);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.iscas.crashtracker.client.exception;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
Expand Down Expand Up @@ -144,11 +143,11 @@ public static void addRelatedValues(JSONObject jsonObject, ExceptionInfo info) {
jsonObject.put("paramValues", PrintUtils.printList(info.getRelatedParamValues()));
if(info.getRelatedFieldValues().size()>0)
jsonObject.put("fieldValues", PrintUtils.printList(info.getRelatedFieldValues()));
if(info.getCaughtedValues().size()>0)
jsonObject.put("caughtValues", PrintUtils.printList(info.getCaughtedValues()));
if(info.getRelatedParamValues().size() + info.getRelatedFieldValues().size() + info.getCaughtedValues().size()>0)
if(info.getCaughtValues().size()>0)
jsonObject.put("caughtValues", PrintUtils.printList(info.getCaughtValues()));
if(info.getRelatedParamValues().size() + info.getRelatedFieldValues().size() + info.getCaughtValues().size()>0)
jsonObject.put("relatedValues", PrintUtils.printList(info.getRelatedParamValues())+"; "
+PrintUtils.printList(info.getRelatedFieldValues()) +"; "+ PrintUtils.printList(info.getCaughtedValues()));
+PrintUtils.printList(info.getRelatedFieldValues()) +"; "); // + PrintUtils.printList(info.getCaughtValues())
}

private static void addBackwardParamCallerNum(JSONObject jsonObject, ExceptionInfo exceptionInfo) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/mvn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
shutil.copy("target/CrashTracker-jar-with-dependencies.jar", "CrashTracker.jar")
print("copy jar to the root directory.")
else:
print("Fail to build! Please run \"mvn -f pom.xml package\" to see the detail info.")
print("Fail to build! Please run \"mvn -f pom.xml clean package -DskipTests\" to see the detail info.")
41 changes: 20 additions & 21 deletions scripts/summaryConstruction.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
echo python scripts/runCrashTracker-framework.py M_framework android2.3 2.3 ETSResults
python scripts/runCrashTracker-framework.py M_framework android2.3 2.3 ETSResults

echo python scripts/runCrashTracker-framework.py 2.3
python scripts/runCrashTracker-framework.py 2.3
echo python scripts/runCrashTracker-framework.py M_framework android4.4 4.4 ETSResults
python scripts/runCrashTracker-framework.py M_framework android4.4 4.4 ETSResults

echo python scripts/runCrashTracker-framework.py 4.4
python scripts/runCrashTracker-framework.py 4.4
echo python scripts/runCrashTracker-framework.py M_framework android5.0 5.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android5.0 5.0 ETSResults

echo python scripts/runCrashTracker-framework.py 5.0
python scripts/runCrashTracker-framework.py 5.0
echo python scripts/runCrashTracker-framework.py M_framework android6.0 6.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android6.0 6.0 ETSResults

echo python scripts/runCrashTracker-framework.py 6.0
python scripts/runCrashTracker-framework.py 6.0
echo python scripts/runCrashTracker-framework.py M_framework android7.0 7.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android8.0 7.0 ETSResults

echo python scripts/runCrashTracker-framework.py 7.0
python scripts/runCrashTracker-framework.py 7.0
echo python scripts/runCrashTracker-framework.py M_framework android8.0 8.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android8.0 8.0 ETSResults

echo python scripts/runCrashTracker-framework.py 8.0
python scripts/runCrashTracker-framework.py 8.0
echo python scripts/runCrashTracker-framework.py M_framework android9.0 9.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android9.0 9.0 ETSResults

echo python scripts/runCrashTracker-framework.py 9.0
python scripts/runCrashTracker-framework.py 9.0
echo python scripts/runCrashTracker-framework.py M_framework android10.0 10.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android10.0 10.0 ETSResults

echo python scripts/runCrashTracker-framework.py 10.0
python scripts/runCrashTracker-framework.py 10.0
echo python scripts/runCrashTracker-framework.py M_framework android11.0 11.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android11.0 11.0 ETSResults

echo python scripts/runCrashTracker-framework.py 11.0
python scripts/runCrashTracker-framework.py 11.0

echo python scripts/runCrashTracker-framework.py 12.0
python scripts/runCrashTracker-framework.py 12.0
echo python scripts/runCrashTracker-framework.py M_framework android12.0 12.0 ETSResults
python scripts/runCrashTracker-framework.py M_framework android12.0 12.0 ETSResults

tar -czvf Files/newAllCond-android.tar.gz Files/android*

Expand Down

0 comments on commit 7d901aa

Please sign in to comment.