tags:

views:

1166

answers:

7

In a nutshell: I want to do the same thing "Dependency Walker" does.

Is there any Win32 API function which can enumerate the dependencies of a EXE and/or DLL file?

And is there any safe way to detect dependencies on ActiveX classes? (I doubt it is possible, but who knows ...)

EDIT: I'm aware of available tools which provide the same core functionality (Dependency Walker, ProcessExplorer, AQTime, ...) but I want to create my own program which dumps a text file containing the required modules.

EDIT 2: What is this "DB API" which is mentioned in some answers? Do you have any links or other information?

+1  A: 

Run up the application, with Process Explorer already running and set to filter for your applications .exe name.

There is no way to detect all COM dependancies that an executable has without running it.

Richard Ev
+3  A: 

It seems that dependency walker source code itslef was given by micrsoft via MSJ. Please look at http://www.mail-archive.com/[email protected]/msg11397.html You need to refer some other site to download since the link given in this mail trail is not working.

Please check http://www.microsoft.com/msj/codeupdates.aspx : Since I don't have time, I have not checked whether it contains source code or only exe.

lakshmanaraj
+2  A: 

The following commands dumps the direct dependencies of some.exe :

dumpbin /imports some.exe

It works on DLLs too.

This won't list dependencies such as plugins loaded at application launch (via LoadLibrary calls). Same for COM dependencies since they work the same way (as far as I know).

If you need to know all the DLLs used by a running program, use ProcessExplorer.

bltxd
A: 

Yes, you can do it with Win32 api (DB)

See Adv. Win32 api newsgroup news://comp.os.ms-windows.programmer.win32 where it's a classic question...

+1  A: 

User @blue... eluded to Dependency Walker. When using Dependency Walker, after opening the file you can see the base requirements that are used. Only when executing the program and exercising all of its functions can you find all of the dynamically-loaded DLLs.

Sometimes the best thing to do if you can is ask the developer what DLLs are required. An application may only load some DLLs when absolutely needed. e.g. Loading faultrep.dll, for custom Windows Error Reporting, when it is about to crash.

Kris Kumler
Not true re delay load dlls, they're in an import section of the exe just like regular dlls. But I agree, to find the dynamically loaded dlls you'd have to hook LoadLibrary() and exercise the required code paths in the exe.
Len Holgate
+1  A: 

You probably need to walk the executable's file structure to work this out programatically. Therefore something like the 'PE Dump' program that's mentioned here: http://msdn.microsoft.com/en-gb/magazine/cc301808.aspx would be a good starting point. The actual code that you need can be found here: http://www.wheaty.net/downloads.htm

Len Holgate
+1  A: 

findstr -i .dll exe.exe | more | findstr -i .dll | more

rem :)