c++ - 如何打开用 C++ 创建的 DLL 文件以查看类、方法和源代码?

标签 c++ dll

我找到了一个用 C++ 创建的 .dll 文件。我想打开这个文件并查看类中的函数。

如何打开此文件并调用我的 C++ 项目中的函数?

最佳答案

使用微软的命令行工具 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 更具表现力。看起来像个函数名,但是名字里有? @等奇怪的字符。这些是“mangled”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) 

所以你得到函数的类,它是否是虚拟的,如果它是静态的,返回类型,调用约定,以及每个参数的类型。

也许这对您有帮助,但如您所见,它相当手工,无法完成。您看不到例如类继承和非导出成员。

关于c++ - 如何打开用 C++ 创建的 DLL 文件以查看类、方法和源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30379340/

相关文章:

c++ - DLL 中的 VC++ vector::push_back "Access Violation"

c++ - 在 Win 7 中从远程进程获取 PEB

c++ - 堆/堆栈上的类成员分配?

C++ 程序立即使用 2 GB RAM : how to find culprit?

android - 在 NDK 中处理 RGB_565 位图

c++ - while循环继续运行

c# - 当 64 位非托管代码通过 COM 调用托管代码时会发生什么

c++ - 为什么派生类调用基类运算符而不是自己的运算符

c++ - 在 Windows XP 上更新 MSVCRT.dll

c++ - PHP7 - 从源 x86/x64 Windows 编译