从 C# 可执行文件扫描 DLL 依赖项
我正在开发一个并行构建工具,它可以构建(以及其他许多东西)各种类型的 Windows 程序。我们工具的一部分是 EXE 和 DLL 文件的自动依赖性扫描,它使我们的用户的生活变得更加轻松。这意味着,例如,如果用户说他们想要运行“bob.exe”,那么当“bob.exe”分发到构建网络中的其他节点时,他们不必担心依赖问题。这是因为我们扫描“bob.exe”找出它需要哪些 DLL,并将它们与它一起发送。
总的来说,除非 EXE 以编程方式加载 DLL,否则这种方法工作得很好。然后必须将依赖项硬编码到用户 make 文件中。我们最近开始遇到的一个问题是如何处理 C# DLL/EXE。这些似乎包含不属于 PE 格式一部分的 DLL 引用。我认为这些引用位于某种 C# 容器内,并且 C# 运行时只是在 C# 运行时启动时以编程方式加载它们。
谁能告诉我以二进制级别扫描这些引用的最佳方法是什么?我的构建工具是多平台的,因此我的 PE 扫描器目前是用 Java 编写的。因此我不能依赖任何.NET 库。我的 PE 扫描器已经可以解析出 PE 文件中的所有部分,并且我习惯于解析出包含 C++ 应用程序的并排汇编信息的部分。我只需要一些关于在 C# 应用程序中该怎么做的指示......
I work on a parallel build tool which builds (among lots of other things) windows programs of various types. One part of our tool which makes life alot easier for our users is the automatic dependency scanning of EXE and DLL files. This means that if a user says they want to run "bob.exe" for example, they don't have to worry about dependency problems when "bob.exe" get's distributed to other nodes in the build network. This is because we scan "bob.exe" work out what DLLs it needs and send them along with it.
On the whole this works well except when an EXE programatically loads a DLL. Then the dependency has to be hard coded into the users make file. One problem we've started to have recently is what to do about C# DLLs/EXEs. These seem to contain DLL references which are not part of the PE format. I presume the references are inside some kind of C# container and that the C# runtime just programmatically loads them when the C# runtime kicks into action.
Can anyone tell me what the best approach would be to scanning out these references at a binary level? My build tool is multiplatform and my PE scanner is currently written in Java for this reason. Therefore I can't rely on any of the .NET libraries. My PE scanner can already parse out all the sections in the PE file and I'm used to parsing out the section which contains side-by-side assembly information for C++ applications. I just need some pointers for what to do in the case of C# apps...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.NET 程序集的格式由标准 ECMA-335“通用语言”定义基础设施 (CLI)”,特别是“第二部分:元数据定义和语义”,可免费下载。您可以使用它为它们编写自己的 Java 解析器来提取引用。
The format of .NET assemblies is defined by standard ECMA-335 "Common Language Infrastructure (CLI)", specifically "Partition II: Metadata Definition and Semantics", which is freely available for download. You can use that to write your own Java parser for them that would extract the references.
您可以使用(或从中获取灵感) pe-file-reader 库:
You can use (or take inspiration from) the pe-file-reader library: