确定用于创建程序集的语言和编译器?
我想确定用于创建特定程序集的语言(C#、VB 等)。
我还想确定编译器(MS 编译器,mono)。
大会上似乎没有任何信息。有关 Ecma-335 分区 II 中程序集标头的部分没有提及任何有用的内容。
我想知道程序集中是否有指纹可以揭示“啊哈,这是 C#/c# 编译器非常特殊的东西,你是用 C# 编写的!”
了解这对于我正在编写的静态分析工具很有用。
I would like to identify the language(C#, VB, whatever) used to create a particular assembly.
I would also like to identify the compiler (the MS one, mono).
There doesn't seem to be any information in the assembly. The section about the headers of an assembly in Ecma-335 partition II doesn't mention anything useful.
I wonder if there are fingerprints in an assembly that could reveal that "aha this is something very particular to C#/the c# compiler, you were written in C#!"
This would be useful to know for the static analysis tool I'm writing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设计使然,程序集存储元数据和 IL(语言中立的信息)。这样您就可以轻松地混合和匹配用不同语言编写的代码。非常好的.NET 功能。
不过,这些都是提示。 VB.NET 程序员可能会使用 .NET 框架中的辅助程序集中实现的 VB.NET 特定语言功能。就像 My 命名空间和 CType 这样的转换运算符。使用 Ildasm.exe 打开程序集并查看 .assemble 指令的清单。如果您看到 Microsoft.VisualBasic 的一个,那么它很可能是用 VB.NET 编写的。如果缺少它,那么 C# 的胜算很大,尽管还不是结论性的。如果您查看类列表并看到顶部的
,那么您肯定知道它是用 C++/CLI 编写的。确保你实际上并不关心这个。
This is by design, an assembly stores metadata and IL, information that's language neutral. So that you can easily mix and match code written in different languages. Very nice .NET feature.
The are hints though. A VB.NET programmer is likely to use VB.NET specific language features that are implemented in a helper assembly in the .NET framework. Like the My namespace and conversion operators like CType. Open the assembly with Ildasm.exe and look at the manifest for the .assembly directives. If you see one for Microsoft.VisualBasic then the odds are very high that this was written in VB.NET. If it is missing then good odds for C#, although not conclusive. If you look at the class list and see
<CppImplementationDetails>
at the top then you know for sure it was written in C++/CLI.Make sure you don't actually care about this.