Skip to content

Commit

Permalink
add precondition for exception-thrown methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hanada committed Jul 14, 2023
1 parent 7ea19a4 commit 5d71db3
Show file tree
Hide file tree
Showing 49 changed files with 4,809 additions and 1,467 deletions.
Binary file modified CrashTracker.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class MyConfig {

private boolean isJimple = true;
private boolean isJimple = false;
private String resultFolder;
private String resultWarpperFolder;
private String appName;
Expand All @@ -21,6 +21,7 @@ public class MyConfig {
private int timeLimit;
private String androidJar;
private boolean stopFlag = false;
private String tag ;

private boolean isSootAnalyzeFinish;
private boolean isManifestClientFinish;
Expand Down Expand Up @@ -65,7 +66,16 @@ public String getStrategy() {
public void setStrategy(String strategy) {
Strategy = strategy;
}
public boolean isJimple() {

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public boolean isJimple() {
return isJimple;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.iscas.crashtracker.client.cg.cgApk;
package com.iscas.crashtracker.client.cg;

import com.iscas.crashtracker.base.Analyzer;
import com.iscas.crashtracker.utils.SootUtils;
Expand All @@ -19,69 +19,51 @@ public CgModify() {

@Override
public void analyze() {
boolean lightMode = false;
if(lightMode){
addTopoForSupplySingle();
}else{
addEdgesByOurAnalyze(appModel.getCg());
// removeExlibEdge(appModel.getCg());
// removeNotActiveEdge(appModel.getCg());
removeSameEdge(appModel.getCg());
removeSelfEdge(appModel.getCg());
addEdgesByOurAnalyze(appModel.getCg());
// removeExlibEdge(appModel.getCg());
// removeNotActiveEdge(appModel.getCg());
removeSameEdge(appModel.getCg());
removeSelfEdge(appModel.getCg());

/** multiple topo queue **/
// List<CallGraph> cgs = new ArrayList<CallGraph>();
// List<Set<SootMethod>> methodSets = new ArrayList<Set<SootMethod>>();
// seperateCG2multiple(appModel.getCg(), methodSets, cgs);
// // log.info("seperateCG2multiple"+cgs.size());
// for (int i = 0; i < cgs.size(); i++) {
// CallGraph cg = cgs.get(i);
// Set<SootMethod> methodSet = methodSets.get(i);
// Map<SootMethod, Integer> inDegreeMap = constructInDregreeMap(cg, methodSet);
// removeCirclefromCG(inDegreeMap, cg);
// Map<SootMethod, Integer> outDegreeMap = constructOutDregreeMap(cg, methodSet);
// sortCG(outDegreeMap, cg);
// // log.info("sortCG");
// }
// addTopoForSupplyMulti();
// /** multiple topo queue **/
// List<CallGraph> cgs = new ArrayList<CallGraph>();
// List<Set<SootMethod>> methodSets = new ArrayList<Set<SootMethod>>();
// seperateCG2multiple(appModel.getCg(), methodSets, cgs);
// // log.info("seperateCG2multiple"+cgs.size());
// for (int i = 0; i < cgs.size(); i++) {
// CallGraph cg = cgs.get(i);
// Set<SootMethod> methodSet = methodSets.get(i);
// Map<SootMethod, Integer> inDegreeMap = constructInDregreeMap(cg, methodSet);
// removeCirclefromCG(inDegreeMap, cg);
// Map<SootMethod, Integer> outDegreeMap = constructOutDregreeMap(cg, methodSet);
// sortCG(outDegreeMap, cg);
// // log.info("sortCG");
// }
// addTopoForSupplyMulti();

// /** single topo queue **/
Map<SootMethod, Integer> inDegreeMap = constructInDregreeMap(appModel.getCg());
removeCirclefromCG(inDegreeMap, appModel.getCg());
Map<SootMethod, Integer> outDegreeMap = constructOutDregreeMap(appModel.getCg());
sortCG(outDegreeMap, appModel.getCg());
addTopoForSupplySingle();
/** single topo queue **/
Map<SootMethod, Integer> inDegreeMap = constructInDregreeMap (appModel.getCg());
removeCirclefromCG (inDegreeMap, appModel.getCg());
Map<SootMethod, Integer> outDegreeMap = constructOutDregreeMap (appModel.getCg());

sortCG (outDegreeMap, appModel.getCg());
addTopoForSupplySingle();

}
log.info("Call Graph has " + appModel.getCg().size() + " edges.");
}

/**
* addTopoForSupplyMulti
*/
private void addTopoForSupplyMulti() {
List<SootMethod> subTopo = new ArrayList<SootMethod>();
appModel.getTopoMethodQueueSet().add(subTopo);
for (SootClass sc : Scene.v().getApplicationClasses()) {
for (SootMethod sm : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(sm) == false)
continue;
if (!appModel.getTopoMethodQueue().contains(sm)) {
appModel.getTopoMethodQueue().add(0, sm);
subTopo.add(0, sm);
}
}
}
}

/**
* addTopoForSupplyMulti
*/
private void addTopoForSupplySingle() {
if (appModel.getTopoMethodQueueSet().size() == 0)
appModel.getTopoMethodQueueSet().add(new ArrayList<SootMethod>());
appModel.getTopoMethodQueueSet().add(new ArrayList<>());
List<SootClass> classes = new ArrayList<>(Scene.v().getApplicationClasses());
if(classes.size()==0)
classes = new ArrayList<>(Scene.v().getClasses());
for (List<SootMethod> subTopo : appModel.getTopoMethodQueueSet()) {
for (SootClass sc : Scene.v().getApplicationClasses()) {
for (SootClass sc : classes) {
for (SootMethod sm : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(sm) == false)
continue;
Expand Down Expand Up @@ -203,8 +185,12 @@ private void addInvocationEdges(SootMethod sm, CallGraph callGraph) {
if (invoke != null) { // u is invoke stmt
Set<SootMethod> targetSet = SootUtils.getInvokedMethodSet(sm, u);
for (SootMethod target : targetSet) {
Edge e = new Edge(sm, (Stmt) u, target);
callGraph.addEdge(e);
try {
Edge e = new Edge(sm, (Stmt) u, target);
callGraph.addEdge(e);
}catch (Exception e){

}
}
}
}
Expand Down Expand Up @@ -438,16 +424,17 @@ private Map<SootMethod, Integer> constructOutDregreeMap(CallGraph callGraph) {
Map<SootMethod, Integer> outDegreeMap = new HashMap<SootMethod, Integer>();// get
// outDegreeMap
for (SootClass sc : Scene.v().getApplicationClasses()) {
for (SootMethod m : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(m) == false)
for (SootMethod sm : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(sm) == false)
continue;
outDegreeMap.put(m, 0); // initial outDegreeMap
outDegreeMap.put(sm, 0); // initial outDegreeMap
}
}
Iterator<Edge> it = callGraph.iterator();
while (it.hasNext()) {
Edge edge = it.next();
if (SootUtils.hasSootActiveBody(edge.getTgt().method()) == false)
//not java library method
if (SootUtils.hasSootActiveBody(edge.getTgt().method()) == false || edge.getTgt().method().isJavaLibraryMethod())
continue;
if (outDegreeMap.containsKey(edge.getSrc().method()))
outDegreeMap.put(edge.getSrc().method(), outDegreeMap.get(edge.getSrc()) + 1);
Expand All @@ -466,10 +453,10 @@ private Map<SootMethod, Integer> constructInDregreeMap(CallGraph callGraph) {
Map<SootMethod, Integer> inDegreeMap = new HashMap<SootMethod, Integer>();// get
// outDegreeMap
for (SootClass sc : Scene.v().getApplicationClasses()) {
for (SootMethod m : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(m) == false)
for (SootMethod sm : sc.getMethods()) {
if (SootUtils.hasSootActiveBody(sm) == false)
continue;
inDegreeMap.put(m, 0); // initial outDegreeMap
inDegreeMap.put(sm, 0); // initial outDegreeMap
}
}
Iterator<Edge> it = callGraph.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.iscas.crashtracker.base.MyConfig;
import com.iscas.crashtracker.client.BaseClient;
import com.iscas.crashtracker.client.cg.CgClientOutput;
import com.iscas.crashtracker.client.cg.CgModify;
import com.iscas.crashtracker.client.manifest.ManifestClient;
import com.iscas.crashtracker.utils.ConstantUtils;
import com.iscas.crashtracker.utils.FileUtils;
Expand Down

This file was deleted.

Loading

0 comments on commit 5d71db3

Please sign in to comment.