Hi JB, I find its resolution. First, I create a variable, like:
1. var temp = new VariableDefinition(MethodModule.Import(typeof(object
)));
2. var tempctorref = MethodModule.Import(typeof(object
).GetConstructor(new Type[]{}));
3. method.Body.Variables.Add(temp);
then,just use :
1. ins = ilProcessor.Create(OpCodes.Stloc, temp);
so, I don't care about what's the index of the call stack. Is it right?
在 2016年3月16日星期三 UTC+8上午10:03:42,[email protected]写道:
>
> I know my mistakes. CLR just allows to set the call stack
> successively.When I want to use V_1, V_0 must be used. Here is question,
>
> how can I know how many Call stack variable are used? and How to use the
> stloc.s, exactly how to write its parameter?
>
> 在 2016年3月8日星期二 UTC+8上午12:53:41,Jb Evain写道:
>>
>> Hi,
>>
>> Thanks for using Cecil and reaching out on the group, but please be
>> careful. You're sending multiple messages with basically the same
>> content, which is not a great way to get help.
>>
>> It's definitely possible to insert instructions that are manipulating the
>> stack.
>>
>> If you face any issue, please use peverify to diagnose what's wrong in
>> the IL.
>>
>> Short of that, please show some code in a Gist or in pastebin.
>>
>> Jb
>>
>>
>> On Mon, Mar 7, 2016 at 12:53 AM, <[email protected]> wrote:
>> > As the title mentioned, when I modified a method, where there is no
>> variable
>> > defined original, I cannot insert new
>> >
>> > instructions to use the Call Stack, like stloc, etc. For example:
>> >
>> > the original program is like:
>> >
>> > void fun()
>> > {
>> > Console.WriteLine("hello.");
>> > }
>> >
>> > I cannot use Mono.Cecil to insert instruction, stloc_0 or ldloc_0,
>> cause
>> > Call Stack loc_0 seems not able to use.and CLR reports error.
>> >
>> > How to deal with it? Thank you for your advice.
>> >
>> > --
>> > --
>> > --
>> > mono-cecil
>> > ---
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "mono-cecil" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an
>> > email to [email protected].
>> > For more options, visit https://groups.google.com/d/optout.
>>
>
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.