Does Mono.Cecil take care of branches etc location?

后端 未结 1 1581
耶瑟儿~
耶瑟儿~ 2021-01-02 05:55

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         


        
相关标签:
1条回答
  • 2021-01-02 06:19

    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.

    0 讨论(0)
提交回复
热议问题