soot icon indicating copy to clipboard operation
soot copied to clipboard

Run code with custom entry points

Open harshita19244 opened this issue 3 years ago • 0 comments

Please examine each of the following points so that we can help you as soon and best as possible.

I want to use soot with custom entry points. I am analysing the guava library and want to do so for specific guava classes. I have already tried using the implementation for custom entry points as provided in the documentation. But my code just runs for very long and no call graph is being generated, Can some guidance be provided? @anddann

import soot.*;
import soot.jimple.toolkits.callgraph.CHATransformer;
import soot.jimple.toolkits.callgraph.CallGraph;
import soot.jimple.toolkits.callgraph.Targets;
import soot.options.Options;
import java.util.*;

public class CallGraphExample
{
    static HashMap<SootMethod,SootMethod> linkmap = new HashMap<>();
    static ArrayList<SootMethod> targetmethods = new ArrayList<>();

    public static void main(String[] args) {
        List<String> argsList = new ArrayList<>(Arrays.asList(args));
        Options.v().set_verbose(false);
        Options.v().set_keep_line_number(true);
        String classesDir = "C:\\Users\\USer\\sootrun\\out\\production\\sootrun";
        String depdir = "C:\\Users\\USer\\sootrun\\src\\testers";
        String newdir = "C:\\Users\\USer\\sootrun\\src";
        System.out.println("Classpath: " + Scene.v().getSootClassPath());
        Scene.v().extendSootClassPath(classesDir);
        Scene.v().extendSootClassPath(depdir);
        Scene.v().extendSootClassPath(newdir);
        System.out.println("Classpath: " + Scene.v().getSootClassPath());

        argsList.addAll(Arrays.asList("-w",
//                "-main-class",
//                "testers.CallGraphs",
//                "testers.CallGraphs",
                "com.google.common.base.Splitter"

        ));
         PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {

            @Override
            protected void internalTransform(String phaseName, Map options) {
                CHATransformer.v().transform();
                SootClass c = Scene.v().forceResolve("com.google.common.base.Splitter", SootClass.BODIES);
                c.setApplicationClass();
                Scene.v().loadNecessaryClasses();
                SootMethod src = c.getMethodByName("onPattern");
                List entryPoints = new ArrayList();
                entryPoints.add(src);
                Scene.v().setEntryPoints(entryPoints);
                PackManager.v().runPacks();
//                SootClass c = Scene.v().getSootClass("testers.CallGraphs");
//                SootMethod src = c.getMethodByName("main");
                CallGraph cg = Scene.v().getCallGraph();
                recurse(cg,src,2,0);
                for (SootMethod method : targetmethods) {
                    System.out.println(method);
                }

                for (Map.Entry<SootMethod, SootMethod> pair : linkmap.entrySet()) {
                    System.out.println(pair.getKey().getName() + " -> "+ pair.getValue().getName());
                }


//                for (String s : arr) {
//                    SootMethod targets = a.getMethodByName(s);
//                    recurseback(cg, targets, 2, 0);
//                }
//
            }

        }));
        args = argsList.toArray(new String[0]);
        soot.Main.main(args);
    }

harshita19244 avatar Oct 07 '21 07:10 harshita19244