After add some new instructions, the br.s will direct to a wrong place.

96 views
Skip to first unread message

clark...@gmail.com

unread,
Feb 25, 2016, 11:02:20 AM2/25/16
to mono-cecil
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.

clark...@gmail.com

unread,
Feb 25, 2016, 8:52:52 PM2/25/16
to mono-cecil
I have gotten it. After going through the previous disccusion, Mono.cecil.rock has sovled the problem.Please seehttp://stackoverflow.com/questions/7267480/does-mono-cecil-take-care-of-branches-etc-location, it works for me, THANKS.

在 2016年2月26日星期五 UTC+8上午12:02:20,clark...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages