[Soot-list] Building a call graph for a class that has no main

John Dee jdsoot at hotmail.com
Fri Jul 22 12:05:00 EDT 2011


Hi Eric,
I have spent the past couple of hours looking over the information in the archives and I canfind 2 possible solutions.
The first solution is stated here - http://www.sable.mcgill.ca/pipermail/soot-list/2011-January/003434.htmlWhich says that before calling Soot's main method - you can call
Scene.v().setEntryPoints(new MyEntryPoints())
Now, I see an issue with this. To subclass 'EntryPoints', you must provide a call to super with anargument of type Singletons.Global. I'm not sure what that is or how to pass it into the 'MyEntryPoints' constructor.
The second approach I found was here - http://www.sable.mcgill.ca/pipermail/soot-list/2005-August/000326.htmlThis says to call 'EntryPoints.v().application' to get your application entry points. You then alter this list and call'Scene.v().setEntryPoints(...)' with your altered list. I tried this and it doesn't work either. I get an error stating:
Exception in thread "main" java.lang.RuntimeException: There is no main class set!
I have no main method in my class and after trying several approaches, I can't find a work around.The code I have is:
public class CallGraphExample{		public static void main(String[] args) {		// create a list from args	   List<String> argsList = new ArrayList<String>(Arrays.asList(args));	   	   // add on the following arguments	   argsList.addAll(Arrays.asList(new String[]{			   "-w",			   "testers.CallGraphs"	   }));	   	   // 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();		       		       // return the soot class with the given name               SootClass a = Scene.v().getSootClass("testers.CallGraphs");                              List<SootMethod> entryMethods = new ArrayList<SootMethod>();               SootMethod method = a.getMethodByName("doStuff");               entryMethods.add(method);               entryMethods.addAll(EntryPoints.v().application());               Scene.v().setEntryPoints(entryMethods);               for (SootMethod sMethod : Scene.v().getEntryPoints()) {            	   if (sMethod.getName().equals("main")) {            		   Scene.v().getEntryPoints().remove(sMethod);            		   break;            	   }               }
		       SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");		       CallGraph cg = Scene.v().getCallGraph();
		       Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));		       while (targets.hasNext()) {		           SootMethod tgt = (SootMethod)targets.next();		           System.out.println(src + " may call " + tgt);		       }		}	   }));
           args = argsList.toArray(new String[0]);           soot.Main.main(args);  // **** EXCEPTION THROWN HERE	}}
My test class looks like:
package testers;
public class CallGraphs{	public static void doStuff() {		StringBuilder b = new StringBuilder("Blah");		b.append(" Blah");		new A().foo();	}}
class A{	public void foo() {		bar();	}		public void bar() {	}}
I have also tried updating the EntryPoints list before the call to soot.Main.main(args) and this doesn't work either.When I do this, I get an error stating - 
Exception in thread "main" java.lang.RuntimeException: 
Aborting: can't find classfile testers.CallGraphs
	at soot.Scene.getSootClass(Scene.java:484)
	at dk.brics.soot.callgraphs.CallGraphExample.main(CallGraphExample.java:56)
I'm using Eclipse 3.6 with the latest version of Soot. I'm really stuck and don't know what else to try. if anyone couldhelp me out I would really appreciate it. As I mentioned, I have examined the archives but can't find a definitive answer.
Thanks & regardsJD
> From: bodden at st.informatik.tu-darmstadt.de
> Date: Fri, 22 Jul 2011 13:28:16 +0200
> Subject: Re: [Soot-list] Building a call graph for a class that has no main
> To: jdsoot at hotmail.com
> CC: soot-list at sable.mcgill.ca
> 
> Hi John.
> 
> This has been answered many times on the list. Please search the
> archives for EntryPoints.
> 
> Eric
> 
> On 21 July 2011 23:03, John Dee <jdsoot at hotmail.com> wrote:
> > Hi there.
> > I refer to the example of building a class graph from the 'soot survivors
> > guide':
> > public static void main(String[] args) {
> >   List<String> argsList = new ArrayList<String>(Arrays.asList(args));
> >   argsList.addAll(Arrays.asList(new String[]{
> >   "-w",
> >   "-main-class",
> >   "testers.CallGraphs",//main-class
> >   "testers.CallGraphs",//argument classes
> >   "testers.A" //
> >   }));
> >   PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new
> > SceneTransformer() {
> > @Override
> > protected void internalTransform(String phaseName, Map options) {
> >       CHATransformer.v().transform();
> >                        SootClass a = Scene.v().getSootClass("testers.A");
> >       SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
> >       CallGraph cg = Scene.v().getCallGraph();
> >       Iterator<MethodOrMethodContext> targets = new
> > Targets(cg.edgesOutOf(src));
> >       while (targets.hasNext()) {
> >           SootMethod tgt = (SootMethod)targets.next();
> >           System.out.println(src + " may call " + tgt);
> >       }
> > }
> >   }));
> >            args = argsList.toArray(new String[0]);
> >            soot.Main.main(args);
> > }
> > The above example works fine, except that class 'CallGraphs' contains a main
> > method. However, the class that I want to analyse does
> > not contain a main method. So, I'm wondering how I can set the method entry
> > point?
> > Thanks & Regards,
> > JD
> >
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list at sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> >
> 
> 
> 
> -- 
> Dr. Eric Bodden, http://bodden.de/
> Principal Investigator in Secure Services at CASED
> Coordinator of the CASED Advisory Board of Study Affairs
> PostDoc at Software Technology Group, Technische Universität Darmstadt
> Tel: +49 6151 16-5478    Fax: +49 6151 16-5410
> Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20110722/eb432cab/attachment-0001.html 


More information about the Soot-list mailing list