Repository: soot-oss/soot

Issue #1043: Problem importing a method after export dex
Created: 2018-10-16T17:42:21Z
Hello again,
I am exporting as dex all the dependencies class found.
When I try to import them back and I try to get the active bodies from the SootMethods of these classes, Soot throws exception :
Exception in thread "main" java.lang.RuntimeException: no active body present for method <rid.hth.XZU.z.a: rid.hth.XZU.z.b a(int)>
	at soot.SootMethod.getActiveBody(SootMethod.java:334)
	at Instrumenter.main(Instrumenter.java:46)  

The problem is that if I check if the same classes before the export has Active body, soot tells me true, and unpacking the .dex file in which all my classes are stored , I can clearly see that they have an active body.
How can I workaround this issue?

Duplicate issue #1013: java.lang.RuntimeException: No method source set for method 
Created: 2018-08-30T06:41:48Z
Hi,  I am trying to run Pack twice, at the second run java.lang.RuntimeException: No method source set for method  exception occured, How can i fix this?
I am also trying add two packs first and invoke soot.Main.main, but now, two packs are running in parallel manner, but i want to run two packs one after one, how can i do this?

Closing comment (2019-10-10T16:56:55Z): I can reproduce the issue in a similar situation. And it is also the same as #1043
In my case, I'm instrumenting apks and then calling PackManager.v().writeOutput(). After this, when I try to load the classes again I get the exception.
Exception in thread "main" java.lang.RuntimeException: No method source set for method <com.rhul.simpledataitem.MainActivity: void <init>()>
	at soot.SootMethod.retrieveActiveBody(SootMethod.java:398).

It is worth to mention the program generates the instrumented apk and write correctly.
I'm using soot  3.2.0. This is my configuration.
		Options.v().set_src_prec(Options.src_prec_apk);
		Options.v().set_output_format(Options.output_format_dex);
		Options.v().set_whole_program(true);
		Options.v().set_force_overwrite(true);
		Options.v().set_allow_phantom_refs(true);
		Options.v().set_prepend_classpath(true);
		Options.v().set_android_jars(androidPlatforms);
		Options.v().set_process_dir(Collections.singletonList(apkPath));
		Options.v().set_process_multiple_dex(true);
		Options.v().set_validate(true);
		Scene.v().loadNecessaryClasses();

This is one apk that I'm using  https://github.com/mtileria/Android-testcases/blob/master/apk/SimpleDataItem/mobile-debug.apk but the same problem occurs using DirectLeak1.apk from DroidBench and a dummy instrumentation like adding one AssignStmt, which I put below.
The dummy instrumentation is

	public void internalTransform(String phaseName, Map<String, String> options) {
		SootClass sClass = Scene.v().getSootClass("xx.xx.MainActivity");
		Body body = sClass.getMethodByName("onCreate").getActiveBody();
		Local arg = Jimple.v().newLocal("l1", RefType.v("java.lang.String"));
		body.getLocals().add(arg);
		AssignStmt astm = Jimple.v().newAssignStmt(arg, StringConstant.v("crash!"));
		Unit first = body.getUnits().getFirst();
		body.getUnits().insertBefore(astm, first);
	}

And this is the Main.
			PackManager.v().getPack("wjtp")
					.add(new Transform("wjtp.MyInstrumentation", new DummySceneTransformer(classesToInstrument)));
			PackManager.v().getPack("wjtp").apply(); 
			printClassByName("xx.x.MainActivity");  --> No Error
			PackManager.v().writeOutput();
			printClassByName("xx.x.MainActivity"); --> Error

Note that the first time that I call printClassByName("xx.x.MainActivity"), the program iterates over all the methods and output the class without any problem, but when I call the same function after call PackManager.v().writeOutput(), I get the No method source set for method [...] 	at soot.SootMethod.retrieveActiveBody(SootMethod.java:398).
I can see that the body "disappear" while Debugging after writing the output apk.