-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing reflog files; add SimplifiedEvaluator; refactor code
- Loading branch information
Dongjie
committed
Aug 8, 2022
1 parent
cfdcf45
commit 30c9316
Showing
60 changed files
with
1,081 additions
and
1,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
package qilin.stat; | ||
|
||
import qilin.core.PTA; | ||
import qilin.core.builder.FakeMainFactory; | ||
import qilin.core.builder.MethodNodeFactory; | ||
import qilin.core.pag.*; | ||
import qilin.core.sets.P2SetVisitor; | ||
import qilin.core.sets.PointsToSetInternal; | ||
import qilin.util.PTAUtils; | ||
import qilin.util.Stopwatch; | ||
import soot.*; | ||
import soot.jimple.*; | ||
import soot.jimple.toolkits.callgraph.CallGraph; | ||
import soot.jimple.toolkits.callgraph.Edge; | ||
|
||
import java.util.*; | ||
|
||
public class SimplifiedEvaluator implements IEvaluator { | ||
protected final PTA pta; | ||
protected final Exporter exporter; | ||
protected Stopwatch stopwatch; | ||
|
||
public SimplifiedEvaluator(PTA pta) { | ||
this.pta = pta; | ||
exporter = new Exporter(); | ||
} | ||
|
||
@Override | ||
public void begin() { | ||
stopwatch = Stopwatch.newAndStart("PTA evaluator"); | ||
} | ||
|
||
@Override | ||
public void end() { | ||
stopwatch.stop(); | ||
exporter.collectMetric("Time (sec):", String.valueOf(((double) stopwatch.elapsed()))); | ||
exporter.collectMetric("#Reachable Method (CI):", String.valueOf(pta.getNakedReachableMethods().size() - 1)); | ||
CallGraph ciCallGraph = pta.getCallGraph(); | ||
exporter.collectMetric("#Call Edge(CI):", String.valueOf(ciCallGraph.size() - FakeMainFactory.implicitCallEdges)); | ||
|
||
CallGraph callGraph = pta.getCallGraph(); | ||
|
||
// loop over all reachable method's statement to find casts, local | ||
// references, virtual call sites | ||
Set<SootMethod> reachableMethods = new HashSet<>(); | ||
for (MethodOrMethodContext momc : pta.getCgb().getReachableMethods()) { | ||
final SootMethod sm = momc.method(); | ||
reachableMethods.add(sm); | ||
} | ||
int totalPolyCalls = 0; | ||
int totalCastsMayFail = 0; | ||
for (SootMethod sm : reachableMethods) { | ||
// All the statements in the method | ||
for (Unit unit : PTAUtils.getMethodBody(sm).getUnits()) { | ||
Stmt st = (Stmt) unit; | ||
// virtual calls | ||
if (st.containsInvokeExpr()) { | ||
InvokeExpr ie = st.getInvokeExpr(); | ||
if (!(ie instanceof StaticInvokeExpr)) { | ||
// Virtual, Special or Instance | ||
// have to check target soot method, cannot just | ||
// count edges | ||
Set<SootMethod> targets = new HashSet<>(); | ||
for (Iterator<Edge> it = callGraph.edgesOutOf(st); it.hasNext(); ) | ||
targets.add(it.next().tgt()); | ||
if (targets.size() > 1) { | ||
totalPolyCalls++; | ||
} | ||
} | ||
} else if (st instanceof AssignStmt) { | ||
Value rhs = ((AssignStmt) st).getRightOp(); | ||
Value lhs = ((AssignStmt) st).getLeftOp(); | ||
if (rhs instanceof CastExpr && lhs.getType() instanceof RefLikeType) { | ||
final Type targetType = ((CastExpr) rhs).getCastType(); | ||
Value v = ((CastExpr) rhs).getOp(); | ||
if (!(v instanceof Local)) { | ||
continue; | ||
} | ||
boolean fails = false; | ||
Set<Node> pts = new HashSet<>(); | ||
((PointsToSetInternal) pta.reachingObjects((Local) v)).mapToCIPointsToSet().forall(new P2SetVisitor() { | ||
@Override | ||
public void visit(Node n) { | ||
pts.add(n); | ||
} | ||
}); | ||
for (Node n : pts) { | ||
if (fails) { | ||
break; | ||
} | ||
fails = !PTAUtils.castNeverFails(n.getType(), targetType); | ||
} | ||
if (fails) { | ||
totalCastsMayFail++; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
exporter.collectMetric("#May Fail Cast (Total):", String.valueOf(totalCastsMayFail)); | ||
exporter.collectMetric("#Virtual Call Site(Polymorphic):", String.valueOf(totalPolyCalls)); | ||
|
||
ptsStat(); | ||
} | ||
|
||
private void ptsStat() { | ||
int ptsCntNoNative = 0; | ||
int varCntNoNative = 0; | ||
// locals exclude Exceptions | ||
for (Local local : pta.getPag().getLocalPointers()) { | ||
try { | ||
LocalVarNode lvn = pta.getPag().findLocalVarNode(local); | ||
if (local.toString().contains("intermediate/")) { | ||
continue; | ||
} | ||
mLocalVarNodes.add(lvn); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
// stat avg pts. | ||
for (SootMethod sm : pta.getNakedReachableMethods()) { | ||
MethodPAG mpag = pta.getPag().getMethodPAG(sm); | ||
MethodNodeFactory mnf = mpag.nodeFactory(); | ||
if (!sm.isStatic()) { | ||
mLocalVarNodes.add((LocalVarNode) mnf.caseThis()); | ||
} | ||
for (int i = 0; i < sm.getParameterCount(); ++i) { | ||
Type mType = sm.getParameterType(i); | ||
if (mType instanceof RefLikeType) { | ||
mLocalVarNodes.add((LocalVarNode) mnf.caseParm(i)); | ||
} | ||
} | ||
} | ||
Set<LocalVarNode> tmp = new HashSet<>(); | ||
for (LocalVarNode lvn : mLocalVarNodes) { | ||
SootMethod sm = lvn.getMethod(); | ||
if (PTAUtils.isFakeMainMethod(sm)) { | ||
tmp.add(lvn); | ||
continue; | ||
} | ||
PointsToSetInternal cpts = (PointsToSetInternal) pta.reachingObjects(lvn); | ||
final Set<Object> callocSites = getPointsToNewExpr(cpts); | ||
if (callocSites.size() > 0) { | ||
if (!handledNatives.contains(sm.toString())) { | ||
ptsCntNoNative += callocSites.size(); | ||
varCntNoNative++; | ||
} | ||
} else { | ||
tmp.add(lvn); | ||
} | ||
} | ||
mLocalVarNodes.removeAll(tmp); | ||
|
||
exporter.collectMetric("#Avg Points-to Target without Native Var(CI):", String.valueOf(((double) ptsCntNoNative) / (varCntNoNative))); | ||
} | ||
|
||
private final Set<String> handledNatives = Set.of( | ||
"<org.apache.xerces.parsers.XML11Configuration: boolean getFeature0(java.lang.String)>", | ||
"<java.lang.ref.Finalizer: void invokeFinalizeMethod(java.lang.Object)>", | ||
"<java.lang.Thread: java.lang.Thread currentThread()>", | ||
"<java.lang.Thread: void start0()>", | ||
"<java.lang.Object: java.lang.Object clone()>", | ||
"<java.lang.System: void setIn0(java.io.InputStream)>", | ||
"<java.lang.System: void setOut0(java.io.PrintStream)>", | ||
"<java.lang.System: void setErr0(java.io.PrintStream)>", | ||
"<java.io.FileSystem: java.io.FileSystem getFileSystem()>", | ||
"<java.io.UnixFileSystem: java.lang.String[] list(java.io.File)>", | ||
"<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction)>", | ||
"<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)>", | ||
"<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction)>", | ||
"<java.security.AccessController: java.lang.Object doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)>" | ||
); | ||
|
||
private final Set<LocalVarNode> mLocalVarNodes = new HashSet<>(); | ||
|
||
protected Set<Object> getPointsToNewExpr(PointsToSetInternal pts) { | ||
final Set<Object> allocSites = new HashSet<>(); | ||
pts.forall(new P2SetVisitor() { | ||
public void visit(Node n) { | ||
allocSites.add(((AllocNode) n).getNewExpr()); | ||
} | ||
}); | ||
return allocSites; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return exporter.report(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/ArrayNewInstance.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Array.newInstance;int[];qilin.microben.core.reflog.ArrayNewInstance.main;9;; |
3 changes: 3 additions & 0 deletions
3
qilin.microben/src/qilin/microben/core/reflog/ClassForName.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Class.forName;qilin.microben.core.reflog.ClassForName;qilin.microben.core.reflog.ClassForName.main;9;; | ||
Class.forName;qilin.microben.core.reflog.ClassForName;qilin.microben.core.reflog.ClassForName.main;11;; | ||
Class.forName;java.lang.Object;qilin.microben.core.reflog.ClassForName.main;13;; |
3 changes: 3 additions & 0 deletions
3
qilin.microben/src/qilin/microben/core/reflog/ClassForName1.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Class.forName;qilin.microben.core.reflog.ClassForName1;qilin.microben.core.reflog.ClassForName1.main;9;; | ||
Class.forName;qilin.microben.core.reflog.ClassForName1;qilin.microben.core.reflog.ClassForName1.main;11;; | ||
Class.forName;java.lang.Object;qilin.microben.core.reflog.ClassForName1.main;13;; |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/ClassNewInstance.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Class.newInstance;qilin.microben.core.reflog.ClassNewInstance;qilin.microben.core.reflog.ClassNewInstance.main;10;; |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/ConstructorNewInstance.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Constructor.newInstance;<qilin.microben.core.reflog.ConstructorNewInstance: void <init>(java.lang.Object)>;qilin.microben.core.reflog.ConstructorNewInstance.main;17;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Field.get*;<javax.xml.xpath.XPathConstants: javax.xml.namespace.QName STRING>;qilin.microben.core.reflog.DoopRefBug.main;15;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Field.get*;<qilin.microben.core.reflog.FieldGet: java.lang.Object f>;qilin.microben.core.reflog.FieldGet.main;12;; |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/FieldGetStatic.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Field.get*;<qilin.microben.core.reflog.FieldGetStatic: java.lang.Object f>;qilin.microben.core.reflog.FieldGetStatic.main;11;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Field.set*;<qilin.microben.core.reflog.FieldSet: java.lang.Object f>;qilin.microben.core.reflog.FieldSet.main;13;; | ||
Field.set*;<qilin.microben.core.reflog.FieldSet: java.lang.Object f>;qilin.microben.core.reflog.FieldSet.main;14;; |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/FieldSetStatic.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Field.set*;<qilin.microben.core.reflog.FieldSetStatic: java.lang.Object f>;qilin.microben.core.reflog.FieldSetStatic.main;10;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Method.invoke;<qilin.microben.core.reflog.MethodInvoke: java.lang.Object id(java.lang.Object)>;qilin.microben.core.reflog.MethodInvoke.main;8;; |
1 change: 1 addition & 0 deletions
1
qilin.microben/src/qilin/microben/core/reflog/MethodInvokeStatic.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Method.invoke;<qilin.microben.core.reflog.MethodInvokeStatic: java.lang.Object id(java.lang.Object)>;qilin.microben.core.reflog.MethodInvokeStatic.main;15;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.