从程序集中提取特定IL(.NET中间语言)签名的机制 [英] Mechanism to extract specific IL (.NET Intermediate Language) signatures from an assembly

查看:97
本文介绍了从程序集中提取特定IL(.NET中间语言)签名的机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Microsoft .NET程序集mscorlib.dll中找到了大约25种类型的列表,我需要在其中提取类及其成员的IL签名。我希望每种类型一个文件,每个签名都在一行上。因此,例如,采用类型

I have a list of about 25 types found in the Microsoft .NET assembly mscorlib.dll where I need to extract the IL signatures of the class and its members. I want one file per type, with each signature on one line. So, for example, take the type

System.Collections.Generic.Comparer<T>

我想从程序集中为该类型提取以下内容(有些私人成员我会这样做'不需要,但是我可以根据需要手动处理。)

I want to extract the following from the assembly for that type (there are some private members I won't need, but I can handle that manually if needed).

.class public abstract auto ansi serializable beforefieldinit System.Collections.Generic.Comparer`1<T> extends System.Object implements System.Collections.IComparer, class System.Collections.Generic.IComparer`1<!T>
.method family hidebysig specialname rtspecialname instance void  .ctor() cil managed
.method public hidebysig newslot abstract virtual instance int32  Compare(!T x, !T y) cil managed
.method private hidebysig newslot virtual final instance int32  System.Collections.IComparer.Compare(object x, object y) cil managed
.property class System.Collections.Generic.Comparer`1<!T> Default() { .get class System.Collections.Generic.Comparer`1<!T> System.Collections.Generic.Comparer`1::get_Default() }

所以,我考虑过完成此操作的四种方法:

So, I have thought about four ways of accomplishing this:


  • 手动将每种类型的每个签名手动剪切并粘贴到ildasm的文本文件中(直接或通过转储mscorlib.dll)。其中一些类型很长,因此可能会很乏味。如果我需要做更多的事情,这绝对不是一个好的长期解决方案。

  • Manually cut and paste each signature from each type by hand into the text files from ildasm (either directly or via a dump of mscorlib.dll). Some of the types are pretty long, so this could get tedious. And this is definitely not a good long-term solution if I need to do more.

编写一个使用反射来尝试获取所有签名的工具。我曾在较高级别上考虑过使用类似下面的伪代码[1]的方法。

Write a tool that uses Reflection to try to get all of the signatures. I have, at a high level, thought about using something like the psuedo-code [1] below.

编写一种在IL上使用字符串解析的工具ildasm转储以查找类型并获取签名

Write a tool that uses string parsing on the IL dump of ildasm to find the types and get the signatures

使用现有工具来完成任务。

Use an already existing tool to accomplish the task.

有人知道现有的工具或机制可以帮助我完成任务吗?如果没有,那么对于获得这种工具的方向有何建议?而且,如果您对如何完成代码有任何想法,我将不胜感激。

Does anyone know of an existing tool or mechanism that might help me accomplish my task? If not, any suggestions on which direction to go to get such a tool made? And if you have any code ideas about how to get it done, I would appreciate hearing them.

[1]

System.Reflection.GetType(string)
Type.GetMethods() For each item in
MethodInfo, GetMethodBody()
GetILAsByteArray().ToString()
Determine a way to get just the signature from the IL


推荐答案

红色门反射器可以使粘贴和粘贴变得更快。

red gate reflector could make cut and paste go a lot quicker.

这篇关于从程序集中提取特定IL(.NET中间语言)签名的机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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