[Soot-list] How could I get the assignment statement of a "static final" field with soot?

Bernhard Berger berber at tzi.de
Sat Apr 14 05:24:53 EDT 2018


Hi,

the optimization of static final fields is already done by the compiler. If you use javap to decompile the byte code  you will find that the value is already inlined. The byte code also tells that there is a Constant attribute assigned to the field. Perhaps you can use the Tag-API of Soot to fetch the value.

Cheers, Bernhard

> Am 14.04.2018 um 11:01 schrieb 周书林 <zhoushulin1992 at gmail.com>:
> 
> Hi,
> 
> I am novice in soot, and I want to analyse some Java projects. But there is some puzzle during the jimple analysis.
> 
> In my analysis, I want to get the definition of the class fields, including the field name, attributes, and value. But there is something wrong.
> 
> For the following class bat, I define a "final static" field "TEST_FIELD", and a "static" field "TEST_FIELD2". But in the jimple code, the "final static TEST_FIELD" is simplified as "100". I tried to find it in the "<clinit>" method. However, when I got the units in "<clinit>" method, I couldn't find the assignment for the "final static TEST_FIELD". More weird, if I delete the definition of "public static int TEST_FIELD2 = 100", I cannot even get the "<clinit>" method by API "SootClass.getMethodByName()".
> 
> public class bat{
> 	public static final int TEST_FIELD = 100;
> 	public static int TEST_FIELD2 = 100;
> 
> 	public int method1(int a){
> 		return TEST_FIELD+a;
> 	}
> 
> 	public static void main(String[] args){
> 		bat b = new bat();
> 		int a = 0;
> 		int r1 = b.method1(b.TEST_FIELD);
> 		int r2 = b.method1(b.TEST_FIELD2);
> 		System.out.println(r1);
> 		System.out.println(r2);
> 	}
> }
> 
> So, my question is : how could I get access to the definition of this "static final" field.
> 
> 
> 
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20180414/e80c3acd/attachment.html>


More information about the Soot-list mailing list