尝试分析隐式加载和显式加载的dll在exe中进行反汇编时的表现。
1. 测试条件
(1)动态库 testdll1 导出函数 int add(int, int) 和 int add2(int, int)
1 #pragma once
2
3 #ifdef MY_LIB_EXPORT
4 #define MY_LIB __declspec(dllexport)
5 #else
6 #define MY_LIB __declspec(dllimport)
7 #endif
8
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14
15 MY_LIB int __stdcall add(int a, int b);
16 MY_LIB int __stdcall add2(int a, int b);
17
18
19 #ifdef __cplusplus
20 }
21 #endif
(2)动态库 testdll2 导出函数 int sub(int, int)
1 #pragma once
2
3 #ifdef MY_LIB_EXPORT
4 #define MY_LIB __declspec(dllexport)
5 #else
6 #define MY_LIB __declspec(dllimport)
7 #endif
8
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14
15 MY_LIB int __stdcall add(int a, int b);
16
17 #ifdef __cplusplus
18 }
19 #endif
(3)测试进程
testdll1 隐式加载到测试进程
#pragma comment(lib, "..\\x64\\debug\\testdll1.lib")
int a = 100;
int b = 200;
int c = add(a, b);
testdll2 显式加载到测试进程
1 HMODULE hMod = LoadLibrary(TEXT("..\\x64\\debug\\testdll2.dll"));
2 sub_t func = (sub_t)GetProcAddress(hMod, "sub");
3 if (!func)
4 {
5 FreeLibrary(hMod);
6 hMod = NULL;
7 }
8 int d = func(a, b);
2、用IDA Pro打开测试进程
打开后,观察测试进程的导入表如下:

在add函数调用处下断点

在sub函数调用处下断点

启动调试,add调用处按下F7进入(step into),如下所示:
