javastatic-analysiscode-analysissootinternal-representation

Soot - Map from java class to jimple


With the following code I can get the jimple representation of a java .class file:

        soot.Main.main(args);
        SootClass mainClass = Scene.v().getMainClass();
        String methodSignature = "void main(java.lang.String[])";
        SootMethod mainMethod = mainClass.getMethod(methodSignature);
        Body jimpleBody = mainMethod.retrieveActiveBody();

However, I need to know the map from .class to jimple. In detail, For a certain line of code in the .class file, I want to know its corresponding jimple representation. Since one line of code can be converted into multiple jimple codes, this map can be one-to-many. Does there exist any API or method that can solve this problem?


Solution

  • I find the solution here. In detail, for a Unit you can use

    Unit unit = ...
    int sourceID = unit.getJavaSourceStartLineNumber();
    // do something smart here ...