Does Mono.Cecil take care of branches etc location?

≡放荡痞女 提交于 2019-12-18 15:24:09

问题


Well this question may seem odd but it's simple - my point is if i have a "goto" (brtrue etc) in the decompiled code like example

br IL_0003
call *****
IL_0003: ret

and I add a command after that **** call will the br at the top point to ret like it should or to that code.

does Cecil do it by itself or I have to take care of all those branches ? :/ it wouldn't be very hard to fix them but if Cecil doesn't then I simply won't start this project, I've no time (or knowledge) for advanced IL magic :P

(yes I know it won't be IL_0003 it's just for example)


回答1:


Yes, Cecil will update the branch for you.

The only case you have to take care of, is the case where the branch is a short form branch. If you inject too much instructions, it might overflow.

There's a very simple way to handle this. Before injecting code, simply call the extension methods SimplifyMacros from the Mono.Cecil.Rocks, like this:

method.Body.SimplifyMacros ();

This will turn the br.s into br.

And when you're done injecting code, simply call:

method.Body.OptimizeMacros ();

Which is the opposite operation, that is, it will try to turn br into br.s if possible.



来源:https://stackoverflow.com/questions/7267480/does-mono-cecil-take-care-of-branches-etc-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!