[Soot-list] Error the CallGraph: Edges not present

Dhriti Khanna dhritik at iiitd.ac.in
Sun Dec 15 05:42:04 EST 2019


Hello,
For method A, I want to find all the methods that A might invoke in a Java
class. I am implementing this as follows:

  List<String> argsList = new ArrayList<String>(Arrays.asList(_cut));
  argsList.addAll(Arrays.asList(new String[]{
          "-w",
          "-main-class",
          _cut
  }));

  Options.v().set_no_bodies_for_excluded(true);
  Options.v().set_output_format(Options.output_format_jimple);

Options.v().set_output_dir("/home/dhriti/Dropbox/new-workspace/EscapeAnalysis/sootOutput");
  Options.v().setPhaseOption("cg.spark", "on");
  Options.v().set_whole_program(true);
  Options.v().set_prepend_classpath(true);
  Options.v().set_allow_phantom_refs(true);
  Scene.v().addBasicClass("sun.misc.ClassFileTransformer",
SootClass.HIERARCHY);
  Scene.v().addBasicClass("java.io.ObjectStreamClass$MemberSignature",
SootClass.HIERARCHY);
  SootClass sootClass = Scene.v().forceResolve(_cut, SootClass.BODIES);
  sootClass.setApplicationClass();
  Scene.v().loadNecessaryClasses();
  PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new
SceneTransformer() {

    @Override
    protected void internalTransform(String arg0, Map arg1) {
    Iterator<SootMethod> sootMethodsIt = sootClass.getMethods().iterator();
    while(sootMethodsIt.hasNext()) {

        SootMethod caller = sootMethodsIt.next();
        if(caller.isPublic() &&
caller.getDeclaringClass().getName().equals(_cut)) {
            List<SootMethod> entryPoints = new ArrayList<SootMethod>();
            entryPoints.add(caller);
            Scene.v().setEntryPoints(entryPoints);

            CallGraph cg = Scene.v().getCallGraph();
            Iterator<Edge> edges = cg.edgesOutOf(caller);
            ArrayList<SootMethod> targets = new ArrayList<SootMethod>();
            while(edges.hasNext()) {
                Edge edge = edges.next();
                SootMethod target = edge.getTgt().method();
                if(target.getDeclaringClass().getName().equals(_cut)) {
                    targets.add(target);
                }
            }
            targetMethods_For_Method.put(caller, targets); // List of
targets can be empty
        }
    }
    }
  }));

String[] argsArray = (String[]) argsList.toArray(new
String[argsList.size()]);
soot.Main.main(argsArray);

However, I am not getting the required output unless I call anyone method
of the class from the main method. If I do this, then the output is fine.
Otherwise, if I leave the main method empty, the target list for each
method is empty. Why is this happening even when I set the entry point to
be a non-main method (as highlighted in the color yellow above)?

Note: This is an issue with Soot-2.5.0

-- 
Regards
Dhriti Khanna
PhD Scholar
IIIT Delhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20191215/6a57878b/attachment.html>


More information about the Soot-list mailing list