用 Mono.Cecil 替换类
假设我有程序集 A。它用 Mono.Cecil 进行了一些修改。现在假设我有程序集 B。它有一个名为 SomeClass
的类。程序集 A 还有一个名为 SomeClass
的类。现在我想用程序集 B 中的程序集 A 中的 SomeClass
替换。我尝试了一些方法,但我知道,对于我的其中一次尝试,它实际上重新映射了一个方法调用,如下所示:
Console.WriteLine("Test.");
.. .into this:
int.WriteLine("Test.");
那是不对的。用 Mono.Cecil 替换类的正确方法是什么?
Say I have assembly A. It was modified with Mono.Cecil a little bit. Now say I have assembly B. It has a class named SomeClass
. Assembly A also has a class named SomeClass
. Now I want to replace SomeClass
from assembly A with the one in assembly B. I tried a few things, but I know that for one of my attempts, it actually remapped a method call like this:
Console.WriteLine("Test.");
...into this:
int.WriteLine("Test.");
That can't be right. What is the correct way to replace a class with Mono.Cecil?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可能正在做一些塞西尔不理解的事情。如果没有看到任何代码,就不可能告诉您什么。
将一种类型交换为另一种类型并不简单,您必须在目标模块中重新创建要注入的对象模型,并将其每个引用替换为新的引用。基本上,您必须遍历目标模块中的每个引用并确保其得到正确处理。
You're probably doing something that Cecil doesn't understand. It's impossible to tell you what without seeing any code.
Swapping a type by another is not trivial, you'd have to recreate in the target module the object model you want to inject, and replace every reference of it with the new one. Basically, you'd have to walk over every reference in the target module and make sure it's properly processed.