Hi,

maybe the mail from cygin on march, 18th helps you:

> MethodBody.Simplify() simplifies the body by turning short
> instructions into normal ones (e.g. leave_s to leave)
> After that, you can inject instructions without overflowing the
> offsets.
> Finally, you can use MethodBody.Optimize() to turn all into short form
> when possible.

Regard,
Simon


sergiy.sakharov wrote:
> Hello,
>
> Yesterday I've stumbled upon weird errors while instrumenting existing
> assembly:
> "Common Language Runtime detected an invalid program. while compiling
> method"
> After some digging I found out te problem was in an overflow of conditional
> IL operator:
> IL_00...:  brtrue.s   IL_ffffffc9
> (actually there were a number of overflows not only with brtrue.s
> operator..)
>
> This happened when I inserted some instructions in the middle of method and
> therefore brtrue.s ' int8 size of offset was not enough any more, so now I
> have to create myself some checks and replace small conditional instructions
> in such cases, but that's not the story...
>
> During this investigation I've found a place in CodeWriter.cs that could be
> changed a bit:
>
> Line 215:
> from          m_codeWriter.Write ((byte) (((Instruction) 
> instr.Operand).Offset -
> to            m_codeWriter.Write (checked((sbyte) (((Instruction)
> instr.Operand).Offset -
>
> Firstly - sbyte is actually INT8 which is ecpected as an operant of ".s"
> operators, and secondly - checked will actually throw exception in case of
> overflow.
> I know that "Cecil does absolutely no verification on what it emits.", but
> just in case...
>
> Best Regards.
> Sergiy
>
>   


--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to