[Soot-list] JNewExpr and JSpecialInvokeExpr pairs

Bodden, Eric eric.bodden at sit.fraunhofer.de
Mon Feb 2 17:08:02 EST 2015


Hi Nour.

Can you please open a bug report for this on Github so that we can keep track of this? We will look into this as soon as we can but we have limited time at the moment. Any additional input you could give us about the probably causes of this would help a lot.

Thanks,
Eric

> On 02.02.2015, at 15:22, Nouraldin I. Jaber <njaber at purdue.edu> wrote:
> 
> Hi Eric,
> 
> So I concluded that the "importBodyContentsFrom" works perfectly fine. and it has all the information needed stored. I also did output .class files and they run fine.
> 
> the problem was with the soot.Printer PrintTo function. as it ,for some reason, not only produce wrong results but also make the .jimple files generated in sootOutput folder also go wrong.
> 
> here is my code for testing this:
> 
> public class MySootMainTwo {
> 
> 	static {
> 		soot.options.Options.v().set_full_resolver(true);
> 		soot.options.Options.v().set_keep_line_number(true);
> 		soot.options.Options.v().set_whole_program(true);
> 		soot.options.Options.v().setPhaseOption("cg", "verbose:true");
> 	}
> 
> 	public static void main(String[] args) {
> 
> 		SootClass mainClass = Scene.v().loadClassAndSupport("TestConstructorCalls");
> 		Scene.v().loadClassAndSupport("MyList").setApplicationClass();
> 
> 		mainClass.setApplicationClass();
> 		Scene.v().setMainClass(mainClass);
> 
> 		PackManager.v().getPack("wjtp").add(new Transform("wjtp.myclassrans", ClassTransformer2.instance2()));
> 
> 		soot.Main.main(args);
> 	}
> 
> }
> 
> class ClassTransformer2 extends SceneTransformer {
> 
> 	@Override
> 	protected void internalTransform(String phaseName, Map options) {
> 
> 		SootClass c = Scene.v().getSootClass("TestConstructorCalls");
> 		//writeSootClassAsJimpleFile(c, c.getName() + "TestOne"); // this line (*)
> 
> 	}
> 
> 	static final ClassTransformer2 inst = new ClassTransformer2();
> 
> 	public static ClassTransformer2 instance2() {
> 		return inst;
> 	}
> 
> 	private void writeSootClassAsJimpleFile(SootClass sootClass, String name) {
> 		String fileName = name + ".jimple";
> 		FileOutputStream streamOut = null;
> 		PrintWriter writerOut = null;
> 
> 		try {
> 			streamOut = new FileOutputStream(fileName);
> 		} catch (FileNotFoundException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 		writerOut = new PrintWriter(new EscapedWriter(new OutputStreamWriter(streamOut)));
> 
> 		soot.Printer printer = soot.Printer.v();
> 		printer.setOption(Integer.MAX_VALUE);
> 		PrintWriter writer = new java.io.PrintWriter(writerOut);
> 		printer.printTo(sootClass, writer);
> 		writer.close();
> 	}
> 
> }
> 
> 
> 
> 
> and the output of this code "with line (*) commented" taken from the generated Jimple file in the soot output looks like this:
> 
>   void <init>(java.lang.String)
>   {
>       TestConstructorCalls r0;
>       java.lang.String r1;
> 
>       r0 := @this: TestConstructorCalls;
>       r1 := @parameter0: java.lang.String;
>       specialinvoke r0.<SuperForTestConstructorCalls: void <init>(java.lang.String)>("");
>       return;
>   }
> 
> but the same function only removing the comment looks like this:
> 
>   void <init>(java.lang.String)
>   {
>       TestConstructorCalls r0;
>       java.lang.String r1;
> 
>       r0 := @this;
>       r1 := @parameter0;
>       specialinvoke r0.<init>("");
>       return;
>   }
> 
> note that both outputs are from the sootOutput folder, meaning that this is NOT the file I output from the printer, in other words, calling this printer did somehow affect the jimple files generated automatically.
> 
> 
> also ALL other jimple output files "even those not passed to this function" are also wrong.
> 
> 
> the code for printing is taken from: https://github.com/Sable/soot/wiki/Creating-a-class-from-scratch
> 
> 
> I hope this is helpful.
> 
> Kind Regards,
> 
> Nour
> 
> 
> ----- Original Message -----
> From: "Eric Bodden" <eric.bodden at sit.fraunhofer.de>
> To: "Nouraldin I. Jaber" <njaber at purdue.edu>
> Sent: Monday, February 2, 2015 8:00:35 AM
> Subject: Re: [Soot-list] JNewExpr and JSpecialInvokeExpr pairs
> 
> Hi again.
> 
>> 
>> but since only the assignments are allowed I could even use simpler logic tracing down and comparing locals until i hit the invoke stmt. and "by experiment" I concluded there is no NewExpr without a call to the constructor.
> 
> Right that would be invalid Jimple code. There must be a init-call before the method returns.
> 
>> And since I'm using "importBodyContentsFrom" i noticed that ,for some reason, even if only cloned the body of a function and printed it, some information are missing, for example cloning this jimple body:
>> 
>> void <init>()
>>  {
>>      TestConstructorCalls r0;
>> 
>>      r0 := @this: TestConstructorCalls;
>>      specialinvoke r0.<TestConstructorCalls: void <init>(java.lang.String)>("");
>>      return;
>>  }
>> 
>> will produce this:
>> 
>>  void <init>()
>>  {
>>      TestConstructorCalls r0;
>> 
>>      r0 := @this;
>>      specialinvoke r0.<init>(""); //not clear anymore if it's a call for a local constructor or some other super class constructor.
>>      return;
>>  }
>> 
> 
> This looks odd. I don't even know what the second specialinvoke statement would look like in Jimple's object representation. Every invokeexpr has to have an associated base class and method signature. So where did they go?
> 
>> now I know as long as the program is running I can still get the missing info by getting them from Values' types but the thing is, the cloned jimple can't be an input to SOOT anymore "I tried to input that and the Lexer keeps complaining".
> 
> It would help us if you could look into the object representation of the cloned Jimple method to see if the information is really missing. If it is then probably something is wrong with importBodyContentsFrom, and should be fixed.
> 
> Cheers,
> Eric

--
Prof. Eric Bodden, Ph.D., http://sse.ec-spride.de/ http://bodden.de/
Head of Secure Software Engineering at Fraunhofer SIT, TU Darmstadt and EC SPRIDE
Tel: +49 6151 16-75422    Fax: +49 6151 869-127
Room B5.11, Fraunhofer SIT, Rheinstraße 75, 64295 Darmstadt



More information about the Soot-list mailing list