Programmatic MSIL injection

前端 未结 7 2066
情书的邮戳
情书的邮戳 2021-02-09 08:01

Let\'s say I have a buggy application like this:

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
          


        
相关标签:
7条回答
  • 2021-02-09 08:21

    If your exe is signed then that wouldn't be possible. Why can't you just release that single assembly, instead of shipping the whole application again? It seems like you're aiming for a complex solution for a simple problem.

    0 讨论(0)
  • 2021-02-09 08:24

    I guess the question I would ask is "how would you deploy the patch"? Somewhere, you have to deploy something to fix a bug that is already out in the wild. Why would recompiling the dll and releasing the fixed version really be an issue? My guess is that figuring out how to programatically inject MSIL is going to be more trouble than simply redeploying a fixed assembly.

    0 讨论(0)
  • 2021-02-09 08:24

    If the reason you don't want to redeploy the whole stuff is because it is really half a gig, you should probably use some sort of binary patch tool - that's the first result on Google:

    Binary Diff http://www.daemonology.net/bsdiff/

    0 讨论(0)
  • 2021-02-09 08:24

    You can use static MSIL Injection. Mono Cecil or PostSharp maybe helpful.

    0 讨论(0)
  • 2021-02-09 08:25

    good source of information...

    IL Programming ebook

    another is MS Press book on IL programming.

    steps to decompile to IL and recompile

    1. ildasm /output=ConsoleApplication1.il ConsoleApplication1.exe

    2. //modify ConsoleApplication1.il code

    3. ilasm ConsoleApplication1.il

    0 讨论(0)
  • 2021-02-09 08:30

    Rather than injecting MSIL at runtime, have you considered inserting the source directly into the assembly?

    You can disassemble with ildasm, insert your MSIL, and then reassemble with ilasm, then deploy the product of that.

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