Sara27
Sara27

Reputation: 49

How can I open DLL file created in C++ to view classes, methods and source code?

I found a .dll file created in C++. I want to open this file and see the functions inside the classes.

How can I open this file and call the functions within my c++ project ?

Upvotes: 3

Views: 6240

Answers (1)

Christophe
Christophe

Reputation: 73577

With Microsoft's command line utility dumpbin, you can display what a DLL imports or exports:

dumpbin /exports Test0221-5.dll 

This displays the exposed functions. But it's up to you to analyse the content. For example:

Dump of file Test0221-5.dll
File Type: DLL
  Section contains the following exports for Test0221-5.dll
    00000000 characteristics
    555E19D5 time date stamp Thu May 21 19:45:57 2015
        0.00 version
           1 ordinal base
           4 number of functions
           4 number of names

    ordinal hint RVA      name
          1    0 000113E3 ??0Btest@@QAE@XZ = @ILT+990(??0Btest@@QAE@XZ)
          2    1 000112CB ??1Btest@@QAE@XZ = @ILT+710(??1Btest@@QAE@XZ)
          3    2 00011028 ?MemberFunc@A@@UAEXXZ = @ILT+35(?MemberFunc@A@@UAEXXZ)
          4    3 00011244 createInstance = @ILT+575(_createInstance)
  Summary
        1000 .data
        1000 .idata
        3000 .rdata
        1000 .reloc
        1000 .rsrc
        C000 .text
       10000 .textbss

So, above, you can see the function 4. The name corresponds to a symbol, so it's probably an extern "C" function called createInstance() . But you can't find out nothing more about its parameters or its return type.

Functions 1 to 3 are more expressive. It looks like a function name, but there are ? @ and other strange characters in the name. These are "mangled" C++ name. The mangling of name depends on the compiler.

MSVC has a tool undname:

undname ??0Btest@@QAE@XZ
  Undecoration of :- "??0Btest@@QAE@XZ"
  is :- "public: __thiscall Btest::Btest(void)"

You call it symbol by symbol. Fortunately there's a more convenient alternative: http://demangler.com/. You can copy the full list of mangled names (MSVC or GCC) and past it in the browser, to find out, for our example:

public: __thiscall Btest::Btest(void) = @ILT 990(public: __thiscall Btest::Btest(void)
public: __thiscall Btest::~Btest(void) = @ILT 710(public: __thiscall Btest::~Btest(void)
public: virtual void __thiscall A::MemberFunc(void) = @ILT 35(public: virtual void __thiscall A::MemberFunc(void) 

So you get the funcion's class, if it's virtual or not, if it's static or not, the return type, the calling conventions, and the type of each parameter.

Perhaps this could help you, but as you see it's rather artisanal, and can't be complete. You don't see for example class inheritance, and non exported members.

Upvotes: 3

Related Questions