How can I programatically analyze a native DLL to read its imports?
[EDIT: my original question looked like the following, along with a huge chunk of defective code. Please see answers below for more correct code.]
The C# code located at this link is intended to print the imports of a native DLL.
I find that when I run the sample code with the original example’s target, MSCOREE.DLL, it prints all the imports fine. But when I use other dlls like GDI32.DLL or WSOCK32.DLL the imports do not get printed. What’s missing from this code that would let it print all the imports as, for example, DUMPBIN.EXE does?
There is one very big problem in the code (namely the definition of
THUNK_DATA) and various other smaller problems mostly concerning end-of-table detection (usingIsBadReadPtrinstead of NULL checks, and also not adding base address as needed).Here is a fixed version that produces the same output as dumpbin at least for wsock32: