程序化MSIL注入 [英] Programmatic MSIL injection

查看:58
本文介绍了程序化MSIL注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个有问题的应用程序,例如:

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

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("2 + 1 = {0}", Add(2, 1));
        }

        static int Add(int x, int y)
        {
            return x + x; // <-- oops!
        }
    }
}

应用程序已经编译并部署到野外。有人发现了该错误,现在他们正在寻求修复。虽然我可以使用该修补程序重新部署该应用程序,但由于无法控制的原因,它极度麻烦-我只想为该错误编写一个补丁。

The application is already compiled and deployed into the wild. Someone has found the bug, and now they are requesting a fix for it. While I could re-deploy this application with the fix, its an extreme hassle for reasons outside of my control -- I just want to write a patch for the bug instead.

特别是,我想将自己的MSIL插入有问题的汇编源文件中。我以前从未做过这样的事情,而且谷歌搜索还没有发现任何有用的信息。如果我可以在上面的代码中看到如何执行此操作的示例,那么它将极大地帮助我:)

Specifically, I want to insert my own MSIL into the offending assmembly source file. I've never done anything like this before, and googling hasn't turned up any useful information. If I could just see a sample of how to do this on the code above, it would help me out tremendously :)

如何以编程方式注入自己的将MSIL集成到已编译的.NET程序集中?

对于那些问过的人:我不需要运行时热交换。对于我来说,关闭应用程序,操纵程序集然后再次重新启动程序是非常好的。

To those who asked: I don't need runtime hotswapping. Its perfectly fine for me to have the app closed, manipulate the assembly, then restart the program again.

[再编辑一次:]看起来,一般共识是操纵程序集是修补程序的一种方法。如果它是坏主意,我不会走这条路。 / a>。

It looks like the general consensus is "manipulating the assembly is a bad way to patch a program". I won't go down that road if its a bad idea.

我将悬而未决,因为MSIL注入可能仍可用于其他用途:)

I'll leave the question open because MSIL injection might still be useful for other purposes :)

推荐答案

我想我要问的问题是您将如何部署补丁?在某个地方,您必须部署某些东西来修复已经存在的错误。为什么重新编译dll并发布固定版本确实是个问题?我的猜测是,弄清楚如何以编程方式注入MSIL比简单地重新部署固定程序集要麻烦得多。

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.

这篇关于程序化MSIL注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆