[Soot-list] cast soot.SootClass to Local variable

Eric Bodden bodden at st.informatik.tu-darmstadt.de
Thu Dec 3 03:16:42 EST 2009


Hi again.

Actually you got me confused there. Why exactly do you want to pass
the class argument to newStaticInvokeExpr? Do you want to pass the
class instance to the static call at runtime?

If so, then you need to insert a call "x =
Class.forName(<static_class.toString()>)" and then insert a call to
your static method that uses x as the third argument.

Eric

--
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



2009/12/2 Zhang Yixi <zhangy16 at rpi.edu>:
> Hi Eric,
>
> Thanks for your reply. But based on my understanding of your tips, I modified my code as:
> sc =
> Jimple.v().newStaticInvokeExpr(before_call_vi, StringConstant.v(call_id), Class.forName(static_class.toString()));
> But when compile the java file error shows cant cast Class to soot.Value, the same as always. Or I misunderstood your idea, should insert receiverExpr = ((InstanceInvokeExpr)c).getBase() into Class.forName to get the class at runtime. Then what's the next step?
>
> Regards,
> Yixi
> MEng, ELEC, RPI
>
>
> On Dec 2, 2009, at 8:27 AM, Eric Bodden wrote:
>
>> Hi.
>>
>> If your target machine does not support class constants, then you
>> basically have to do what pre-Java-1.4 compilers did: insert calls to
>> Class.forName(..) to retrieve the class constant object at runtime.
>>
>> Eric
>>
>> --
>> 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
>>
>>
>>
>> 2009/12/1 Zhang Yixi <zhangy16 at rpi.edu>:
>>> Hi all,
>>> I'm trying to fix my code for a programming assignment. My question is how
>>> to convert the SootClass static_class to a soot.Value variable can use as
>>> the newStaticInvokeExpr()'s third argument. The restriction is cant use
>>> ClassConstant.v() because our remote machine doesn't support that. What I
>>> have is
>>> private static String tracker_name = "RuntimeTracker";
>>> private static SootMethod before_call_vi;
>>> tracker_class = Scene.v().getSootClass(tracker_name);
>>> before_call_vi =tracker_class.getMethod("void
>>> beforeCall(java.lang.String,java.lang.Object)");
>>> Value receiver_expr = ((InstanceInvokeExpr)c).getBase();
>>> Type static_type = receiver_expr.getType();
>>> SootClass static_class = ((RefType)static_type).getSootClass();
>>> sc =
>>> Jimple.v().newStaticInvokeExpr(before_call_vi,StringConstant.v(call_id),static_class);
>>> The compile error is
>>> "Explicit cast needed to convert soot.SootClass to soot.Value."
>>> _______________________________________________
>>> 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