[Soot-list] Generating a CallGraph

Graziella Galea gra.galea at gmail.com
Fri Mar 21 10:48:47 EDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20140321/caddf1ca/attachment-0001.html 


More information about the Soot-list mailing list