Anyone?....please :)

On Nov 18, 4:22 pm, Jeff Nevins <[email protected]> wrote:
> I guess this is more of an IL instruction but I'd appreciate any help
> all the same.
>
> I need to add a method call at the end of an arbitrary set of methods.
> The Instructions I'm emitting are fine for most methods - I'm adding
> my new Instructions before the last found instruction with a Ret code:
>
>            var returnInstruction =
> method.Body.Instructions.LastOrDefault(i => i.OpCode.Code ==
> Code.Ret);
>
> ....
>
>             foreach (Instruction instruction in exitInstructions)
>             {
>                 processor.InsertBefore(returnInstruction,
> instruction);
>             }
>
> However, sometimes this approach bombs and I get an Invalid Program
> exception, which seems to happen when there is a Br_S instruction
> before the Ret instruction....which I guess makes sense.
>
> So, my question is...how can I reliably determine where to insert my
> new instruction(s) at the end of the method, before it returns?
>
> Thanks in advance.

-- 
--
mono-cecil

Reply via email to