修改并运行现有的.NET程序集而不保存到磁盘 [英] Modify and run existing .NET assembly without saving to disk

查看:89
本文介绍了修改并运行现有的.NET程序集而不保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以修改现有.NET程序集中的方法,并在不将其保存到磁盘的情况下执行该程序集?我想要类似于`System.Reflection.Emit.MethodRental` ,但是`Reflection.Emit`名称空间仅处理动态创建的程序集.有许多方法涉及创建新的可执行文件.或修改现有的,但是我想避免做这两个.

我也可以使用CLR事件探查器的JIT编译钩子来重写方法主体,但希望使用可以在C#中完成的方法.该用例是作为探查器的一部分,该探查器在函数入口/出口处输出程序值.

Is there any way to modify methods in an existing .NET assembly, and execute the assembly without saving it to disk? I would like functionality similar to `System.Reflection.Emit.MethodRental` but the `Reflection.Emit` namespace only deals with dynamically created assemblies. There are many approaches that involve creating a new executable. or modifying an existing one, but I would like to avoid doing either of these.

I could use the CLR profiler''s JIT compilation hooks to rewrite the method bodies as well, but would prefer an approach that could be done in C#. The use case is as part of a profiler that outputs program values at function entrance/exit.

推荐答案

看看以下内容(JavaScript):
http://odetocode.com/Code/80.aspx [ http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm [ ^ ]

祝你好运!
Have a look at this (JavaScript):
http://odetocode.com/Code/80.aspx[^]

or this (c#):
http://www.west-wind.com/presentations/dynamicCode/DynamicCode.htm[^]

Good luck!


以下是一些有用的链接,可以帮助您入门:
http://www.mono-project.com/Cecil [ http://sebastien.lebreton.free.fr/reflexil/ [组装操作和C#/VB.NET代码注入 [
Here are some useful links to get you started:
http://www.mono-project.com/Cecil[^]

http://sebastien.lebreton.free.fr/reflexil/[^]

Assembly Manipulation and C# / VB.NET Code Injection[^]

Regards
Espen Harlinn


这篇关于修改并运行现有的.NET程序集而不保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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