[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

specialinvoke for <init> = super()



Ok, I created the new method <init> in my class but how do I get a statement like this?

specialinvoke r0.<java.lang.Object: void <init>()>();

I got the "java.lang.Object: void <init>()" SootMethod as you can see below:

Chain myUnits = myBody.getUnits();

SootClass mySuperClass = myClass.getSuperclass();

SootMethod myInitMethod = mySuperClass.getMethodByName("<init>");


But when I try to add this to my chain/body: myUnits.addLast(Jimple.v().newSpecialInvokeExpr(initLocal,myInitMethod));


I get the a "Exception in thread "main" java.lang.ClassCastException" exception when I try to write it out with the Printer package to a class file. Of course initLocal is exactly the r0 local referred above in my target Jimple expression.


Cheers,

Emil

Feng Qian wrote:
I believe you have to create an <init> method, because a newly created object should be initialized before other uses. You can create a very simple <init> method which invokes super.<init> .

Cheers,
Feng