soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.88k stars 708 forks source link

RuntimeException Local not in Chain #243

Closed f1n4rf1n closed 10 years ago

f1n4rf1n commented 10 years ago

This error pops up when trying to do a infoflow analysis first and then using soot afterwards (see code). When I move the InfoflowResults res = app.runInfoflow() to the second position right after Scene.v().runNecessaryClasses(); then the error doesn't pops up and it seems that everything works as desired.

//Do Infoflow analysis
SetupApplication app = new SetupApplication
            ("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms",
             "/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk");
app.calculateSourcesSinksEntrypoints("/Users/neji/Documents/Uni-Stuff/Master-      
                Thesis/FlowDroid/SourcesAndSinks.txt");

app.setComputeResultPaths(true);
app.setTaintWrapper(new EasyTaintWrapper("/Users/neji/Documents/Uni-Stuff/Master-
               Thesis/FlowDroid/EasyTaintWrapperSource.txt"));
app.setEnableImplicitFlows(true);

InfoflowResults res = app.runInfoflow();  

soot.G.reset();

Options.v().set_src_prec(Options.src_prec_apk);
        Options.v().set_process_dir(Collections.singletonList("/Users/neji/Desktop/AndroidSpecific_DirectLeak1.apk"));
Options.v().set_android_jars("/Users/neji/Documents/Uni-Stuff/Master-Thesis/android-platforms");
Options.v().set_whole_program(true);
Options.v().set_allow_phantom_refs(true);
Options.v().set_output_format(Options.output_format_class);
Options.v().setPhaseOption("cg.spark", "on");

Scene.v().loadNecessaryClasses();

// ------->   InfoflowResults res = app.runInfoflow();   < --------------

SootMethod entryPoint = app.getEntryPointCreator().createDummyMain();
Options.v().set_main_class(entryPoint.getSignature());

Scene.v().setEntryPoints(Collections.singletonList(entryPoint));

PackManager.v().runPacks();
CallGraph cg = Scene.v().getCallGraph();
[...]   

Edit: Here is the Stacktrace:

Exception in thread "main" java.lang.RuntimeException: Local not in chain : $r0 in <dummyMainClass: void dummyMainMethod()>
    at soot.Body.validateLocal(Body.java:279)
    at soot.Body.validateLocals(Body.java:267)
    at soot.Body.validate(Body.java:231)
    at soot.jimple.JimpleBody.validate(JimpleBody.java:71)
    at soot.baf.BafBody.<init>(BafBody.java:66)
    at soot.baf.Baf.newBody(Baf.java:560)
    at soot.PackManager.convertJimpleBodyToBaf(PackManager.java:956)
    at soot.PackManager.runBodyPacks(PackManager.java:916)
    at soot.PackManager.runBodyPacks(PackManager.java:584)
    at soot.PackManager.runBodyPacks(PackManager.java:487)
    at soot.PackManager.runPacksNormally(PackManager.java:464)
    at soot.PackManager.runPacks(PackManager.java:388)
    at test.main(test.java:62)
ericbodden commented 10 years ago

Can you please provide a full stack trace? Thanks

StevenArzt commented 10 years ago

The problem arises because of caching in the BaseEntryPointCreator class. You first call runInfoflow() which creates a dummy main method that it needs as an entry point for the callgraph used in the data flow analysis. Then, you reset Soot and use the same entry point creator again in a new instance of Soot. The caches in the entry point creator now however contain outdated values which are no longer valid in the new Soot instance.

The "official" way around this problem would be to do it all in the same Soot run if possible. You can also call the overload of runInfoflow() that takes two parameters. In this case, the second parameter is an interface implementing a callback method which FlowDroid invokes once the data flow computation is done. Inside this method, the callgraph used by FlowDroid is still alive, so you don't even need to run your own Soot instance, but can directly access Scene.v().getCallgraph() or access any Soot objects you may like. You can take the callback handler as a special "phase".

StevenArzt commented 10 years ago

I'll close that issue since it has not received any further attention for more than two weeks. If the problem persists, feel free to re-open it.