c++ - DLL 如何解析它的 IAT?

标签 c++ windows winapi dll portable-executable

当我在我的进程中加载​​ dll 时,该 dll 如何解析它导入的函数地址? 我尝试在 GetProcAddress 和 LdrGetProcedureAddress 上设置断点,但它并没有在那里中断。

请有人解释。

最佳答案

加载 DLL 时,如果需要,加载程序将更新所有地址以反射(reflect)加载 DLL 的基地址。

http://msdn.microsoft.com/en-us/magazine/bb985014.aspx :

When creating a DLL, the linker assumes that the DLL will load at a particular address. Certain pieces of the code and data contain hardcoded addresses that are only correct if the DLL loads at the preferred address. However, at runtime it's possible that the operating system may have to load the DLL at a different memory location.

To handle the situation where the OS has to move the DLL, the linker adds base relocations to the DLL. Base relocations are addresses that require modification so that they contain the correct address for where the DLL loaded in memory. The more base relocations a DLL has, the more time the OS needs to process them and to load the DLL. A properly based DLL loads at its preferred address, and can skip processing the base relocation records.

如今,将 DLL 的基地址随机化作为一种​​安全措施更为常见,上面的文章早于此。另见:

Relocation (Wikipedia)

Portable Executable (Wikipedia)

关于c++ - DLL 如何解析它的 IAT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10677731/

相关文章:

winXP 上的 python 版本

windows - 检查 Windows API 级别的 DLL

c++ - 绘画后winapi窗口不刷新

c++ - Qt - 在两种形式之间传递数据

c++ - 引用不能为 NULL 或者它可以为 NULL?

c++ - goto 对 C++ 编译器优化的影响

c++ - 如何声明 constexpr extern?

windows - JMeter 命令行 - linux 版本 vs windows 版本

winapi - 从点开始的真实 hwnd

c++ - 如何在 Windows NT 中获取线程的动态优先级?