Skip to content

Commit

Permalink
submission
Browse files Browse the repository at this point in the history
  • Loading branch information
kadirayk committed May 5, 2023
1 parent 5b47146 commit dfb1aa5
Show file tree
Hide file tree
Showing 13 changed files with 616 additions and 17 deletions.
18 changes: 16 additions & 2 deletions src/main/java/analysis/IDELinearConstantAnalysisProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
import heros.*;
import heros.edgefunc.EdgeIdentity;
import heros.flowfunc.Identity;
import heros.flowfunc.KillAll;
import soot.*;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JimpleLocal;
import soot.jimple.toolkits.ide.DefaultJimpleIDETabulationProblem;
import soot.toolkits.graph.BriefUnitGraph;
import soot.toolkits.graph.DirectedGraph;
import util.CFGUtil;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -107,13 +110,24 @@ public FlowFunction<DFF> getCallFlowFunction(Unit callStmt, SootMethod dest) {

@Override
public FlowFunction<DFF> getReturnFlowFunction(Unit callSite, SootMethod calleeMethod, Unit exitStmt, Unit returnSite) {
CPAReturnFlowFunctionProvider ffp = new CPAReturnFlowFunctionProvider(callSite, exitStmt, icfg.getMethodOf(callSite));
CPAReturnFlowFunctionProvider ffp = new CPAReturnFlowFunctionProvider(callSite, exitStmt, icfg.getMethodOf(callSite), icfg.getMethodOf(exitStmt));
return ffp.getFlowFunction();
}

@Override
public FlowFunction<DFF> getCallToReturnFlowFunction(Unit callSite, Unit returnSite) {
return Identity.v();
// we kill statics and keep rest as id
return new FlowFunction<DFF>() {
@Override
public Set<DFF> computeTargets(DFF source) {
if(source.getValue() instanceof StaticFieldRef){
return Collections.emptySet();
}
Set<DFF> res = new HashSet<>();
res.add(source);
return res;
}
};
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public EdgeFunction<Integer> meetWith(EdgeFunction otherFunction) {
} else if (otherFunction instanceof IntegerAllBottom) {
return otherFunction;
}
throw new RuntimeException("can't meeet: " + this.toString() + " and " + otherFunction.toString());
throw new RuntimeException("can't meet: " + this.toString() + " and " + otherFunction.toString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import analysis.data.DFF;
import analysis.flowfunctions.call.CallFF;
import analysis.flowfunctions.call.ReturnFF;
import analysis.flowfunctions.call.ReturnVoidFF;
import analysis.flowfunctions.normal.FieldStoreAliasHandler;
import heros.FlowFunction;
import heros.flowfunc.KillAll;
Expand All @@ -15,6 +16,7 @@
import soot.jimple.InvokeExpr;
import soot.jimple.ReturnStmt;
import soot.jimple.Stmt;
import soot.jimple.internal.JReturnVoidStmt;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -26,7 +28,7 @@ public class CPAReturnFlowFunctionProvider implements FlowFunctionProvider<DFF>

private FlowFunction<DFF> flowFunction;

public CPAReturnFlowFunctionProvider(Unit callSite, Unit exitStmt, SootMethod method){
public CPAReturnFlowFunctionProvider(Unit callSite, Unit exitStmt, SootMethod caller, SootMethod callee){
flowFunction = KillAll.v(); // we want to kill everything else when returning from a nested context
if (exitStmt instanceof ReturnStmt) {
ReturnStmt returnStmt = (ReturnStmt) exitStmt;
Expand All @@ -38,10 +40,12 @@ public CPAReturnFlowFunctionProvider(Unit callSite, Unit exitStmt, SootMethod me
if (leftOp instanceof Local) {
final Local tgtLocal = (Local) leftOp;
final Local retLocal = (Local) op;
flowFunction = new ReturnFF(tgtLocal, retLocal, new FieldStoreAliasHandler(method, callSite, tgtLocal));
flowFunction = new ReturnFF(tgtLocal, retLocal, new FieldStoreAliasHandler(caller, callSite, tgtLocal));
}
}
}
}else if(exitStmt instanceof JReturnVoidStmt){
flowFunction = new ReturnVoidFF(callSite, callee);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/analysis/flowfunctions/call/CallFF.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import soot.SootMethod;
import soot.Value;
import soot.jimple.IntConstant;
import soot.jimple.StaticFieldRef;

import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -34,6 +35,9 @@ public Set<DFF> computeTargets(DFF source) {
return Collections.emptySet();
}
Set<DFF> res = new HashSet<>();
if(source==zeroValue || source.getValue() instanceof StaticFieldRef){
res.add(source);
}
for (int i = 0; i < callArgs.size(); i++) {
// Special case: check if function is called with integer literals as params
if (callArgs.get(i) instanceof IntConstant && source == zeroValue) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/analysis/flowfunctions/call/ReturnFF.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import analysis.flowfunctions.normal.FieldStoreAliasHandler;
import heros.FlowFunction;
import soot.Local;
import soot.jimple.StaticFieldRef;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -29,6 +30,9 @@ public Set<DFF> computeTargets(DFF source) {
res.add(DFF.asDFF(tgtLocal));
aliasHandler.handleAliases(res);
}
if(source.getValue() instanceof StaticFieldRef){
res.add(source);
}
return res;
}
}
75 changes: 75 additions & 0 deletions src/main/java/analysis/flowfunctions/call/ReturnVoidFF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package analysis.flowfunctions.call;

import analysis.data.DFF;
import analysis.flowfunctions.normal.FieldStoreAliasHandler;
import heros.FlowFunction;
import heros.solver.Pair;
import soot.*;
import soot.jimple.InvokeStmt;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JIdentityStmt;
import soot.jimple.internal.JInstanceFieldRef;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ReturnVoidFF implements FlowFunction<DFF> {
private Unit callsite;
private SootMethod method;

public ReturnVoidFF(Unit callsite, SootMethod method) {
this.callsite = callsite;
this.method = method;
}


@Override
public Set<DFF> computeTargets(DFF source) {
callsite.toString();
Set<DFF> res = new HashSet<>();
Value d = source.getValue();
if(d instanceof JInstanceFieldRef){
if(callsite instanceof InvokeStmt){
InvokeStmt invoke = (InvokeStmt) callsite;
List<Value> args = invoke.getInvokeExpr().getArgs();
JInstanceFieldRef fieldRef = (JInstanceFieldRef) d;
Value base = fieldRef.getBase();
int argIndex = 0;
for (Value arg : args) {
Pair<Value, Integer> mArg = new Pair<>(arg, argIndex);
if(isSameParam(method, mArg, base)){
JInstanceFieldRef mapRef = new JInstanceFieldRef(arg, fieldRef.getFieldRef());
res.add(DFF.asDFF(mapRef));
}
argIndex++;
}
}
}
if(d instanceof StaticFieldRef){
res.add(source);
}
return res;
}

boolean isSameParam(SootMethod method, Pair<Value, Integer> actualParam, Value formalParam){
if(actualParam.getO1().getType() instanceof RefType){
Body activeBody = method.getActiveBody();
UnitPatchingChain units = activeBody.getUnits();
int idIndex = -1; // @this
for (Unit unit : units) {
if(unit instanceof JIdentityStmt){
JIdentityStmt id = (JIdentityStmt) unit;
Value rightOp = id.getRightOp();
Value leftOp = id.getLeftOp();
if(rightOp.getType().equals(actualParam.getO1().getType()) && leftOp.equals(formalParam) && actualParam.getO2().equals(idIndex)){
return true;
}
idIndex++;
}
}
}
return false;
}

}
2 changes: 1 addition & 1 deletion src/main/java/solver/JimpleIDESolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public JimpleIDESolver(IDETabulationProblem<Unit, D, SootMethod, V, I> problem)

public void solve(String targetClassName) {
super.solve();
this.dumpResults(targetClassName);
//this.dumpResults(targetClassName);
}

private static List<Pair<String, Set<String>>> checked = new ArrayList<>();
Expand Down
Loading

0 comments on commit dfb1aa5

Please sign in to comment.