[Soot-list] Generating a CallGraph

Marc-Andre Laverdiere-Papineau marc-andre.laverdiere-papineau at polymtl.ca
Fri Mar 21 15:05:47 EDT 2014


Hi Graziella,

Soot doesn't care about the class loader that you use - it uses its own 
class loading logic. You would need to either change that mechanism, or 
dump the classes you get from other sources to the disk and let Soot 
retrieve that.

Also, it is generally recommended to use the Soot main if you're new at 
Soot.

Also, note that entry points need to be static. IIRC, when you are 
working in app mode, you need to have an explicit main method, but I'm 
not 100% sure about that.

BTW, you can join us on IRC at #soot on Freenode if that's your thing.

Le 2014-03-21 10:48, Graziella Galea a écrit :
>
> I am currently working on a project whereby I need to generate a call 
> graph for Java code analysis using SOOT. Unfortunately, for each class 
> in the project I am analyzing, soot is returning a warning that the 
> class in a phantom reference. Now, if I am not mistaken, a phantom 
> reference is a class which I cannot provide but I am actually 
> providing it. I first started thinking that the problem was with the 
> Soot's classpath but I think it is correct. The path String variable 
> used to set the classpath (as shown in the code snippet below) 
> specifies the bin folder of the project I'm analysing.
>
> Could anyone help me? It's been over a week and cannot seem to get it 
> right.
>
> Code used for setup:
>
>
> |private  CallGraph  setUp(ArrayList<String>  paths,  String  testSuite)  throws  Exception{
>      Options.v().set_whole_program(true);
>      Options.v().set_allow_phantom_refs(true);
>      Options.v().set_app(true);
>      Options.v().set_no_bodies_for_excluded(true);
>      //set each method in the source folder as an entry point
>      Parser  p=  new  Parser();
>      List<SootMethod>  entryPoints=  new  ArrayList<SootMethod>();
>      //the arraylist paths contains the path to the test suite and the path to the source folder
>      for(String  path:  paths){
>          if(path!=  null){//if it is null then the user chose to identify the methods only
>              //create a classLoader for this path
>              File  file=  new  File(path);  
>              ClassLoader  classLoader=  new  URLClassLoader(new  URL[]{file.toURI().toURL()},  parent);
>              MultiClassLoader  mcl=  new  MultiClassLoader();
>              mcl.addClassLoader(classLoader);
>              ArrayList<File>  allFiles=  p.getSourceFiles(path,  false);
>              Options.v().set_process_dir(Arrays.asList(path+"\\"));
>              Options.v().set_soot_classpath("C:\\Program Files\\Java\\jre7\\lib\\rt.jar;"  +
>                      path+"\\;C:\\Program Files\\Java\\jre7\\lib\\jce.jar");
>                  for(File  f:  allFiles){
>                      //remove the path and leave package path only
>                      String  name=  f.getAbsolutePath().replace(path+"\\",  "");
>                      name=  name.replace("\\",  ".");
>                      name=  name.replace(".class",  "");
>                      //saves test files so as to be able to distinguish between normal methods and test cases
>                          if(path.equals(testSuite)){
>                              testFiles.add(name);
>                          }
>                          //load the class
>                         Class<?>  cls=  mcl.getClassLoader(0).loadClass(name);
>                         SootClass  sootClass=  Scene.v().loadClassAndSupport(cls.getName());
>                         sootClass.setApplicationClass();
>                                  //set all of the methods in this class as entrypoints since there is no main method available
>                          for(SootMethod  m:  sootClass.getMethods()){
>                                if  (!m.isAbstract())  {
>                               System.out.println("entrypoint"+m);
>                               entryPoints.add(m);     
>                                }
>                             }
>              }
>              mcl.removeClassLoader(classLoader);  
>      }
> }
>      Scene.v().addBasicClass("java.lang.ThreadGroup",SootClass.SIGNATURES);
>      Scene.v().setEntryPoints(entryPoints);
>      PackManager.v().runPacks();
>      return  Scene.v().getCallGraph();
>     }|
> -- 
> Graziella Galea
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list

-- 
Marc-André Laverdière-Papineau
Doctorant - PhD Candidate

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20140321/721030ed/attachment-0001.html 


More information about the Soot-list mailing list