Skip to content

Commit

Permalink
refactor(spgroup#31): pr adjuts
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Oct 6, 2021
1 parent 77f532e commit d55e86b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import soot.jimple.IdentityStmt;
import soot.jimple.InvokeStmt;
import soot.jimple.Stmt;
import soot.jimple.internal.JAssignStmt;

import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* This abstract class works as a contract. Whenever we
Expand Down Expand Up @@ -42,7 +42,6 @@ public void loadSinkStatements() {
sinkStatements = loadStatements(sinkDefinitions, Statement.Type.SINK);
}


public List<Statement> getSourceStatements() {
return sourceStatements;
}
Expand All @@ -51,7 +50,6 @@ public List<Statement> getSinkStatements() {
return sinkStatements;
}


/**
* This method should return a list of pairs, where the
* first element is the full qualified name of
Expand Down Expand Up @@ -153,7 +151,7 @@ else if(u instanceof InvokeStmt) {
return res;
}

private Statement createStatement(SootMethod sm, Unit u, Statement.Type type) {
public Statement createStatement(SootMethod sm, Unit u, Statement.Type type) {
return Statement.builder().setClass(sm.getDeclaringClass()).setMethod(sm)
.setUnit(u).setType(type).setSourceCodeLineNumber(u.getJavaSourceStartLineNumber())
.build();
Expand Down Expand Up @@ -199,11 +197,10 @@ private SootClass retrieveOuterClass(SootClass aClass) {
* or not. So, in this implementation, we first try to retrieve
* one. If an exception is thrown, we just return null.
*/
private Body retrieveActiveBodySafely(SootMethod method) {
public Body retrieveActiveBodySafely(SootMethod method) {
try {
return method.retrieveActiveBody();
}
catch(RuntimeException e) {
} catch (RuntimeException e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private FlowSet<DataFlowAbstraction> traverse(FlowSet<DataFlowAbstraction> in, S

this.traversedMethods.add(sootMethod);

Body body = retrieveActiveBodySafely(sootMethod);
Body body = definition.retrieveActiveBodySafely(sootMethod);

if (body != null) {
for (Unit unit : body.getUnits()) {
Expand All @@ -146,13 +146,6 @@ private FlowSet<DataFlowAbstraction> traverse(FlowSet<DataFlowAbstraction> in, S
return in;
}

private Body retrieveActiveBodySafely(SootMethod sootMethod) {
try {
return sootMethod.retrieveActiveBody();
} catch (RuntimeException e) {
return null;
}
}

private FlowSet<DataFlowAbstraction> runAnalysisWithTaggedUnit(FlowSet<DataFlowAbstraction> in, SootMethod sootMethod,
Statement.Type flowChangeTag, Unit unit) {
Expand Down Expand Up @@ -193,7 +186,7 @@ private FlowSet<DataFlowAbstraction> runAnalysis(FlowSet<DataFlowAbstraction> in
separeteAbstraction(in);
if (tagged) {
Statement stmt = getStatementAssociatedWithUnit(sootMethod, unit, flowChangeTag);
setStackTraceInStmt(stmt);
stmt.setTraversedLine(new ArrayList<>(this.stacktraceList));
// logger.log(Level.INFO, () -> String.format("%s", "stmt: " + stmt.toString()));
gen(in, stmt);
} else {
Expand Down Expand Up @@ -226,12 +219,12 @@ In this case, this condition will be executed for the call to the foo() method a

private void separeteAbstraction(FlowSet<DataFlowAbstraction> in) {
in.forEach(item -> {
if (isLefAndRightStatement(item.getStmt())) {
right.add(item);
if (item.getStmt().isLefAndRightStatement()) {
left.add(item);
} else if (isLeftStatement(item.getStmt())) {
right.add(item);
} else if (item.getStmt().isLeftStatement()) {
left.add(item);
} else if (isRightStatement(item.getStmt())) {
} else if (item.getStmt().isRightStatement()) {
right.add(item);
}
});
Expand Down Expand Up @@ -281,13 +274,13 @@ private boolean isInLeftAndRightStatementFlow(Statement.Type flowChangeTag) {
// TODO add depth to InstanceFieldRef and StaticFieldRef...
// TODO rename Statement. (UnitWithExtraInformations)
private void gen(FlowSet<DataFlowAbstraction> in, Statement stmt) {
if (isLeftStatement(stmt)) {
if (stmt.isLeftStatement()) {
checkConflict(stmt, right);

} else if (isRightStatement(stmt)) {
} else if (stmt.isRightStatement()) {
checkConflict(stmt, left);

} else if (isLefAndRightStatement(stmt)) {
} else if (stmt.isLefAndRightStatement()) {
addConflict(stmt, stmt);
}
addStmtToList(stmt, in);
Expand Down Expand Up @@ -373,21 +366,17 @@ private String getArrayRefName(ArrayRef arrayRef) {
private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u, Statement.Type flowChangeTag) {
if (isLeftAndRightUnit(u) || isInLeftAndRightStatementFlow(flowChangeTag) || isBothUnitOrBothStatementFlow(u,
flowChangeTag)) {
return createStatement(sootMethod, u, Statement.Type.SOURCE_SINK);
return definition.createStatement(sootMethod, u, Statement.Type.SOURCE_SINK);
} else if (isLeftUnit(u)) {
return findLeftStatement(u);
} else if (isRightUnit(u)) {
return findRightStatement(u);
} else if (isInLeftStatementFlow(flowChangeTag)) {
return createStatement(sootMethod, u, flowChangeTag);
return definition.createStatement(sootMethod, u, flowChangeTag);
} else if (isInRightStatementFlow(flowChangeTag)) {
return createStatement(sootMethod, u, flowChangeTag);
return definition.createStatement(sootMethod, u, flowChangeTag);
}
return createStatement(sootMethod, u, Statement.Type.IN_BETWEEN);
}

private void setStackTraceInStmt(Statement stmt) {
stmt.setTraversedLine(new ArrayList<>(this.stacktraceList));
return definition.createStatement(sootMethod, u, Statement.Type.IN_BETWEEN);
}

private void addStackTrace(TraversedLine traversedLine) {
Expand Down Expand Up @@ -424,21 +413,4 @@ private Statement findLeftStatement(Unit u) {
findFirst().get();
}

private Statement createStatement(SootMethod sootMethod, Unit u, Statement.Type flowChangeTag) {
return Statement.builder().setClass(sootMethod.getDeclaringClass()).setMethod(sootMethod)
.setUnit(u).setType(flowChangeTag).setSourceCodeLineNumber(u.getJavaSourceStartLineNumber())
.build();
}

private boolean isRightStatement(Statement stmt) {
return stmt.getType().equals(Statement.Type.SINK);
}

private boolean isLeftStatement(Statement stmt) {
return stmt.getType().equals(Statement.Type.SOURCE);
}

private boolean isLefAndRightStatement(Statement stmt) {
return stmt.getType().equals(Statement.Type.SOURCE_SINK);
}
}
12 changes: 12 additions & 0 deletions src/main/java/br/unb/cic/analysis/model/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ public boolean isSink() {
return type == Type.SINK || type == Type.SOURCE_SINK;
}

public boolean isRightStatement() {
return this.type == Type.SINK || type == Type.SOURCE_SINK;
}

public boolean isLeftStatement() {
return this.type == Type.SOURCE || type == Type.SOURCE_SINK;
}

public boolean isLefAndRightStatement() {
return this.type == Type.SOURCE_SINK;
}

public boolean isAssign() {
return this.unit instanceof AssignStmt;
}
Expand Down

0 comments on commit d55e86b

Please sign in to comment.