[Soot-list] get value of final fields

Patrick Lam plam at sable.mcgill.ca
Thu Jan 31 23:31:32 EST 2013


On 01/31/13 23:19, Tony Yan wrote:
> Hi,
>
> Is it possible in soot to get the value of a final field?
>
> Example:
>
> class A {
>    public static final int f = 1;
> }
>
> Is the fact that `f' is always `1' saved somewhere in soot?

No, because that information doesn't seem to be in the classfile; I'm 
not quite sure why. If you look at java.lang.System, on the other hand, 
you'll find a class initializers which sets java.lang.System.out to 
null. That's where you should find the information you're looking for. 
Note that javac inlines the f field in the bytecode at the end.

pat

plam at plym:/tmp$ cat A.java
public class A {
     public static final int f = 1;
     public static void main(String[] argv) { System.out.println(f); }
}

plam at plym:/tmp$ java soot.Main -soot-class-path 
.:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar -f j A
Soot started on Fri Feb 01 04:23:06 GMT 2013
Transforming A...
Writing to sootOutput/A.jimp
Soot finished on Fri Feb 01 04:23:07 GMT 2013
Soot has run for 0 min. 1 sec.

plam at plym:/tmp$ cat sootOutput/A.jimp
class A extends java.lang.Object
{
     public static final int f;

     void <init>()
     {
         A r0;

         r0 := @this;
         specialinvoke r0.<init>();
         return;
     }

     public static void main(java.lang.String[])
     {
         java.lang.String[] r0;
         java.io.PrintStream $r1;

         r0 := @parameter0;
         $r1 = java.lang.System.out;
         $r1.println(1);
         return;
     }
}

plam at plym:/tmp$ javap A
Compiled from "A.java"
class A extends java.lang.Object{
     public static final int f;
     A();
}

plam at plym:/tmp$ javap -c A
Compiled from "A.java"
class A extends java.lang.Object{
public static final int f;

A();
   Code:
    0:	aload_0
    1:	invokespecial	#1; //Method java/lang/Object."<init>":()V
    4:	return

public static void main(java.lang.String[]);
   Code:
    0:	getstatic	#2; //Field java/lang/System.out:Ljava/io/PrintStream;
    3:	iconst_1
    4:	invokevirtual	#3; //Method java/io/PrintStream.println:(I)V
    7:	return

}



More information about the Soot-list mailing list