__declspec(dllexport) double Add(double a, double b) {
return a + b;
}
__declspec(dllexport) double Sub(double a, double b) {
return a - b;
}
__declspec(dllexport) double Mul(double a, double b) {
return a * b;
}
执行:
Microsoft (R) COFF/PE Dumper Version 14.10.25019.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Math.dll
File Type: DLL
Section contains the following imports:
KERNEL32.dll
1001A000 Import Address Table
1001A1D0 Import Name Table
0 time date stamp
0 Index of first forwarder reference
1A6 FreeLibrary
2A6 GetProcAddress
3B4 LoadLibraryA
212 GetCurrentProcess
5BB VirtualQuery
2AC GetProcessHeap
33F HeapFree
33B HeapAlloc
259 GetLastError
270 GetModuleHandleW
37B IsProcessorFeaturePresent
2C8 GetStartupInfoW
55B SetUnhandledExceptionFilter
59A UnhandledExceptionFilter
358 InitializeSListHead
11A DisableThreadLibraryCalls
2E1 GetSystemTimeAsFileTime
217 GetCurrentThreadId
213 GetCurrentProcessId
43E QueryPerformanceCounter
5E8 WideCharToMultiByte
3E0 MultiByteToWideChar
453 RaiseException
374 IsDebuggerPresent
579 TerminateProcess
VCRUNTIME140D.dll
1001A0A4 Import Address Table
1001A274 Import Name Table
0 time date stamp
0 Index of first forwarder reference
25 __std_type_info_destroy_list
35 _except_handler4_common
2E __vcrt_GetModuleFileNameW
2F __vcrt_GetModuleHandleW
31 __vcrt_LoadLibraryExW
48 memset
ucrtbased.dll
1001A0EC Import Address Table
1001A2BC Import Name Table
0 time date stamp
0 Index of first forwarder reference
2E1 _register_onexit_function
197 _initialize_onexit_table
196 _initialize_narrow_environment
DC _configure_narrow_argv
2ED _seh_filter_dll
8E __stdio_common_vsprintf_s
57E wcscpy_s
548 strcpy_s
19A _initterm_e
199 _initterm
15 _CrtDbgReportW
14 _CrtDbgReport
82 __stdio_common_vfprintf
45 __acrt_iob_func
3E4 _wsplitpath_s
3C8 _wmakepath_s
565 terminate
10C _execute_onexit_table
E7 _crt_at_quick_exit
544 strcat_s
E8 _crt_atexit
CA _cexit
Summary
1000 .00cfg
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
6000 .text
10000 .textbss
View Code 在上面,我们会看到很多没有用到的函数也在里面,这是因为在构建Windows DLL时,还链接了支持DLL运行的基本运行库,这个基本运行库需要用到Kerne132.dll,所有就有了这些导入函数。
在Windows中,系统的装载器会确保任何一个模块的依赖条件都得到满足,每个PE文件所依赖的文件都被加载。
在动态链接过程中,如果某一个被依赖的模块无法正确的加载,那么系统将会错误提升(比如:缺少某个DLL),并且终止运行该进程。
导入表结构体也在”Winnt.h”中:
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
union {
DWORD Characteristics; // 0 for terminating null import descriptor
DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
//导入名称表,简称INT。和IAT一样
} DUMMYUNIONNAME;
DWORD TimeDateStamp; // 0 if not bound,
// -1 if bound, and real date\time stamp
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
// O.W. date/time stamp of DLL bound to (Old BIND)
DWORD ForwarderChain; // -1 if no forwarders
DWORD Name;
DWORD FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
//指向一个导入地址数组,IAT是导入表中最重要的结构,IAT中每个元素对应一个被导入的符号,元素的值在不同情况下有不同的含义。
} IMAGE_IMPORT_DESCRIPTOR;