soot-oss / soot

Soot - A Java optimization framework
GNU Lesser General Public License v2.1
2.85k stars 706 forks source link

Why SOOT Cannot find the method calls from a dynamic loaded class? #1965

Open FlyTweety opened 1 year ago

FlyTweety commented 1 year ago

I am a beginner in learning soot and I was tormented by this strange problem: I create a instance of a class and I cannot find its methodcalls.

Here is the source code that I want to analyze: `package com.example.hello;

public class TestInputMain { public static void main(String[] args) {

    Calculator calc = new Calculator();  // another class in same package, written by me. 

    int result = calc.add(10, 20); // I CANNOT FIND IT!!!

    System.out.println("The result of adding 10 and 20 is " + result);
}

}`

Here is part of soot codes that I use: `…… //SET UP CALL GRAPH String[] sootArgs = { "-pp", "-process-dir", jarFilePath, //I put them in a jar. The result is same without a jar "-allow-phantom-refs", "-no-bodies-for-excluded", "-whole-program", "-verbose", "-p", "cg.cha", "enabled:true", "-dynamic-dir", jarFilePath, }; Options.v().parse(sootArgs);

    String sootClassPath = jarFilePath;
    Options.v().set_soot_classpath(sootClassPath);

    Scene.v().loadNecessaryClasses();

    PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTransform", new SceneTransformer() {
        @Override
        protected void internalTransform(String phaseName, Map<String, String> options) {
            CallGraph cg = Scene.v().getCallGraph();

…… //PRINT EVERY EDGE IN CALLGRAPH CallGraph callgraph = Scene.v().getCallGraph(); Iterator edgesdebug = callgraph.iterator(); while (edgesdebug.hasNext()) { Edge it = edgesdebug.next(); System.out.println("??????" + it.src() + " =>> " + it.tgt()); }` The situation is, even if I print every edge in callgraph, including all kinds of lib functions, I still cannot find "add".

NiceAsiv commented 5 months ago

me too