Recently, I used the Mono.cecil to modify another assembly, exactly my aim is to instrumentate that program. So I use the ILProcessor.InsertBefore to add some new instructions before each ot instructions of objected assembly to show its execution trace. At begining, it works well, BUT, when the program contains the instruction, br.s, it goes wrong. I dump the original and modified IL codes, and find the modified IL codes gived a wrong destination or miss the destination. For example, there is an instruction like this:
IL_000c: brtrue.s IL_001b
Obviously, its destination is IL_001b
after modified the assembly, its destination should be IL_01c4 since I add new instructions, but actually, the program missed it or sometimes it gives a wrong place(I haven't figured out which code leads to the different situations, but usually it will miss the destination.)
I don't know if it is a bug of the ILProcessor.InsertBefore or I have made some mistake?
Really appreciate your precious advice or discussion. Thank you.