Hello
Working with cecil I found a problem when injecting code into a method
thus increasing method's size. Problem is that if there are br.s
instructions in that method they might now have an operand that is
greater than sbyte so a wrong operand will be written when casting to
sbyte.
Solution is to change these instructions to normal br. So you have to
have some algorithm for deciding when to do that. There might be
several options, all should be implemented around the
CodeWriter.ComputeHeader area:
1. Calc all offsets, then iteratively: see if a br.s operand is too
big, if so change it and recalc offsets. check again if other br.s
operands are now too big because we changed br.s to br which means we
increased method size. check again and again until there's nothing to
change.
2. Calc all offsets. Check if method size is now greater than sbyte.
If so go over all br.s instructions and change them to br. recalc
offsets.

I think option 2 is neater. What's your opinion?
Thanks
Ros

-- 
--
mono-cecil

Reply via email to