检查可执行文件的依赖关系.

检查可执行文件的依赖关系.

问题描述:

我将如何以编程方式检查可执行文件的依赖项(例如dll)?

How would I go about examining an executables dependencies (e.g. dlls) programatically?

阅读PE格式并尝试从中提取信息. PE格式是Windows上用于.exe,.dll等的格式.
Read about the PE format and try to extract information out of it. PE format is the format on Windows for .exe, .dll etc .


使用 Dependency Walker(取决于. exe) [ ^ ]在命令行模式下:它可以完成工作您需要并将其输出发送到控制台.您需要的是产生它的过程,附加它的输出,最后解析它给您的东西.

[edit]

在互联网上搜索了一下之后,我发现了以下页面:

Use the Dependency Walker (depends.exe)[^] in command line mode: it does the work you require and send its output to the console. What you need is to spawn its process, attach its output and finally parse what it gives you.

[edit]

After searching a bit on internet, I found these pages:


  • http://www.codeguru.com/forum/archive/index.php/t-376151.html[^]
  • http://msdn.microsoft.com/en-us/library/ms809762[^]
  • http://msdn.microsoft.com/it-it/magazine/cc301805(en-us).aspx[^]


需要牢记的是,这里您可以计算出的全部时间就是加载时间或链接器支持的延迟加载依赖性.如果有人手动加载DLL,则很难检测到(尽管您可以从EXE导入LoadLibrary/GetProcAddress的事实中得知).出于相同的原因,诸如COM对象激活之类的事情也很难跟踪.

干杯,

On quick caveat to bear in mind here is that about all you''ll be able to work out are the load time or linker supported delay loaded dependencies. If someone''s manually loading a DLL then it''s a lot harder to detect (although you can get an inkling from the fact that the EXE imports LoadLibrary/GetProcAddress). Things like COM object activation are also hard to track for the same reasons.

Cheers,

Ash