soot icon indicating copy to clipboard operation
soot copied to clipboard

Custom instrumentation pass not being run on methods that are part of the analyzed library

Open prashast opened this issue 3 years ago • 0 comments

Describe the bug Soot is not performing the specified intra-procedural pass using jtp over classes that are part of the analyzed jar which is the rome library and simply ignoring them. I believe the reason this is happening is because the analyzed classes which are in the rome-1.0.jar are part of the standard Java API (com.sun.syndication.*). Is there a way to force Soot to run the instrumentation pass over these classes?

BaseAnalysis.java (The soot environment setup)

public class BaseAnalysis {

    public static void main(String[] args) {

        // Get the jarfile and source dir
        String jarFile = args[0];
        String sourceDirectory = Paths.get(jarFile).getParent().toString();

        System.out.println(String.format("Jar file:%s\nProcess dir:%s", jarFile, sourceDirectory));
        G.reset();
        Options.v().set_prepend_classpath(true); //-pp
        Options.v().set_whole_program(true); //-w
        Options.v().set_allow_phantom_refs(true);
        List<String> processdirs = new ArrayList<>();
        PackManager.v().getPack("jtp").add(new Transform("jtp.MethodPass", MethodPass.v()));
        processdirs.add(jarFile);
        Options.v().set_process_dir(processdirs);
        Options.v().set_soot_classpath(sourceDirectory);
        Options.v().set_output_jar(true); // Creates the output jar file with instrumented code
        Scene.v().loadNecessaryClasses();
        PackManager.v().runPacks();
        System.out.println("Writing processed jar file to sootOutput");
        PackManager.v().writeOutput();
    }
}

MethodPass.java (Simple custom pass that's just validating method bodies)

public class MethodPass extends BodyTransformer {

    private static MethodPass instance = new MethodPass();
    private MethodPass() {}

    public static MethodPass v() { return instance; }

	protected void internalTransform(Body body, String phase, Map options) {
            // body's method
            SootMethod method = body.getMethod();
            System.out.println("Validating body of:" + method.toString());
            body.validate();
	}

}

Input file debug_rome.tar.gz

To reproduce Steps to reproduce the behavior: The attached tarball contains a repro package to debug the issue in Rome where the classes and methods corresponding to the analyzed jar file are not being iterated over during the specified intra-procedural analysis. This in turn causes the output jar file to be empty.

  • Untar the provided repro package.

  • To run the test for the Rome library run the below set of commands

    • Perform the analysis pass which for the sake of simplicity is just iterating over the classes in the jar file and validating the bodies of the methods.

      cd src/static
      gradle run --args="$PWD/../../libs/rome/rome-1.0.jar"
      
    • If there were methods analyzed by the custom pass there would be messages of the form "Validating body of " to be printed but instead there is no such output

    • You can also see that the output jar is empty by checking the file generated ./sootOutput/out.jar

  • To see the expected output, we provided a synthetic jar file as well containing some sample methods.

    • Perform the analysis pass which for the sake of simplicity is just iterating over the classes in the jar file and validating the bodies of the methods.

      gradle run --args="$PWD/../../libs/FizzBuzz/FizzBuzz.jar"
      
    • If there were methods analyzed by the custom pass there would be messages of the form "Validating body of " to be printed which indeed there are.

    • You can see that the output jar file is non-empty as well as seen in ./sootOutput/out.jar

Expected behavior For the rome library I would expect the classes belong to this library to be correctly processed by the specified intra-procedural analysis pass as provided using jtp.

prashast avatar Oct 21 '22 21:10 prashast