如何打开在c++中创建的DLL文件来查看类、方法和源代码

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

本文关键字:方法 源代码 文件 c++ 何打开 创建 DLL      更新时间:2023-10-16

我发现了一个用c++创建的。dll文件。我想打开这个文件,看看类里面的函数。

如何打开这个文件并在我的c++项目中调用函数?

使用Microsoft的命令行实用程序 dumpbin ,您可以显示DLL导入或导出的内容:

dumpbin /exports Test0221-5.dll 

显示公开的函数。但这取决于你来分析内容。例如:

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

因此,在上面,您可以看到函数4。这个名字对应一个符号,所以它可能是一个叫做createInstance()extern "C"函数。但是你不能找到任何关于它的参数或者它的返回类型的信息。

函数1到3更具表现力。它看起来像一个函数名,但名字中有? @等奇怪的字符。这些都是"乱糟糟"的c++名称。名称的混淆取决于编译器。

MSVC有一个工具undname:

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

你称它为一个符号一个符号。幸运的是,有一个更方便的选择:http://demangler.com/。您可以复制损坏名称的完整列表(MSVC或GCC)并在浏览器中传递它,以查找,例如:

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) 

你得到函数的类,它是虚的还是非虚的,它是静态的还是非静态的,返回类型,调用约定,以及每个参数的类型。

也许这可以帮助你,但正如你所看到的,这是相当手工的,不可能是完整的。例如,您不会看到类继承和非导出成员。