soot icon indicating copy to clipboard operation
soot copied to clipboard

java.lang.RuntimeException when ...

Open pikuit opened this issue 4 years ago • 6 comments

Steps to reproduce: 1.) ..Run the below code with jdk 8 in eclipse 2019-12 with soot-4.2.1-jar-with-dependencies.jar

Files used to reproduce: import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map;

import soot.MethodOrMethodContext; import soot.PackManager; import soot.Scene; import soot.SceneTransformer; import soot.SootClass; import soot.SootMethod; import soot.Transform; import soot.jimple.toolkits.callgraph.CHATransformer; import soot.jimple.toolkits.callgraph.CallGraph; import soot.jimple.toolkits.callgraph.Targets; public class MySootTest {

public static void main(String args[]) {
	List<String> argsList = new ArrayList<String>(Arrays.asList(args));
	   argsList.addAll(Arrays.asList(new String[]{
			   "-w",
			   "-main-class",
			   "test.CallGraphs",//main-class
			   "test.CallGraphs",//argument classes
			   "test.A"			//
	   }));
	

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

		@Override
		protected void internalTransform(String phaseName, Map<String, String> options) {
		       CHATransformer.v().transform();
                       SootClass a = Scene.v().getSootClass("testers.A");

		       SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
		       CallGraph cg = Scene.v().getCallGraph();

		       Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
		       while (targets.hasNext()) {
		           SootMethod tgt = (SootMethod)targets.next();
		           System.out.println(src + " may call " + tgt);
		       }
		}

					
		   
	   }));

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

}

Soot version:

soot-4.2.1-jar-with-dependencies.jar from https://github.com/soot-oss/soot#how-do-i-obtain-the-nightly-builds

Command line:

-cp lib\soot-4.2.1-jar-with-dependencies.jar;. soot.Main -w -main-class test.CallGraphs test.CallGraphs test.A

Max Memory:

1797MB

Stack trace:

java.lang.RuntimeException: None of the basic classes could be loaded! Check your Soot class path!
	at soot.Scene.loadBasicClasses(Scene.java:1755)
	at soot.Scene.loadNecessaryClasses(Scene.java:1845)
	at soot.Main.run(Main.java:241)
	at soot.Main.main(Main.java:141)
	at MySootTest.main(MySootTest.java:54)

pikuit avatar Aug 06 '20 16:08 pikuit

Okay, the error is telling us that soot did not find the rt.jar . In your command line options can you please omit the cmd-parameter cp and just use the cmd-paramter -process-dir.

Given your command line, soot uses the classpath -cp lib\soot-4.2.1-jar-with-dependencies.jar;. and tries to find rt.jar in these directories. Obviously, soot is unable to locate the rt.jar, and thus fails to load basic classes, e.g., String, Object, etc.

anddann avatar Aug 18 '20 15:08 anddann

Remediated the soot classpath runtime exception by setting the below options to execute the soot and run callgraph.

Options.v().set_verbose(false); Options.v().set_keep_line_number(true); Options.v().set_src_prec(Options.src_prec_class); //Options.v().set_soot_classpath(classpath); Options.v().set_prepend_classpath(true); Options.v().set_soot_classpath(classpath);

But facing issue with callgraph as Soot is unable to run with main method in spring mvc code . kindly assist how to do a callgraph in spring-mvc

pikuit avatar Aug 19 '20 19:08 pikuit

Super, that the RuntimeException is fixed! Can you give more details concerning the issue? Does not soot find the main method?

anddann avatar Aug 20 '20 09:08 anddann

Created a sample Spring mvc HelloController below class with added provided jars: spring-web-3.2.18.RELEASE.jar, org.springframework.web-3.2.2.RELEASE.jar, org.springframework.web.servlet-3.2.2.RELEASE.jar, org.springframework.expression-3.2.1.RELEASE.jar, org.springframework.core-3.2.2.RELEASE.jar, org.springframework.context-3.2.2.RELEASE.jar, org.springframework.beans-3.2.2.RELEASE.jar, org.springframework.asm-3.1.4.RELEASE.jar, commons-logging-1.2.jar

HelloController.java

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.ui.ModelMap;

@Controller @RequestMapping("/hello") public class HelloController { @RequestMapping(method = RequestMethod.GET) public String printHello(ModelMap model) { model.addAttribute("message", "Hello Spring MVC Framework!"); return "hello"; } }

SootMain CLass

Options.v().set_verbose(false); Options.v().set_keep_line_number(true); Options.v().set_src_prec(Options.src_prec_class); //Options.v().set_soot_classpath(classpath); Options.v().set_prepend_classpath(true); Options.v().set_soot_classpath();

        String path=<libary path>;
        File folder = new File(path);
        File[] files = folder.listFiles();
        List<String> flpath = new ArrayList<String>();
        for(File fl:files) {
        	flpath.add(fl.toString());
        }
        Options.v().set_process_dir(flpath);
        Options.v().set_allow_phantom_refs(true);

        PhaseOptions.v().setPhaseOption("bb", "off");
        PhaseOptions.v().setPhaseOption("tag.ln", "on");
        PhaseOptions.v().setPhaseOption("jj.a", "on");
        PhaseOptions.v().setPhaseOption("jj.ule", "on");

        Options.v().set_whole_program(true);
	List<String> argsList = new ArrayList<String>(Arrays.asList(args));
	   argsList.addAll(Arrays.asList(new String[]{
			   "-w",
			  // "-main-class"
	   }));
	
	   Map<String , String> fileMAp = new HashMap<String , String>();
	   fileMAp.put("test.HelloController","printHello");
	  		   
	   SootClass a = Scene.v().loadClassAndSupport("test.UserMain");
	   Scene.v().setMainClass(a);

Exception: Soot started on Sat Aug 22 21:28:17 IST 2020 java.lang.RuntimeException: Failed to convert <org.springframework.asm.commons.AnalyzerAdapter: void visitFrame(int,int,java.lang.Object[],int,java.lang.Object[])> at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:2163) at soot.SootMethod.retrieveActiveBody(SootMethod.java:402) at soot.jimple.toolkits.annotation.LineNumberAdder.internalTransform(LineNumberAdder.java:64) at soot.PackManager.runPacksNormally(PackManager.java:491) at soot.PackManager.runPacks(PackManager.java:419) at soot.Main.run(Main.java:269) at soot.Main.main(Main.java:141) at MySootTest.main(MySootTest.java:139) Caused by: java.lang.RuntimeException: Trying to create virtual invoke expression for interface type (org.springframework.asm.MethodVisitor in file uknown). Use JInterfaceInvokeExpr instead! at soot.jimple.internal.JVirtualInvokeExpr.(JVirtualInvokeExpr.java:49) at soot.jimple.Jimple.newVirtualInvokeExpr(Jimple.java:469) at soot.asm.AsmMethodSource.convertMethodInsn(AsmMethodSource.java:1396) at soot.asm.AsmMethodSource.convert(AsmMethodSource.java:1907) at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:2161) ... 7 more

Callgraph is not working and soot is throwing above exception

pikuit avatar Aug 22 '20 16:08 pikuit

Any update on how to achieve callgraph on spring-mvc application

pikuit avatar Sep 05 '20 16:09 pikuit

@pikuit In the options you set to resolve the runtime exception, what did you set as classpath?

harshita19244 avatar Sep 13 '21 18:09 harshita19244