[Soot-list] Trying to do getClass() on a static method...need to implement inner classes

Eric Bodden bodden at st.informatik.tu-darmstadt.de
Thu Jun 17 03:40:53 EDT 2010


Hi Kanad.

Please correct me if I misunderstood you but for the following
example, do you just want to get a handle to the class object of
"Foo"?

class Foo {
static void bar() {
//want to get a handle to Foo.class here
}
}

If so, then you can do this a lot easier than using "new Object()
{}.getClass().getEnclosingClass()": you can just use a class constant!

Because the method is static, you know the exact type on which the
method is declared (e.g. "Foo"). Then using this type name, simple
create a class constant:

soot.jimple.ClassConstant.v("Foo")

If you assign this value within a JAssignStmt then this should give
you a runtime handle to the class "Foo".

Eric

--
Dr. Eric Bodden
Software Technology Group, Technische Universität Darmstadt, Germany
Tel: +49 6151 16-5478    Fax: +49 6151 16-5410
Mailing Address: S2|02 A209, Hochschulstraße 10, 64289 Darmstadt



On 17 June 2010 02:23, Kanad Sinha <kanad85 at gmail.com> wrote:
>
> Hi,
>
> First of all, thanks for answering an earlier query of mine that you had
> answered a few days back!
>
> I need to get the runtime class of a static method a la getClass(), by
> instrumenting the following code:
>
> new Object() {}.getClass().getEnclosingClass()        /* (1) */
>
> Suppose this is done for a static method of class Main, it seems this code
> generates an inner class Main$1, which in Jimple looks like:
>
> class Main$1 extends java.lang.Object
> {
>     void <init>()
>     {
>         Main$1 r0;
>
>         r0 := @this: Main$1;
>         specialinvoke r0.<java.lang.Object: void <init>()>();
>         return;
>     }
> }
>
> , and the actual code (1) is translated to:
>
> $r10 = new Main$1;
> specialinvoke $r10.<Main$1: void <init>()>();
> $r11 = virtualinvoke $r10.<java.lang.Object: java.lang.Class getClass()>();
> virtualinvoke $r11.<java.lang.Class: java.lang.Class getEnclosingClass()>();
>
> I created the new class and inserted the above Jimple code. For the new
> class that I created, I also set setOuterClass to the proper class (Main in
> this case). When I run this code, however, it returns null. I am guessing I
> have to do something more to properly register this as an inner class. Could
> anyone suggest what could be done in order to get the proper result?
>
> To avoid spamming later on, I thank you in advance for any help forthcoming.
>
> -- Kanad.
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
>


More information about the Soot-list mailing list