Skip to content

Commit

Permalink
Add method to extract all statement calls on objects
Browse files Browse the repository at this point in the history
  • Loading branch information
smeyer198 committed Jan 24, 2025
1 parent 41ce258 commit 85f8336
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -216,6 +218,22 @@ public Map<Edge, DeclaredMethod> getInvokedMethodOnInstance() {
return invokedMethodsOnInstance;
}

/**
* Get all statements that contain an invoke expression belonging to the original seed.
*
* @return the statements that contain invoke expressions belonging to the original seed.
*/
public Collection<Statement> getInvokeStatementsOnInstance() {
Collection<Statement> statements = new HashSet<>();

Map<Edge, DeclaredMethod> callsOnObject = getInvokedMethodOnInstance();
for (Edge edge : callsOnObject.keySet()) {
statements.add(edge.getStart());
}

return statements;
}

public QueryResults getPotentialNullPointerDereferences() {
// FIXME this should be located nullpointer analysis
Set<Node<Edge, Val>> res = Sets.newHashSet();
Expand Down
19 changes: 10 additions & 9 deletions boomerangPDS/src/test/java/test/cases/bugfixes/Repro.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import boomerang.scene.jimple.*;
import com.google.common.collect.Sets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.junit.Test;
import soot.*;
Expand Down Expand Up @@ -70,7 +70,7 @@ private static void analyze(String... expectedCallSignatureOnFoo) {
PackManager.v().getPack("wjtp").apply();
}

private static Map<Edge, DeclaredMethod> getMethodsInvokedFromInstanceInStatement(
private static Collection<Statement> getMethodsInvokedFromInstanceInStatement(
Statement queryStatement) {
Val var = new AllocVal(queryStatement.getLeftOp(), queryStatement, queryStatement.getRightOp());
ForwardQuery fwq =
Expand All @@ -83,7 +83,7 @@ private static Map<Edge, DeclaredMethod> getMethodsInvokedFromInstanceInStatemen
var);
Boomerang solver = new Boomerang(new SootCallGraph(), SootDataFlowScope.make(Scene.v()), opts);
ForwardBoomerangResults<NoWeight> results = solver.solve(fwq);
return results.getInvokedMethodOnInstance();
return results.getInvokeStatementsOnInstance();
}

static class ReproTransformer extends SceneTransformer {
Expand Down Expand Up @@ -115,13 +115,14 @@ protected void internalTransform(String name, Map<String, String> options) {

// This will only show results if set_exclude above gets uncommented
System.out.println("\nFoo invoked methods:");
Set<Entry<Edge, DeclaredMethod>> entries =
getMethodsInvokedFromInstanceInStatement(newFoo).entrySet();
Collection<Statement> statements = getMethodsInvokedFromInstanceInStatement(newFoo);
Set<String> methodCalledOnFoo = Sets.newHashSet();
for (Map.Entry<Edge, DeclaredMethod> e : entries) {
System.out.println("\t" + e.getKey().toString());
System.out.println("\t\t" + e.getValue().toString());
methodCalledOnFoo.add(e.getValue().toString());
for (Statement s : statements) {
System.out.println("\t" + s);

DeclaredMethod calledMethod = s.getInvokeExpr().getMethod();
System.out.println("\t\t" + calledMethod);
methodCalledOnFoo.add(calledMethod.toString());
}

assert methodCalledOnFoo.equals(Sets.newHashSet(expectedCalledMethodsOnFoo));
Expand Down

0 comments on commit 85f8336

Please sign in to comment.