[Soot-list] Can I ask for a code snippet of creating call graph for a library (no main class)?
Z
zell08v at orange.fr
Fri Jun 29 04:23:10 EDT 2012
Hello, I don't understand. Did you mean you will need a control flow graph
rather than AST to do your transformation?
Zell.
On Fri, Jun 29, 2012 at 7:26 AM, Yi Lin <qinsoon at gmail.com> wrote:
> Hi,
>
> I finally solved this. I will attach my code at the end (it may help
> others perhaps, and any improvements are welcome).
>
> But I now have another problem with Soot. Basically I need AST and call
> graph for my work. I got call graph now, but how can I get AST from
> soot? I see that Dava could decompile bytecode and construct AST. But I
> assume soot should maintian ASTs when it do transformation. What is a
> straightforward way to get AST in soot?
>
> Thank you very much.
>
> Regards,
> Yi
>
> -------------------
> code for generating call graph for library (no main class):
>
> build call graph:
> // PackManager manages the packs containing the various phases and
> their options
> PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans",
> new SceneTransformer() {
> @Override
> protected void internalTransform(String phaseName, Map options) {
> CHATransformer.v().transform();
> }
> }));
>
> Options.v().set_whole_program(true);
> Options.v().set_process_dir(Arrays.asList(libDir)); //library dir
> Options.v().set_soot_classpath("../rt.jar:"+libDir+":../jce.jar:.");
> //library dir along with rt.jar/jce.jar from JRE/JDK
>
> Scene.v().setEntryPoints(getAllMethods());
> Scene.v().loadNecessaryClasses();
> PackManager.v().getPack("wjtp").apply();
>
> get all methods (as entrypoints):
>
> public List<SootMethod> getAllMethods() {
> ArrayList<SootMethod> entrypoints = new ArrayList<SootMethod>();
> for (String klassName : allClasses) {
> // klassName such as org.abc.MyClass
> Scene.v().forceResolve(klassName, SootClass.SIGNATURES);
> SootClass klass = Scene.v().getSootClass(klassName);
>
> // adding all non-abstract method as entrypoint
> for (SootMethod m : klass.getMethods()) {
> if (!m.isAbstract()) {
> entrypoints.add(m);
> }
> }
> }
> return entrypoints;
> }
>
> use call graph:
>
> SootClass klass = Scene.v().getSootClass(someClassYouAreInterested);
> SootMethod method = klass.getMethodByName(someMethodYouAreInterested);
> CallGraph cg = Scene.v().getCallGraph();
> Iterator<MethodOrMethodContext> sources = new
> Sources(cg.edgesInto(focus));
> while (sources.hasNext()) {
> SootMethod src = (SootMethod)sources.next();
> System.out.println(method + " is called by " + src);
> }
>
> On 26/06/12 14:17 , Z wrote:
> > It might be more efficient that you learn them like -w, entrypoints
> > etc... one by one. Most of them can be found in the survivor's guide.
> >
> > If you don't know whether to use such such options, try them!
> >
> > Cheers,
> > Zell.
> >
> >> long list of questions, like whether to use whole program mode '-w',
> >> what should be set as 'entrypoints', whether to use
> >> CHATransformer.v().transform() or
> >> PhaseOptions.v().setPhaseOption("cg.cha", "enabled:true") then
> >> runPacks(), what is the timing to do that, etc. A code snippet would
> >> answer all those annoying questions for me...
> >>
> >> Thank you very much.
> >>
> >> Regards,
> >> Yi
> >> _______________________________________________
> >> Soot-list mailing list
> >> Soot-list at sable.mcgill.ca
> >> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list at sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120629/a421edb4/attachment.html
More information about the Soot-list
mailing list