On Mon, May 2, 2011 at 1:36 PM, Philip Laureano
<[email protected]> wrote:
> Here's the complete example--I can't seem to figure out how to fix the
> invalid branch targets. In this case, I inserted instructions between the
> branch instruction and the instruction target but it doesn't appear to have
> updated the code with the correct offsets. The new branch target offsets
> seem to be the same as the original instructions.

That's an issue on your side. If you add the following code after you
instrumented the method body:

                        foreach (var instruction in body.Instructions) {
                                switch (instruction.OpCode.OperandType) {
                                case OperandType.ShortInlineBrTarget:
                                case OperandType.InlineBrTarget:
                                        var tgt = (Instruction) 
instruction.Operand;
                                        if (!body.Instructions.Contains (tgt))
                                                throw new Exception ("fubared");
                                        break;
                                }
                        }

You can see that the exception is thrown, meaning that you're
targeting an instruction that doesn't exist in the method. Cecil
simply trusts operand here and emits its offset. Cecil could check it,
but it would be quite costly for each branch instruction to check
(O(N)) that the operand is in the body.

Jb

-- 
--
mono-cecil

Reply via email to