[Soot-list] Sample Execution of Heros IFDS solver
Chris Shiflet
cshiflet at pjrcorp.com
Thu Sep 13 13:27:52 EDT 2018
Sure, I'd be happy to, Eric. I was considering doing so already. I'll be in-touch off the mailing list to coordinated if needed.
-----Original Message-----
From: Eric Bodden <eric.bodden at uni-paderborn.de>
Sent: Thursday, September 13, 2018 1:09 AM
To: Chris Shiflet <cshiflet at pjrcorp.com>
Cc: Soot list <soot-list at sable.mcgill.ca>
Subject: Re: [Soot-list] Sample Execution of Heros IFDS solver
Thanks a lot Chris!
It would be great if we could turn this into a Wiki page on Github (in Heros’s space there). As my time is limited these days, I wonder if you would like to give this a try.
Best wishes
Eric
> On 12. Sep 2018, at 20:40, Chris Shiflet <cshiflet at pjrcorp.com> wrote:
>
> For reference, this is my code from earlier updated to reflect Eric's guidance to run Heros in the "wjtp" pack. I include it as an example of how to run Heros IFDS solver in Soot because I could easily find one elsewhere. A big thanks, again, to Eric and Manuel for their help.
>
> ------------------------------------------------------
>
> // Subclass of SceneTransformer to run Heros IFDS solver in Soot's
> "wjtp" pack public class IFDSDataFlowTransformer extends SceneTransformer {
> @Override
> protected void internalTransform(String phaseName, Map<String, String> options) {
> JimpleBasedInterproceduralCFG icfg= new JimpleBasedInterproceduralCFG();
> IFDSTabulationProblem<Unit, Pair<Value,
> Set<DefinitionStmt>>, SootMethod,
> InterproceduralCFG<Unit, SootMethod>> problem = new
> IFDSReachingDefinitions(icfg);
>
> IFDSSolver<Unit, Pair<Value, Set<DefinitionStmt>>,
> SootMethod, InterproceduralCFG<Unit, SootMethod>> solver =
> new IFDSSolver<Unit, Pair<Value,
> Set<DefinitionStmt>>, SootMethod, InterproceduralCFG<Unit,
> SootMethod>>(problem);
>
> System.out.println("Starting solver");
> solver.solve();
> System.out.println("Done");
> }
> }
>
> ------------------------------------------------------
>
> // Code fragment to setup and execute Heros IFDS analysis w/in Soot "wjtp" pack
> Options.v().set_soot_classpath(classpath);
> Options.v().set_whole_program(true);
> Options.v().set_app(true);
>
> Options.v().setPhaseOption("cg", "safe-newinstance:true");
> Options.v().setPhaseOption("cg.cha","enabled:false");
>
> // Enable SPARK
> Options.v().setPhaseOption("cg.spark","enabled:true");
> Options.v().setPhaseOption("cg.spark","verbose:true");
> Options.v().setPhaseOption("cg.spark","on-fly-cg:true");
>
> Options.v().set_allow_phantom_refs(true);
> Options.v().set_output_format(Options.output_format_class);
>
> Options.v().set_main_class(mainClass);
>
> SootClass c = Scene.v().loadClass(mainClass, SootClass.BODIES);
> c.setApplicationClass();
>
> SootMethod entryPoint = c.getMethodByName("main");
> List<SootMethod> entryPoints = new ArrayList<SootMethod>();
> entryPoints.add(entryPoint);
> Scene.v().setEntryPoints(entryPoints);
>
> // Set output dir
> Options.v().set_output_dir(outputDir);
>
> // Load IFDSDataFlowTransformer declared above into "wjtp" pack
> PackManager.v().getPack("wjtp").add(new
> Transform("wjtp.herosifds", new IFDSDataFlowTransformer()));
>
> // Execute Soot
> soot.Main.main();
>
> -----Original Message-----
> From: Eric Bodden <eric.bodden at uni-paderborn.de>
> Sent: Wednesday, September 12, 2018 12:32 AM
> To: Chris Shiflet <cshiflet at pjrcorp.com>
> Cc: Manuel Benz <manuel.benz at uni-paderborn.de>; Soot list
> <soot-list at sable.mcgill.ca>
> Subject: Re: [Soot-list] Issue Loading Method Bodies
>
> Hi Chris, hi all.
>
> The recommended way to run _any_ whole-program analysis in Soot, including Heros, is to execute it within the “wjtp” pack. You need to create a new SceneTransformer callback which inside its tranasform-method contains exactly the code you have to execute Heros. This SceneTransformer you then add to the wjtp pack. Then _afterwards_ you call Soot’s main method. That should also take care of the body-release issue, as then Heros will execute before bodies are released.
>
> Best wishes
> Eric
>
>> On 11. Sep 2018, at 18:37, Chris Shiflet <cshiflet at pjrcorp.com> wrote:
>>
>> Hi Manuel,
>>
>> The "-no-writeout-body-releasing" option you suggested corrected my issue. There is an active method body present after setting it to true using the follow line:
>>
>> Options.v().set_no_writeout_body_releasing(true);
>>
>> Thanks also for the tip about "Scene.v().loadNecessaryClasses()". Out of curiosity, should I be running Heros elsewhere rather than after executing "soot.Main.main()"?
>>
>> Thank you for your help!
>> ---Chris
>>
>> -----Original Message-----
>> From: Manuel Benz <manuel.benz at uni-paderborn.de>
>> Sent: Tuesday, September 11, 2018 9:51 AM
>> To: Eric Bodden <eric.bodden at uni-paderborn.de>; Chris Shiflet
>> <cshiflet at pjrcorp.com>
>> Cc: Soot list <soot-list at sable.mcgill.ca>
>> Subject: Re: [Soot-list] Issue Loading Method Bodies
>>
>> Hi Chris.
>>
>> Can you try the "-no-writeout-body-releasing" option?
>> Soot releases method bodies on write out by default. Since you are using IFDS after running "soot.Main.main()", write out should already have taken place.
>>
>> BTW. You do not need to call "Scene.v().loadNecessaryClasses();" manually if you're running Soot by calling "soot.Main.main()" .
>>
>> Best,
>> Manuel
>>
>> Am 11.09.18, 13:37 schrieb "Soot-list im Auftrag von Eric Bodden" <soot-list-bounces at CS.McGill.CA im Auftrag von eric.bodden at uni-paderborn.de>:
>>
>> Hmm, does the code for this method exist on the classpath you provide to Soot?
>>
>> com.example.UISample.JSONProject: void main(java.lang.String[])
>>
>> Cheers
>> Eric
>>
>>> On 10. Sep 2018, at 16:55, Chris Shiflet <cshiflet at pjrcorp.com> wrote:
>>>
>>> Hi Eric,
>>>
>>> Yes, I do enabled whole-program mode. I neglected to include them in my code snippet. These lines appears just before the snippet in my previous message.
>>>
>>> Options.v().set_whole_program(true);
>>> Options.v().set_app(true);
>>>
>>> Thanks,
>>> ---Chris
>>>
>>> -----Original Message-----
>>> From: Eric Bodden <eric.bodden at uni-paderborn.de>
>>> Sent: Monday, September 10, 2018 3:29 AM
>>> To: Chris Shiflet <cshiflet at pjrcorp.com>
>>> Subject: Re: [Soot-list] Issue Loading Method Bodies
>>>
>>> Hi Chris.
>>>
>>> Do you have whole-program-mode enabled? (-w flag) I cannot see this in your code.
>>>
>>> Cheers
>>> Eric
>>>
>>>> On 7. Sep 2018, at 22:02, Chris Shiflet <cshiflet at pjrcorp.com> wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I'm having an issue with loading method bodies when I attempt run the HEROS IFDS solver. Let me start with my stack trace:
>>>>
>>>> Running Heros IFDS Solver...
>>>> Exception in thread "main" java.lang.RuntimeException: no active body present for method <com.example.UISample.JSONProject: void main(java.lang.String[])>
>>>> at soot.SootMethod.getActiveBody(SootMethod.java:359)
>>>> at soot.jimple.toolkits.ide.exampleproblems.IFDSReachingDefinitions.initialSeeds(IFDSReachingDefinitions.java:170)
>>>> at heros.solver.IFDSSolver$1.initialSeeds(IFDSSolver.java:68)
>>>> at heros.solver.IDESolver.<init>(IDESolver.java:200)
>>>> at heros.solver.IDESolver.<init>(IDESolver.java:165)
>>>> at heros.solver.IFDSSolver.<init>(IFDSSolver.java:52)
>>>> at <redacted calling method in my code>
>>>>
>>>> This is the line where I instantiate IFDSSolver (reacted in the stack trace). You can see it in context later, but I've provided it here for reference:
>>>>
>>>> IFDSSolver<Unit, Pair<Value, Set<DefinitionStmt>>,
>>>> SootMethod, InterproceduralCFG<Unit, SootMethod>> solver =
>>>> new IFDSSolver<Unit, Pair<Value,
>>>> Set<DefinitionStmt>>, SootMethod, InterproceduralCFG<Unit,
>>>> SootMethod>>(problem);
>>>>
>>>> I am able to successfully perform the following earlier in the code:
>>>> * Build a call-graph using SPARK (shown below), and
>>>> * Process active method bodies with BodyTransformer and SceneTransformer in the jtp and wjtp packs, respectively (not shown).
>>>>
>>>> The code leading up to the above error is as follows:
>>>>
>>>> Options.v().setPhaseOption("cg", "safe-newinstance:true");
>>>> Options.v().setPhaseOption("cg.cha","enabled:false");
>>>>
>>>> // Enable SPARK
>>>> Options.v().setPhaseOption("cg.spark","enabled:true");
>>>> Options.v().setPhaseOption("cg.spark","verbose:true");
>>>> Options.v().setPhaseOption("cg.spark","on-fly-cg:true");
>>>>
>>>> Options.v().set_allow_phantom_refs(true);
>>>> Options.v().set_output_format(Options.output_format_class);
>>>>
>>>> Options.v().set_main_class(mainClass);
>>>>
>>>> SootClass c = Scene.v().loadClass(mainClass, SootClass.BODIES);
>>>> c.setApplicationClass();
>>>>
>>>> SootMethod entryPoint = c.getMethodByName("main");
>>>> List<SootMethod> entryPoints = new ArrayList<SootMethod>();
>>>> entryPoints.add(entryPoint);
>>>> Scene.v().setEntryPoints(entryPoints);
>>>>
>>>> Scene.v().loadNecessaryClasses();
>>>>
>>>> // Set output dir
>>>> Options.v().set_output_dir(outputDir);
>>>>
>>>> // Execute Soot
>>>> soot.Main.main();
>>>>
>>>> // Run Heros IFDS Solver...
>>>> JimpleBasedInterproceduralCFG icfg= new JimpleBasedInterproceduralCFG();
>>>> System.out.println("1");
>>>> IFDSTabulationProblem<Unit, Pair<Value,
>>>> Set<DefinitionStmt>>, SootMethod,
>>>> InterproceduralCFG<Unit, SootMethod>> problem = new
>>>> IFDSReachingDefinitions(icfg);
>>>>
>>>> System.out.println("2");
>>>> IFDSSolver<Unit, Pair<Value, Set<DefinitionStmt>>,
>>>> SootMethod, InterproceduralCFG<Unit, SootMethod>> solver =
>>>> new IFDSSolver<Unit, Pair<Value,
>>>> Set<DefinitionStmt>>, SootMethod, InterproceduralCFG<Unit,
>>>> SootMethod>>(problem);
>>>>
>>>> System.out.println("Starting solver");
>>>> solver.solve();
>>>> System.out.println("Done");
>>>>
>>>> Any help is much appreciated!
>>>>
>>>> Best,
>>>> ---Chris
>>>> _______________________________________________
>>>> Soot-list mailing list
>>>> Soot-list at CS.McGill.CA
>>>> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
>>>
>>>
>>
>> _______________________________________________
>> Soot-list mailing list
>> Soot-list at CS.McGill.CA
>> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
>>
>>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
More information about the Soot-list
mailing list