笔者今天来聊一下查看链接库的依赖。
通常情况下,运行一个可执行文件的时候,可能会出现找不到依赖库的情况,比如图下这种情况,可以看到是缺少了license.dll或者libtest.so,所以无法运行。怎么知道它到底缺少什么dll呢?有可能缺少不止一个dll呢?
一、PE格式下面查看依赖
1、Dependency Walker工具显示依赖
有一个工具,Dependency Walker,可以显示exe的依赖,以及dll的依赖。比如刚刚那个main.exe,可以看到缺少LICENSE.dll。
再比如:QT的一些库:Qt5SerialPort.dll,串口库,会依赖QT5CORE.dll、SETUPAPI.dll等
还比如python的库,本质上也是dll,同样可以看到依赖,缺少:Python3 和python38的dll,如下图所示。
2、PE工具读取导入表
相比上面那个工具,PE解析工具功能相关更多,可以查看DOS、NT header,section内容等。
例如section 导入表
还可以看到导入表的函数,当然导出表的函数也可以看到。
3、命令行工具dumpbin.exe
微软也提供了一个命令行工具: dumpbin.exe同样可以看到依赖。
需要输入参数 /DEPENDENTS,即可显示依赖。
查看其它功能,发现其优点与readelf文件一样,可以用来解析PE工具,其功能主要如下:
c
Microsoft (R) COFF/PE Dumper Version 14.29.30141.0
Copyright (C) Microsoft Corporation. All rights reserved.
用法: DUMPBIN [选项] [文件]
选项:
/ALL
/ARCHIVEMEMBERS
/CLRHEADER
/DEPENDENTS
/DIRECTIVES
/DISASM[:{BYTES|NOBYTES}]
/ERRORREPORT:{NONE|PROMPT|QUEUE|SEND}
/EXPORTS
/FPO
/HEADERS
/IMPORTS[:文件名]
/LINENUMBERS
/LINKERMEMBER[:{1|2|4|8|16|32}]
/LOADCONFIG
/NOLOGO
/NOPDB
/OUT:filename
/PDATA
/PDBPATH[:VERBOSE]
/RANGE:vaMin[,vaMax]
/RAWDATA[:{NONE|1|2|4|8}[,#]]
/RELOCATIONS
/SECTION:名称
/SUMMARY
/SYMBOLS
/TLS
/UNWINDINFO
比如查看导入表和导出表,dumpbin.exe /IMPORTS Qt5SerialPort.dll
可以看到其依赖了很多dll的符号。
c
Microsoft (R) COFF/PE Dumper Version 14.29.30141.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Qt5SerialPort.dll
File Type: DLL
Section contains the following imports:
Qt5Core.dll
100090CC Import Address Table
1000CBE0 Import Name Table
0 time date stamp
0 Index of first forwarder reference
BE5 ?data@QByteArray@@QAEPADXZ
A77 ?constData@QByteArray@@QBEPBDXZ
9C8 ?clear@QByteArray@@QAEXXZ
1F8 ??0QString@@QAE@$$QAV0@@Z
1F47 ?utf16@QString@@QBEPBGXZ
1D1F ?toLocal8Bit@QString@@QHAE?AVQByteArray@@XZ
C6C ?detach@QListData@@QAEPAUData@1@H@Z
C75 ?detach_grow@QListData@@QAEPAUData@1@PAHH@Z
1707 ?realloc@QListData@@QAEXH@Z
85B ?append@QListData@@QAEPAPAXXZ
A61 ?connectImpl@QObject@@CA?AVConnection@QMetaObject@@PBV1@PAPAX01PAVQSlotObjectBase@QtPrivate@@W4ConnectionType@Qt@@PBHPBU3@@Z
16FD ?readyRead@QIODevice@@QAEXXZ
92B ?bytesWritten@QIODevice@@QAEX_J@Z
16D3 ?read@QRingBuffer@@QAE?AVQByteArray@@XZ
85D ?append@QRingBuffer@@QAEXPBD_J@Z
EEF ?get@QObjectPrivate@@SAPAV1@PAVQObject@@@Z
C7 ??0QDeadlineTimer@@QAE@_JW4TimerType@Qt@@@Z
F2B ?hasExpired@QDeadlineTimer@@QBE_NXZ
1752 ?remainingTime@QDeadlineTimer@@QBE_JXZ
156 ??0QLibrary@@QAE@PAVQObject@@@Z
322 ??1QLibrary@@UAE@XZ
1826 ?resolve@QLibrary@@QAEP6AXXZPBD@Z
127A ?load@QLibrary@@QAE_NXZ
10F0 ?isLoaded@QLibrary@@QBE_NXZ
1968 ?setFileName@QLibrary@@QAEXABVQString@@@Z
DE4 ?fileName@QLibrary@@QBE?AVQString@@XZ
D70 ?errorString@QLibrary@@QBE?AVQString@@XZ
15DC ?qt_error_string@@YA?AVQString@@H@Z
129D ?lock@QMutex@@QAEXXZ
1F0B ?unlock@QMutexLocker@@QAEXXZ
23A ??0QTimer@@QAE@PAVQObject@@@Z
369 ??1QTimer@@UAE@XZ
1B55 ?start@QTimer@@QAEXXZ
1C84 ?timeout@QTimer@@QAEXUQPrivateSignal@1@@Z
3A7 ??4QByteArray@@QAEAAV0@$$QAV0@@Z
1616 ?qt_metacall@QTimer@@UAEHW4Call@QMetaObject@@HPAPAX@Z
1653 ?qt_metacast@QTimer@@UAEPAXPBD@Z
1C87 ?timerEvent@QTimer@@MAEXPAVQTimerEvent@@@Z
1AA6 ?shared_null@QListData@@2UData@1@B
1BD7 ?staticMetaObject@QTimer@@2UQMetaObject@@B
9A ??0QChar@@QAE@UQLatin1Char@@@Z
455 ??4QString@@QAEAAV0@ABV0@@Z
A79 ?constData@QString@@QBEPBVQChar@@XZ
886 ?arg@QString@@QBE?AV1@KHHVQChar@@@Z
F99 ?indexOf@QString@@QBEHVQChar@@HW4CaseSensitivity@Qt@@@Z
F9A ?indexOf@QString@@QBEHVQLatin1String@@HW4CaseSensitivity@Qt@@@Z
F94 ?indexOf@QString@@QBEHABV1@HW4CaseSensitivity@Qt@@@Z
1245 ?lastIndexOf@QString@@QBEHVQChar@@HW4CaseSensitivity@Qt@@@Z
1357 ?mid@QString@@QBE?AV1@HH@Z
1B7F ?startsWith@QString@@QBE_NVQLatin1String@@W4CaseSensitivity@Qt@@@Z
1DEA ?toUpper@QString@@QHAE?AV1@XZ
EDA ?fromWCharArray@QString@@SA?AV1@PB_WH@Z
1CFA ?toInt@QString@@QBEHPA_NH@Z
1FD ??0QString@@QAE@HW4Initialization@Qt@@@Z
869 ?appendLatin1To@QAbstractConcatenable@@KAXPBDHPAVQChar@@@Z
56 ??0QByteArray@@QAE@$$QAV0@@Z
CA5 ?dispose@QListData@@SAXPAUData@1@@Z
570 ??8@YA_NABVQString@@0@Z
1C85 ?timerEvent@QObject@@MAEXPAVQTimerEvent@@@Z
1AFC ?skip@QIODevicePrivate@@UAE_J_J@Z
1AEC ?size@QIODevice@@UBE_JXZ
18B1 ?seek@QIODevice@@UAE_N_J@Z
180F ?reset@QIODevice@@UAE_NXZ
1535 ?putCharHelper@QIODevicePrivate@@UAE_ND@Z
14B5 ?pos@QIODevice@@UBE_JXZ
148F ?peek@QIODevicePrivate@@UAE_JPAD_J@Z
148E ?peek@QIODevicePrivate@@UAE?AVQByteArray@@_J@Z
D9B ?eventFilter@QObject@@UAE_NPAV1@PAVQEvent@@@Z
D89 ?event@QObject@@UAE_NPAVQEvent@@@Z
C9A ?disconnectNotify@QObject@@MAEXABVQMetaMethod@@@Z
133A ?metaObject@QTimer@@UBEPBUQMetaObject@@XZ
2C3 ??1Connection@QMetaObject@@QAE@XZ
B62 ?customEvent@QObject@@MAEXPAVQEvent@@@Z
A65 ?connectNotify@QObject@@MAEXABVQMetaMethod@@@Z
9A9 ?childEvent@QObject@@MAEXPAVQChildEvent@@@Z
316 ??1QIODevicePrivate@@UAE@XZ
11B ??0QIODevicePrivate@@QAE@XZ
9D0 ?clear@QRingBuffer@@QAEXXZ
1955 ?setErrorString@QIODevice@@IAEXABVQString@@@Z
16EE ?readLineData@QIODevice@@MAE_JPAD_J@Z
118 ??0QIODevice@@IAE@AAVQIODevicePrivate@@PAVQObject@@@Z
944 ?canReadLine@QIODevice@@UBE_NXZ
927 ?bytesToWrite@QIODevice@@UBE_JXZ
922 ?bytesAvailable@QIODevice@@UBE_JXZ
8AA ?atEnd@QIODevice@@UBE_NXZ
9ED ?close@QIODevice@@UAEXXZ
1444 ?open@QIODevice@@UAE_NV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z
1149 ?isReadable@QIODevice@@QBE_NXZ
1132 ?isOpen@QIODevice@@QBE_NXZ
315 ??1QIODevice@@UAE@XZ
15FA ?qt_metacall@QIODevice@@UAEHW4Call@QMetaObject@@HPAPAX@Z
1637 ?qt_metacast@QIODevice@@UAEPAXPBD@Z
CCB ?dynamicMetaObject@QObjectData@@QBEPAUQMetaObject@@XZ
1126 ?isNull@QString@@QBE_NXZ
453 ??4QString@@QAEAAV0@$$QAV0@@Z
356 ??1QString@@QAE@XZ
1FA ??0QString@@QAE@ABV0@@Z
203 ??0QString@@QAE@XZ
2E0 ??1QByteArray@@QAE@XZ
58 ??0QByteArray@@QAE@HD@Z
5C ??0QByteArray@@QAE@XZ
7BA ?activate@QMetaObject@@SAXPAVQObject@@PBU1@HPAPAX@Z
1E38 ?tr@QMetaObject@@QBE?AVQString@@PBD0H@Z
1F9D ?warning@QMessageLogger@@QBAXPBDZZ
16B ??0QMessageLogger@@QAE@PBDH0@Z
4B ??0QBasicMutex@@QAE@XZ
1BB8 ?staticMetaObject@QIODevice@@2UQMetaObject@@B
SETUPAPI.dll
1000927C Import Address Table
1000CD90 Import Name Table
0 time date stamp
0 Index of first forwarder reference
80 CM_Get_Parent
52 CM_Get_DevNode_Status
55 CM_Get_Device_IDW
172 SetupDiGetDeviceRegistryPropertyW
191 SetupDiOpenDevRegKey
154 SetupDiGetClassDevsW
13D SetupDiDestroyDeviceInfoList
140 SetupDiEnumDeviceInfo
ADVAPI32.dll
10009000 Import Address Table
1000CB14 Import Name Table
0 time date stamp
0 Index of first forwarder reference
25B RegCloseKey
28C RegOpenKeyExW
299 RegQueryValueExW
27D RegEnumValueW
MSVCP140.dll
100090C4 Import Address Table
1000CBD8 Import Name Table
0 time date stamp
0 Index of first forwarder reference
28E ?_Xlength_error@std@@YAXPBD@Z
KERNEL32.dll
10009014 Import Address Table
1000CB28 Import Name Table
0 time date stamp
0 Index of first forwarder reference
BF CreateEventW
5D8 WaitForSingleObjectEx
4C6 ResetEvent
516 SetEvent
110 DeleteCriticalSection
35F InitializeCriticalSectionAndSpinCount
3BD LeaveCriticalSection
131 EnterCriticalSection
4E1 SetCommTimeouts
4E0 SetCommState
4DF SetCommMask
4DD SetCommBreak
43E PurgeComm
1D5 GetCommTimeouts
2AE GetProcAddress
1D2 GetCommModemStatus
15D EscapeCommFunction
84 ClearCommError
83 ClearCommBreak
57D Sleep
580 SleepEx
72 CancelIoEx
11D DeviceIoControl
532 SetLastError
261 GetLastError
86 CloseHandle
613 WriteFileEx
474 ReadFileEx
CB CreateFileW
278 GetModuleHandleW
37F IsDebuggerPresent
5AD UnhandledExceptionFilter
1D4 GetCommState
386 IsProcessorFeaturePresent
217 GetCurrentProcess
58C TerminateProcess
44D QueryPerformanceCounter
218 GetCurrentProcessId
21C GetCurrentThreadId
2E9 GetSystemTimeAsFileTime
11E DisableThreadLibraryCalls
363 InitializeSListHead
56D SetUnhandledExceptionFilter
VCRUNTIME140.dll
100092A0 Import Address Table
1000CDB4 Import Name Table
0 time date stamp
0 Index of first forwarder reference
46 memcpy
1 _CxxThrowException
10 __CxxFrameHandler3
47 memmove
21 __std_exception_copy
22 __std_exception_destroy
48 memset
35 _except_handler4_common
25 __std_type_info_destroy_list
api-ms-win-crt-runtime-l1-1-0.dll
100092D8 Import Address Table
1000CDEC Import Name Table
0 time date stamp
0 Index of first forwarder reference
19 _configure_narrow_argv
35 _initialize_narrow_environment
36 _initialize_onexit_table
41 _seh_filter_dll
24 _execute_onexit_table
1F _crt_atexit
17 _cexit
38 _initterm
39 _initterm_e
3E _register_onexit_function
3B _invalid_parameter_noinfo_noreturn
api-ms-win-crt-heap-l1-1-0.dll
100092C8 Import Address Table
1000CDDC Import Name Table
0 time date stamp
0 Index of first forwarder reference
8 _callnewh
19 malloc
18 free
Summary
1000 .data
6000 .rdata
1000 .reloc
1000 .rsrc
8000 .text
查看导出表,dumpbin.exe /EXPORTS Qt5SerialPort.dll
Microsoft (R) COFF/PE Dumper Version 14.29.30141.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Qt5SerialPort.dll
File Type: DLL
Section contains the following exports for Qt5SerialPort.dll
00000000 characteristics
FFFFFFFF time date stamp
0.00 version
1 ordinal base
95 number of functions
95 number of names
ordinal hint RVA name
1 0 00001010 ??0QSerialPort@@QAE@ABVQSerialPortInfo@@PAVQObject@@@Z
2 1 00001080 ??0QSerialPort@@QAE@ABVQString@@PAVQObject@@@Z
3 2 000010F0 ??0QSerialPort@@QAE@PAVQObject@@@Z
4 3 00002AD0 ??0QSerialPortInfo@@AAE@ABVQSerialPortInfoPrivate@@@Z
5 4 00002AF0 ??0QSerialPortInfo@@QAE@ABV0@@Z
6 5 00002B30 ??0QSerialPortInfo@@QAE@ABVQSerialPort@@@Z
7 6 00002B60 ??0QSerialPortInfo@@QAE@ABVQString@@@Z
8 7 00002D70 ??0QSerialPortInfo@@QAE@XZ
9 8 00001350 ??1QSerialPort@@UAE@XZ
10 9 00002DF0 ??1QSerialPortInfo@@QAE@XZ
11 A 00002E30 ??4QSerialPortInfo@@QAEAAV0@ABV0@@Z
12 B 0000A524 ??_7QSerialPort@@6B@
13 C 00001410 ??_FQSerialPort@@QAEXXZ
14 D 000014A0 ?atEnd@QSerialPort@@UBE_NXZ
15 E 00006220 ?availablePorts@QSerialPortInfo@@SA?AV?$QList@VQSerialPortInfo@@@@XZ
16 F 000014B0 ?baudRate@QSerialPort@@QBEHV?$QFlags@W4Direction@QSerialPort@@@@@Z
17 10 000014F0 ?baudRateChanged@QSerialPort@@QAEXHV?$QFlags@W4Direction@QSerialPort@@@@@Z
18 11 00001540 ?breakEnabledChanged@QSerialPort@@QAEX_N@Z
19 12 00001570 ?bytesAvailable@QSerialPort@@UBE_JXZ
20 13 00001580 ?bytesToWrite@QSerialPort@@UBE_JXZ
21 14 000015B0 ?canReadLine@QSerialPort@@UBE_NXZ
22 15 000015C0 ?clear@QSerialPort@@QAE_NV?$QFlags@W4Direction@QSerialPort@@@@@Z
23 16 00001670 ?clearError@QSerialPort@@QAEXXZ
24 17 000016B0 ?close@QSerialPort@@UAEXXZ
25 18 00001720 ?d_func@QSerialPort@@AAEPAVQSerialPortPrivate@@XZ
26 19 00001720 ?d_func@QSerialPort@@ABEPBVQSerialPortPrivate@@XZ
27 1A 00001730 ?d_func@QSerialPortInfo@@AAEPAVQSerialPortInfoPrivate@@XZ
28 1B 00001730 ?d_func@QSerialPortInfo@@ABEPBVQSerialPortInfoPrivate@@XZ
29 1C 00001740 ?dataBits@QSerialPort@@QBE?AW4DataBits@1@XZ
30 1D 00001750 ?dataBitsChanged@QSerialPort@@QAEXW4DataBits@1@@Z
31 1E 00001780 ?dataErrorPolicy@QSerialPort@@QBE?AW4DataErrorPolicy@1@XZ
32 1F 00001790 ?dataErrorPolicyChanged@QSerialPort@@QAEXW4DataErrorPolicy@1@@Z
33 20 000017C0 ?dataTerminalReadyChanged@QSerialPort@@QAEX_N@Z
34 21 00002EA0 ?description@QSerialPortInfo@@QBE?AVQString@@XZ
35 22 000017F0 ?error@QSerialPort@@QAEXW4SerialPortError@1@@Z
36 23 00001820 ?error@QSerialPort@@QBE?AW4SerialPortError@1@XZ
37 24 00001830 ?errorOccurred@QSerialPort@@QAEXW4SerialPortError@1@@Z
38 25 00001860 ?flowControl@QSerialPort@@QBE?AW4FlowControl@1@XZ
39 26 00001870 ?flowControlChanged@QSerialPort@@QAEXW4FlowControl@1@@Z
40 27 000018A0 ?flush@QSerialPort@@QAE_NXZ
41 28 00003BF0 ?handle@QSerialPort@@QBEPAXXZ
42 29 00002F10 ?hasProductIdentifier@QSerialPortInfo@@QBE_NXZ
43 2A 00002F20 ?hasVendorIdentifier@QSerialPortInfo@@QBE_NXZ
44 2B 00001920 ?isBreakEnabled@QSerialPort@@QBE_NXZ
45 2C 000072C0 ?isBusy@QSerialPortInfo@@QBE_NXZ
46 2D 00001930 ?isDataTerminalReady@QSerialPort@@QAE_NXZ
47 2E 00001950 ?isNull@QSerialPortInfo@@QBE_NXZ
48 2F 00001960 ?isRequestToSend@QSerialPort@@QAE_NXZ
49 30 00001980 ?isSequential@QSerialPort@@UBE_NXZ
50 31 00007320 ?isValid@QSerialPortInfo@@QBE_NXZ
51 32 00002F30 ?manufacturer@QSerialPortInfo@@QBE?AVQString@@XZ
52 33 00001990 ?metaObject@QSerialPort@@UBEPBUQMetaObject@@XZ
53 34 000019B0 ?open@QSerialPort@@UAE_NV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z
54 35 00001AC0 ?parity@QSerialPort@@QBE?AW4Parity@1@XZ
55 36 00001AD0 ?parityChanged@QSerialPort@@QAEXW4Parity@1@@Z
56 37 00001B00 ?pinoutSignals@QSerialPort@@QAE?AV?$QFlags@W4PinoutSignal@QSerialPort@@@@XZ
57 38 00001B90 ?portName@QSerialPort@@QBE?AVQString@@XZ
58 39 00002FA0 ?portName@QSerialPortInfo@@QBE?AVQString@@XZ
59 3A 00003000 ?productIdentifier@QSerialPortInfo@@QBEGXZ
60 3B 00001BB0 ?qt_metacall@QSerialPort@@UAEHW4Call@QMetaObject@@HPAPAX@Z
61 3C 00001C70 ?qt_metacast@QSerialPort@@UAEPAXPBD@Z
62 3D 00001CD0 ?qt_static_metacall@QSerialPort@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z
63 3E 00002110 ?readBufferSize@QSerialPort@@QBE_JXZ
64 3F 00002120 ?readData@QSerialPort@@MAE_JPAD_J@Z
65 40 00002130 ?readLineData@QSerialPort@@MAE_JPAD_J@Z
66 41 00002150 ?requestToSendChanged@QSerialPort@@QAEX_N@Z
67 42 00002180 ?sendBreak@QSerialPort@@QAE_NH@Z
68 43 00003010 ?serialNumber@QSerialPortInfo@@QBE?AVQString@@XZ
69 44 00002210 ?setBaudRate@QSerialPort@@QAE_NHV?$QFlags@W4Direction@QSerialPort@@@@@Z
70 45 000022F0 ?setBreakEnabled@QSerialPort@@QAE_N_N@Z
71 46 000023D0 ?setDataBits@QSerialPort@@QAE_NW4DataBits@1@@Z
72 47 00002450 ?setDataErrorPolicy@QSerialPort@@QAE_NW4DataErrorPolicy@1@@Z
73 48 00002520 ?setDataTerminalReady@QSerialPort@@QAE_N_N@Z
74 49 00002690 ?setFlowControl@QSerialPort@@QAE_NW4FlowControl@1@@Z
75 4A 00002710 ?setParity@QSerialPort@@QAE_NW4Parity@1@@Z
76 4B 00002790 ?setPort@QSerialPort@@QAEXABVQSerialPortInfo@@@Z
77 4C 000027C0 ?setPortName@QSerialPort@@QAEXABVQString@@@Z
78 4D 000027F0 ?setReadBufferSize@QSerialPort@@QAEX_J@Z
79 4E 00002820 ?setRequestToSend@QSerialPort@@QAE_N_N@Z
80 4F 00002920 ?setSettingsRestoredOnClose@QSerialPort@@QAEX_N@Z
81 50 00002970 ?setStopBits@QSerialPort@@QAE_NW4StopBits@1@@Z
82 51 000029F0 ?settingsRestoredOnClose@QSerialPort@@QBE_NXZ
83 52 00002A00 ?settingsRestoredOnCloseChanged@QSerialPort@@QAEX_N@Z
84 53 00003080 ?standardBaudRates@QSerialPortInfo@@SA?AV?$QList@H@@XZ
85 54 0000F000 ?staticMetaObject@QSerialPort@@2UQMetaObject@@B
86 55 00002A30 ?stopBits@QSerialPort@@QBE?AW4StopBits@1@XZ
87 56 00002A40 ?stopBitsChanged@QSerialPort@@QAEXW4StopBits@1@@Z
88 57 000030A0 ?swap@QSerialPortInfo@@QAEXAAV1@@Z
89 58 000030C0 ?systemLocation@QSerialPortInfo@@QBE?AVQString@@XZ
90 59 00002A70 ?tr@QSerialPort@@SA?AVQString@@PBD0H@Z
91 5A 00002A70 ?trUtf8@QSerialPort@@SA?AVQString@@PBD0H@Z
92 5B 00003130 ?vendorIdentifier@QSerialPortInfo@@QBEGXZ
93 5C 00002A90 ?waitForBytesWritten@QSerialPort@@UAE_NH@Z
94 5D 00002AA0 ?waitForReadyRead@QSerialPort@@UAE_NH@Z
95 5E 00002AB0 ?writeData@QSerialPort@@MAE_JPBD_J@Z
Summary
1000 .data
6000 .rdata
1000 .reloc
1000 .rsrc
8000 .text
4、命令行工具 objdump
objdump工具可以解析PE格式,提取header信息,以及导入导出表等信息。
$ objdump
Usage: C:\MinGW\bin\objdump.exe <option(s)> <file(s)>
Display information from object <file(s)>.
At least one of the following switches must be given:
-a, --archive-headers Display archive header information
-f, --file-headers Display the contents of the overall file header
-p, --private-headers Display object format specific file header contents
-P, --private=OPT,OPT... Display object format specific contents
-h, --[section-]headers Display the contents of the section headers
-x, --all-headers Display the contents of all headers
-d, --disassemble Display assembler contents of executable sections
-D, --disassemble-all Display assembler contents of all sections
-S, --source Intermix source code with disassembly
-s, --full-contents Display the full contents of all sections requested
-g, --debugging Display debug information in object file
-e, --debugging-tags Display debug information using ctags style
-G, --stabs Display (in raw form) any STABS info in the file
-W[lLiaprmfFsoRt] or
--dwarf[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,
=frames-interp,=str,=loc,=Ranges,=pubtypes,
=gdb_index,=trace_info,=trace_abbrev,=trace_aranges,
=addr,=cu_index]
Display DWARF info in the file
-t, --syms Display the contents of the symbol table(s)
-T, --dynamic-syms Display the contents of the dynamic symbol table
-r, --reloc Display the relocation entries in the file
-R, --dynamic-reloc Display the dynamic relocation entries in the file
@<file> Read options from <file>
-v, --version Display this program's version number
-i, --info List object formats and architectu
比如导入表信息,可以看到依赖的库信息。
D:\个人资料\OD\license_study>objdump -p main.exe
There is an import table in .idata at 0x408000
The Import Tables (interpreted .idata section contents)
vma: Hint Time Forward DLL First
Table Stamp Chain Name Thunk
00008000 00008064 00000000 00000000 00008568 0000814c
DLL Name: KERNEL32.dll
vma: Hint/Ord Member-Name Bound-To
8234 207 DeleteCriticalSection
824c 236 EnterCriticalSection
8264 279 ExitProcess
8272 300 FindClose
827e 304 FindFirstFileA
8290 321 FindNextFileA
82a0 352 FreeLibrary
82ae 388 GetCommandLineA
82c0 510 GetLastError
82d0 529 GetModuleHandleA
82e4 577 GetProcAddress
82f6 734 InitializeCriticalSection
8312 814 LeaveCriticalSection
832a 817 LoadLibraryA
833a 1140 SetUnhandledExceptionFilter
8358 1173 TlsGetValue
8366 1213 VirtualProtect
8378 1215 VirtualQuery
00008014 000080b0 00000000 00000000 00008580 00008198
DLL Name: msvcrt.dll
vma: Hint/Ord Member-Name Bound-To
8388 80 _strdup
8392 82 _stricoll
00008028 000080bc 00000000 00000000 00008610 000081a4
DLL Name: msvcrt.dll
vma: Hint/Ord Member-Name Bound-To
839e 88 __getmainargs
83ae 119 __mb_cur_max
83be 131 __p__environ
83ce 133 __p__fmode
83dc 153 __set_app_type
83ee 219 _cexit
83f8 285 _errno
8402 324 _fpreset
840e 350 _fullpath
841a 417 _iob
8422 422 _isctype
842e 689 _onexit
8438 698 _pctype
8442 753 _setmode
844e 1083 abort
8456 1091 atexit
8460 1098 calloc
846a 1131 free
8472 1142 fwrite
847c 1187 malloc
8486 1194 mbstowcs
8492 1199 memcpy
849c 1208 printf
84a6 1211 putchar
84b0 1212 puts
84b8 1220 realloc
84c2 1227 setlocale
84ce 1229 signal
84d8 1242 strcoll
84e2 1249 strlen
84ec 1277 tolower
84f6 1284 vfprintf
8502 1325 wcstombs
0000803c 00008144 00000000 00000000 00008620 0000822c
DLL Name: license.dll
vma: Hint/Ord Member-Name Bound-To
8510 0 get_license
00008050 00000000 00000000 00000000 00000000 00000000
看到header信息
main.exe: file format pei-i386
Characteristics 0x107
relocations stripped
executable
line numbers stripped
32 bit words
Time/Date Tue Feb 06 15:38:57 2024
Magic 010b (PE32)
MajorLinkerVersion 2
MinorLinkerVersion 28
SizeOfCode 00003000
SizeOfInitializedData 00004e00
SizeOfUninitializedData 00000200
AddressOfEntryPoint 000012e0
BaseOfCode 00001000
BaseOfData 00004000
ImageBase 00400000
SectionAlignment 00001000
FileAlignment 00000200
MajorOSystemVersion 4
MinorOSystemVersion 0
MajorImageVersion 1
MinorImageVersion 0
MajorSubsystemVersion 4
MinorSubsystemVersion 0
Win32Version 00000000
SizeOfImage 00011000
SizeOfHeaders 00000400
CheckSum 00013a06
Subsystem 00000003 (Windows CUI)
DllCharacteristics 00000000
SizeOfStackReserve 00200000
SizeOfStackCommit 00001000
SizeOfHeapReserve 00100000
SizeOfHeapCommit 00001000
LoaderFlags 00000000
NumberOfRvaAndSizes 00000010
二、ELF格式下面查看依赖
1、readelf工具
比如刚刚那个a.out文件,可以通过readelf 可以查看依赖,方便定位问题。
readelf -d xxxx.elf 文件,-d用来显示动态的section,即依赖的动态链接库。
示例操作:可以看到a.out除了依赖libtest.so,还依赖libc库。
readelf 这个工具是命令行工具,用来解析elf文件格式,linux下面也可以使用。
2、objdump工具
windows下面解析PE格式文件,linux下面解析elf文件格式,很方便的跨平台工具,windows下面mingw的一个工具。
当然同elf文件一样,也可以解析header,symbol,section等信息。
c
a.out: file format elf64-little
a.out
architecture: UNKNOWN!, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000400810
Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3
filesz 0x0000000000000188 memsz 0x0000000000000188 flags r-x
INTERP off 0x00000000000001c8 vaddr 0x00000000004001c8 paddr 0x00000000004001c8 align 2**0
filesz 0x000000000000001b memsz 0x000000000000001b flags r--
LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**16
filesz 0x0000000000000a7c memsz 0x0000000000000a7c flags r-x
LOAD off 0x0000000000000a80 vaddr 0x0000000000410a80 paddr 0x0000000000410a80 align 2**16
filesz 0x0000000000000278 memsz 0x00000000000002c0 flags rw-
DYNAMIC off 0x0000000000000a98 vaddr 0x0000000000410a98 paddr 0x0000000000410a98 align 2**3
filesz 0x00000000000001e0 memsz 0x00000000000001e0 flags rw-
NOTE off 0x00000000000001e4 vaddr 0x00000000004001e4 paddr 0x00000000004001e4 align 2**2
filesz 0x0000000000000044 memsz 0x0000000000000044 flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
Dynamic Section:
NEEDED libtest.so
NEEDED libc.so.6
INIT 0x0000000000400740
FINI 0x0000000000400a40
INIT_ARRAY 0x0000000000410a80
INIT_ARRAYSZ 0x0000000000000008
FINI_ARRAY 0x0000000000410a88
FINI_ARRAYSZ 0x0000000000000008
HASH 0x0000000000400228
STRTAB 0x00000000004004e0
SYMTAB 0x00000000004002d0
STRSZ 0x0000000000000123
SYMENT 0x0000000000000018
DEBUG 0x0000000000000000
PLTGOT 0x0000000000410c88
PLTRELSZ 0x00000000000000d8
PLTREL 0x0000000000000007
JMPREL 0x0000000000400668
RELA 0x0000000000400650
RELASZ 0x0000000000000018
RELAENT 0x0000000000000018
VERNEED 0x0000000000400630
VERNEEDNUM 0x0000000000000001
VERSYM 0x0000000000400604
Version References:
required from libc.so.6:
0x06969197 0x00 02 GLIBC_2.17
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001b 00000000004001c8 00000000004001c8 000001c8 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 00000000004001e4 00000000004001e4 000001e4 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 0000000000400204 0000000000400204 00000204 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .hash 000000a4 0000000000400228 0000000000400228 00000228 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .dynsym 00000210 00000000004002d0 00000000004002d0 000002d0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .dynstr 00000123 00000000004004e0 00000000004004e0 000004e0 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .gnu.version 0000002c 0000000000400604 0000000000400604 00000604 2**1
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .gnu.version_r 00000020 0000000000400630 0000000000400630 00000630 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .rela.dyn 00000018 0000000000400650 0000000000400650 00000650 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .rela.plt 000000d8 0000000000400668 0000000000400668 00000668 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .init 00000014 0000000000400740 0000000000400740 00000740 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
11 .plt 000000b0 0000000000400760 0000000000400760 00000760 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .text 00000230 0000000000400810 0000000000400810 00000810 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
13 .fini 00000010 0000000000400a40 0000000000400a40 00000a40 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
14 .rodata 00000028 0000000000400a50 0000000000400a50 00000a50 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .eh_frame 00000004 0000000000400a78 0000000000400a78 00000a78 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .init_array 00000008 0000000000410a80 0000000000410a80 00000a80 2**3
CONTENTS, ALLOC, LOAD, DATA
17 .fini_array 00000008 0000000000410a88 0000000000410a88 00000a88 2**3
CONTENTS, ALLOC, LOAD, DATA
18 .jcr 00000008 0000000000410a90 0000000000410a90 00000a90 2**3
CONTENTS, ALLOC, LOAD, DATA
19 .dynamic 000001e0 0000000000410a98 0000000000410a98 00000a98 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .got 00000010 0000000000410c78 0000000000410c78 00000c78 2**3
CONTENTS, ALLOC, LOAD, DATA
21 .got.plt 00000060 0000000000410c88 0000000000410c88 00000c88 2**3
CONTENTS, ALLOC, LOAD, DATA
22 .data 00000010 0000000000410ce8 0000000000410ce8 00000ce8 2**3
CONTENTS, ALLOC, LOAD, DATA
23 .bss 00000048 0000000000410cf8 0000000000410cf8 00000cf8 2**3
ALLOC
24 .comment 0000002f 0000000000000000 0000000000000000 00000cf8 2**0
CONTENTS, READONLY
25 .debug_aranges 00000110 0000000000000000 0000000000000000 00000d30 2**4
CONTENTS, READONLY, DEBUGGING
26 .debug_info 00000452 0000000000000000 0000000000000000 00000e40 2**0
CONTENTS, READONLY, DEBUGGING
27 .debug_abbrev 00000183 0000000000000000 0000000000000000 00001292 2**0
CONTENTS, READONLY, DEBUGGING
28 .debug_line 0000028a 0000000000000000 0000000000000000 00001415 2**0
CONTENTS, READONLY, DEBUGGING
29 .debug_frame 00000068 0000000000000000 0000000000000000 000016a0 2**3
CONTENTS, READONLY, DEBUGGING
30 .debug_str 0000026c 0000000000000000 0000000000000000 00001708 2**0
CONTENTS, READONLY, DEBUGGING
31 .debug_loc 00000143 0000000000000000 0000000000000000 00001974 2**0
CONTENTS, READONLY, DEBUGGING
32 .debug_ranges 000000d0 0000000000000000 0000000000000000 00001ac0 2**4
CONTENTS, READONLY, DEBUGGING
SYMBOL TABLE:
00000000004001c8 l d .interp 0000000000000000 .interp
00000000004001e4 l d .note.ABI-tag 0000000000000000 .note.ABI-tag
0000000000400204 l d .note.gnu.build-id 0000000000000000 .note.gnu.build-id
0000000000400228 l d .hash 0000000000000000 .hash
00000000004002d0 l d .dynsym 0000000000000000 .dynsym
00000000004004e0 l d .dynstr 0000000000000000 .dynstr
0000000000400604 l d .gnu.version 0000000000000000 .gnu.version
0000000000400630 l d .gnu.version_r 0000000000000000 .gnu.version_r
0000000000400650 l d .rela.dyn 0000000000000000 .rela.dyn
0000000000400668 l d .rela.plt 0000000000000000 .rela.plt
0000000000400740 l d .init 0000000000000000 .init
0000000000400760 l d .plt 0000000000000000 .plt
0000000000400810 l d .text 0000000000000000 .text
0000000000400a40 l d .fini 0000000000000000 .fini
0000000000400a50 l d .rodata 0000000000000000 .rodata
0000000000400a78 l d .eh_frame 0000000000000000 .eh_frame
0000000000410a80 l d .init_array 0000000000000000 .init_array
0000000000410a88 l d .fini_array 0000000000000000 .fini_array
0000000000410a90 l d .jcr 0000000000000000 .jcr
0000000000410a98 l d .dynamic 0000000000000000 .dynamic
0000000000410c78 l d .got 0000000000000000 .got
0000000000410c88 l d .got.plt 0000000000000000 .got.plt
0000000000410ce8 l d .data 0000000000000000 .data
0000000000410cf8 l d .bss 0000000000000000 .bss
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000000 l d .debug_aranges 0000000000000000 .debug_aranges
0000000000000000 l d .debug_info 0000000000000000 .debug_info
0000000000000000 l d .debug_abbrev 0000000000000000 .debug_abbrev
0000000000000000 l d .debug_line 0000000000000000 .debug_line
0000000000000000 l d .debug_frame 0000000000000000 .debug_frame
0000000000000000 l d .debug_str 0000000000000000 .debug_str
0000000000000000 l d .debug_loc 0000000000000000 .debug_loc
0000000000000000 l d .debug_ranges 0000000000000000 .debug_ranges
0000000000000000 l df *ABS* 0000000000000000 /home/tcwg-buildslave/workspace/tcwg-make-release/label/tcwg-x86_64-ex40/target/aarch64-linux-gnu/_build/builds/x86_64-unknown-linux-gnu/aarch64-linux-gnu/glibc.git~release-2.21-master/csu/abi-note.o
00000000004001e4 l .note.ABI-tag 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 /home/tcwg-buildslave/workspace/tcwg-make-release/label/tcwg-x86_64-ex40/target/aarch64-linux-gnu/_build/builds/x86_64-unknown-linux-gnu/aarch64-linux-gnu/glibc.git~release-2.21-master/csu/start.o
0000000000400810 l .text 0000000000000000 $x
000000000040083c l .text 0000000000000000 $d
000000000000000c l .debug_aranges 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 init.c
0000000000400a50 l .rodata 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 /home/guoqing.zhang/gcc-linaro-5.2-2015.11-2-x86_64_aarch64-linux-gnu/bin/../aarch64-linux-gnu/libc/usr/lib/crti.o
0000000000400858 l .text 0000000000000000 $x
0000000000400858 l F .text 0000000000000014 call_weak_fn
0000000000400740 l .init 0000000000000000 $x
0000000000400a40 l .fini 0000000000000000 $x
000000000000005c l .debug_aranges 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 /home/guoqing.zhang/gcc-linaro-5.2-2015.11-2-x86_64_aarch64-linux-gnu/bin/../aarch64-linux-gnu/libc/usr/lib/crtn.o
000000000040074c l .init 0000000000000000 $x
0000000000400a48 l .fini 0000000000000000 $x
00000000000000dc l .debug_aranges 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 crtstuff.c
0000000000410a90 l O .jcr 0000000000000000 __JCR_LIST__
0000000000400870 l .text 0000000000000000 $x
0000000000400870 l F .text 0000000000000000 deregister_tm_clones
00000000004008a8 l .text 0000000000000000 $d
00000000004008b0 l .text 0000000000000000 $x
00000000004008b0 l F .text 0000000000000000 register_tm_clones
00000000004008e8 l .text 0000000000000000 $d
0000000000410cf0 l .data 0000000000000000 $d
00000000004008f0 l .text 0000000000000000 $x
00000000004008f0 l F .text 0000000000000000 __do_global_dtors_aux
0000000000410cf8 l O .bss 0000000000000001 completed.7262
0000000000410a88 l .fini_array 0000000000000000 $d
0000000000410a88 l O .fini_array 0000000000000000 __do_global_dtors_aux_fini_array_entry
0000000000400920 l F .text 0000000000000000 frame_dummy
0000000000400958 l .text 0000000000000000 $d
0000000000410a80 l .init_array 0000000000000000 $d
0000000000410a80 l O .init_array 0000000000000000 __frame_dummy_init_array_entry
0000000000410cf8 l .bss 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 hello.c
0000000000400a58 l .rodata 0000000000000000 $d
0000000000400960 l .text 0000000000000000 $x
0000000000000000 l df *ABS* 0000000000000000 elf-init.c
00000000004009c0 l .text 0000000000000000 $x
0000000000000010 l .debug_frame 0000000000000000 $d
0000000000000000 l df *ABS* 0000000000000000 crtstuff.c
0000000000400a78 l .eh_frame 0000000000000000 $d
0000000000400a78 l O .eh_frame 0000000000000000 __FRAME_END__
0000000000410a90 l .jcr 0000000000000000 $d
0000000000410a90 l O .jcr 0000000000000000 __JCR_END__
0000000000000000 l df *ABS* 0000000000000000
0000000000410a88 l .init_array 0000000000000000 __init_array_end
0000000000410a98 l O .dynamic 0000000000000000 _DYNAMIC
0000000000410a80 l .init_array 0000000000000000 __init_array_start
0000000000410c78 l O .got 0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000400780 l .plt 0000000000000000 $x
0000000000400a38 g F .text 0000000000000004 __libc_csu_fini
0000000000000000 w *UND* 0000000000000000 _ITM_deregisterTMCloneTable
0000000000410ce8 w .data 0000000000000000 data_start
0000000000410cf8 g .bss 0000000000000000 __bss_start__
0000000000410d40 g .bss 0000000000000000 _bss_end__
0000000000410cf8 g .data 0000000000000000 _edata
0000000000400a40 g F .fini 0000000000000000 _fini
0000000000410d40 g .bss 0000000000000000 __bss_end__
0000000000400780 F *UND* 0000000000000000 __libc_start_main@@GLIBC_2.17
0000000000400790 F *UND* 0000000000000000 test_func
0000000000410ce8 g .data 0000000000000000 __data_start
00000000004007a0 F *UND* 0000000000000000 pthread_mutex_init@@GLIBC_2.17
0000000000000000 w *UND* 0000000000000000 __gmon_start__
0000000000410cf0 g O .data 0000000000000000 .hidden __dso_handle
00000000004007c0 F *UND* 0000000000000000 abort@@GLIBC_2.17
0000000000400a50 g O .rodata 0000000000000004 _IO_stdin_used
0000000000410d00 g O .bss 0000000000000040 data
00000000004007d0 F *UND* 0000000000000000 puts@@GLIBC_2.17
00000000004009c0 g F .text 0000000000000078 __libc_csu_init
0000000000410d40 g .bss 0000000000000000 _end
0000000000400810 g F .text 0000000000000000 _start
0000000000410d40 g .bss 0000000000000000 __end__
0000000000410cf8 g .bss 0000000000000000 __bss_start
0000000000400960 g F .text 0000000000000060 main
0000000000000000 w *UND* 0000000000000000 _Jv_RegisterClasses
0000000000410cf8 g O .data 0000000000000000 .hidden __TMC_END__
0000000000000000 w *UND* 0000000000000000 _ITM_registerTMCloneTable
00000000004007e0 F *UND* 0000000000000000 printf@@GLIBC_2.17
00000000004007f0 F *UND* 0000000000000000 pthread_mutex_lock@@GLIBC_2.17
0000000000400740 g F .init 0000000000000000 _init
0000000000400800 F *UND* 0000000000000000 pthread_mutex_unlock@@GLIBC_2.17