tags:

views:

105

answers:

4

There are tools like Dependency Walker, dumpbin, ildasm for looking into DLLs/EXE files on Windows. I would like to analyze DLLs from code, especially dependencies both managed and unmanaged. Are there any (.NET) libraries out there for analyzing with similar functionality?

I want to use this to verify that we am deploying the right DLLs in setup program my company are creating. We have more than 200 DLLs.

+1  A: 

If you want to do your own dependency checking you can write Code Analysis (FxCop) plugins for Visual Studio for managed code assemblies.

Tutorial on writing your own Code Analysis rule

If you want pre-built tools you can use:

  1. The built in Code Analysis (FxCop) tool in Visual Studio.
  2. NDepend
Eilon
There may be something in the FxCop toolkit for creating own rules I can use. Thanks.As for NDepends, as far as I can see it is a standalone tool, and not something I can easily call from my program.
Arve
+1  A: 

I hope this doesn't break any rules, but you might want to look into a library I've developed which can see image imports and exports among a heap of other things. Download the source code from here: https://sourceforge.net/projects/processhacker/files. Extract ProcessHacker.Common and ProcessHacker.Native, include them in your solution, and reference them.

Here's how to use it:

using ProcessHacker.Native.Image;

MappedImage image = new MappedImage("file.exe");

for (int i = 0; i < image.Imports.Count; i++)
{
    Console.WriteLine("Imports for " + image.Imports[i].Name + ":");

    for (int j = 0; j < image.Imports[i].Count; j++)
        Console.WriteLine(image.Imports[i][j].Name);
}

I don't know how to deal with .NET references though.

wj32
I'll try. Thanks.
Arve
I have tried. It worked very well on native DLL references. Too bad I can't give two "approved answers" here..
Arve
I'm glad it works. Don't worry about trying to accept two answers, I don't mind.
wj32
+3  A: 

NDepend is indeed the tool you are looking for but you should also consider decreasing the number of assemblies as explained here: Advices on partitioning code through .NET assemblies

Patrick Smacchia - NDepend dev
+3  A: 

You can use the Cecil library to analyze managed executables. And you can use Gendarme that uses Cecil if you want a rule engine to check your application.

Jb Evain
Cecil looks like good library for managed code, I will have to try to use ut
Arve
You should disclose that you're the author of Cecil.
Jason
@Jason You mean, like putting that info on his profile? Jb is so sneaky, I'm glad you set things straight.
Yann Schwartz
@Jason, and for what sake? Does «disclosing» it provides more information to answer the question? Or is it supposed to put more weight on my answer and gain me more points (and I'm so running after them!)? In any case, I don't really see how it is relevant. Anyone interested can, well, click my name.
Jb Evain
@Yann Scwartz: No, it should be in any posts about Cecil or any projects that Cecil "competes" with.
Jason
@Jb Evian: Because it colors your view. How would anyone know to click your name? Everytime someone recommends, say, ReSharper should I have to click their name to see if they are affiliated with the project? No, it should be disclosed in plain sight.
Jason
There are several threads on Meta on this topic: http://bit.ly/4V5wcH, http://bit.ly/7kgUJo and http://bit.ly/4ywWiu. The consensus is full disclosure in any post you make where the OP or the remarks you make are relevant to a product that you are affiliated with. Note that the first two are clearly oriented towards for pay products, while the last is regarding a free product. The guideline is clear: "Fundamentally, there is very little wrong in believing in one's own product and recommending it to others. However, ethically, a poster should provide some sort of disclaimer of their bias."
Jason
Gee, Cecil is not a product at all (Gendarme isn't either). It's an open source library licensed under one of the most liberal license, the MIT/X11. It's not like am shamelessly plugin it, guess what, it answers the need of the poster.
Jb Evain
Cecil worked very well for my purpose, it was exactly what I wanted for the .NET part
Arve
"the consensus among people who spend too much time on meta SO", that is.
Yann Schwartz