Repository navigation
Closed
Description
As I mentioned on the other tracker, I'm still a bit confused about how Boomerang's forward queries interact with exclusions. I've crafted a more complete small reproduction that I think illustrates my confusion.
Here's a summary:
- If I craft a
ForwardQuerypointing tonew ArrayList, Boomerang finds the methods invoked on that instance correctly. - If I do the same thing pointing to my custom
Fooclass (defined below), Boomerang finds no invoked methods on it. - If I change my Soot setup to exclude
Foofrom analysis (just uncomment the commented line below), then Boomerang successfully finds the invoked methods on it.
For a simple example like this I can obviously just exclude Foo, but in the real world I often want to analyze aspects of Foo (and my Boomerang backward queries might jump into it) as well as getting methods invoked on its instances.
Can you help me understand why forward queries seem so sensitive to exclusions?
Harness code (Boomerang 3.0.2 from this repo + Soot 4.1)
import boomerang.Boomerang;
import boomerang.BoomerangOptions;
import boomerang.ForwardQuery;
import boomerang.scene.*;
import boomerang.scene.jimple.*;
import soot.*;
import soot.jimple.AssignStmt;
import soot.options.Options;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
public class Repro {
static BoomerangOptions opts = new IntAndStringBoomerangOptions();
private static void setupSoot(String classPath) {
Options.v().set_whole_program(true);
Options.v().setPhaseOption("cg.spark", "on");
Options.v().set_no_bodies_for_excluded(true);
Options.v().set_allow_phantom_refs(true);
Options.v().set_keep_line_number(true);
/* ********* Uncomment this line to see methods invoked on Foo! ********* */
// Options.v().set_exclude(Collections.singletonList("Foo"));
Options.v().setPhaseOption("jb", "use-original-names:true");
Options.v().set_soot_classpath(classPath);
Options.v().set_prepend_classpath(true);
Options.v().set_process_dir(Arrays.asList(classPath.split(":")));
Scene.v().loadNecessaryClasses();
}
private static void analyze() {
PackManager.v().getPack("wjtp").add(new Transform("wjtp.repro", new ReproTransformer()));
PackManager.v().getPack("cg").apply();
PackManager.v().getPack("wjtp").apply();
}
public static void main(String[] args) {
setupSoot("Test.jar");
analyze();
}
private static Map<Statement, DeclaredMethod> getMethodsInvokedFromInstanceInStatement(Method method, AssignStmt as) {
Boomerang solver = new Boomerang(new SootCallGraph(), SootDataFlowScope.make(Scene.v()), opts);
Statement stmt = JimpleStatement.create(as, method)[0];
Val var = new AllocVal(new JimpleVal(as.getLeftOp(), method), stmt, new JimpleVal(as.getRightOp(), method));
ForwardQuery fwq = new ForwardQuery(stmt, var);
return solver.solve(fwq).getInvokedMethodOnInstance();
}
static class ReproTransformer extends SceneTransformer {
@Override
protected void internalTransform(String name, Map<String, String> options) {
BoomerangPretransformer.v().reset();
BoomerangPretransformer.v().apply();
SootMethod m = Scene.v().getMethod("<Test: java.util.List foos()>");
Method method = JimpleMethod.of(m);
System.out.println("All method units:");
for (Unit u : m.getActiveBody().getUnits()) {
System.out.println("\t" + u.toString());
}
AssignStmt newFoo = (AssignStmt) m.getActiveBody().getUnits().stream().filter(
x -> x.toString().contains("$stack2 = new Foo")).findFirst().get();
AssignStmt newList = (AssignStmt) m.getActiveBody().getUnits().stream().filter(
x -> x.toString().contains("$stack4 = new java.util.LinkedList")).findFirst().get();
// This will only show results if set_exclude above gets uncommented
System.out.println("\nFoo invoked methods:");
for (Map.Entry<Statement, DeclaredMethod> e : getMethodsInvokedFromInstanceInStatement(method, newFoo).entrySet()) {
System.out.println("\t" + e.getKey().toString());
System.out.println("\t\t" + e.getValue().toString());
}
// This will show results regardless of the exclusion
System.out.println("\nList invoked methods:");
for (Map.Entry<Statement, DeclaredMethod> e : getMethodsInvokedFromInstanceInStatement(method, newList).entrySet()) {
System.out.println("\t" + e.getKey().toString());
System.out.println("\t\t" + e.getValue().toString());
}
}
}
}Code for analysis
import java.util.LinkedList;
import java.util.List;
class Foo {
void bar() {
System.out.println("zomg bar");
}
public void baz() {
System.out.println("zomg baz");
}
}
public class Test {
public static List<Foo> foos() {
Foo foo = new Foo();
foo.baz();
System.out.println(foo);
List<Foo> x = new LinkedList<>();
x.add(foo);
foo.bar();
return x;
}
public static void main(String[] args) {
System.out.println(foos());
}
}How I produced Test.jar that the harness consumes
javac Test.java
jar cvf Test.jar *.class
Metadata
Metadata
Assignees
Labels
No labels
Activity
johspaeth commentedon Aug 22, 2020
Great, thanks for sharing a reproducible example that helps a lot. I'll have a look at it and get back to you.
johspaeth commentedon Aug 26, 2020
Thanks for the example. It allowed me to quickly look into the code.
There is a bug in the implementation of
getInvokedMethodOnInstance. I push a fix and a new version by the end of the week.copumpkin commentedon Aug 26, 2020
Thanks! That's great news, I'll look forward to updating 😄
While you were looking, is there anything obviously silly or wrong I was doing in my setup that will cause me issues down the line? I simplified the core Boomerang querying code for this repro, but the setup stuff is mostly the same.
copumpkin commentedon Sep 2, 2020
Hi @johspaeth, do you know if there's a simple workaround I could use until it's fixed? Or if an old version didn't have this issue?
[#5] Test setup
Test case for #5
Merge branch 'issue/#9' into issue/#5
johspaeth commentedon Nov 9, 2020
@copumpkin The issue is solved in the latest version (3.1.1).
I added a test for the missing reported call and used your code for testing. Thanks for reporting.
copumpkin commentedon Nov 9, 2020
Thank you! I'll give it a go in the coming week 👍
Merge branch 'issue/#5' into issue/#9