笔者今天来聊一下查看链接库的依赖。
通常情况下,运行一个可执行文件的时候,可能会出现找不到依赖库的情况,比如图下这种情况,可以看到是缺少了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工具,其功能主要如下:
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的符号。
Microsoft (R) COFF/PE Dumper Version 14.29.30141.0
Copyright (C) Microsoft Corporation. All rights reserved.Dump of file Qt5SerialPort.dllFile Type: DLLSection contains the following imports:Qt5Core.dll100090CC Import Address Table1000CBE0 Import Name Table0 time date stamp0 Index of first forwarder referenceBE5 ?data@QByteArray@@QAEPADXZA77 ?constData@QByteArray@@QBEPBDXZ9C8 ?clear@QByteArray@@QAEXXZ1F8 ??0QString@@QAE@$$QAV0@@Z1F47 ?utf16@QString@@QBEPBGXZ1D1F ?toLocal8Bit@QString@@QHAE?AVQByteArray@@XZC6C ?detach@QListData@@QAEPAUData@1@H@ZC75 ?detach_grow@QListData@@QAEPAUData@1@PAHH@Z1707 ?realloc@QListData@@QAEXH@Z85B ?append@QListData@@QAEPAPAXXZA61 ?connectImpl@QObject@@CA?AVConnection@QMetaObject@@PBV1@PAPAX01PAVQSlotObjectBase@QtPrivate@@W4ConnectionType@Qt@@PBHPBU3@@Z16FD ?readyRead@QIODevice@@QAEXXZ92B ?bytesWritten@QIODevice@@QAEX_J@Z16D3 ?read@QRingBuffer@@QAE?AVQByteArray@@XZ85D ?append@QRingBuffer@@QAEXPBD_J@ZEEF ?get@QObjectPrivate@@SAPAV1@PAVQObject@@@ZC7 ??0QDeadlineTimer@@QAE@_JW4TimerType@Qt@@@ZF2B ?hasExpired@QDeadlineTimer@@QBE_NXZ1752 ?remainingTime@QDeadlineTimer@@QBE_JXZ156 ??0QLibrary@@QAE@PAVQObject@@@Z322 ??1QLibrary@@UAE@XZ1826 ?resolve@QLibrary@@QAEP6AXXZPBD@Z127A ?load@QLibrary@@QAE_NXZ10F0 ?isLoaded@QLibrary@@QBE_NXZ1968 ?setFileName@QLibrary@@QAEXABVQString@@@ZDE4 ?fileName@QLibrary@@QBE?AVQString@@XZD70 ?errorString@QLibrary@@QBE?AVQString@@XZ15DC ?qt_error_string@@YA?AVQString@@H@Z129D ?lock@QMutex@@QAEXXZ1F0B ?unlock@QMutexLocker@@QAEXXZ23A ??0QTimer@@QAE@PAVQObject@@@Z369 ??1QTimer@@UAE@XZ1B55 ?start@QTimer@@QAEXXZ1C84 ?timeout@QTimer@@QAEXUQPrivateSignal@1@@Z3A7 ??4QByteArray@@QAEAAV0@$$QAV0@@Z1616 ?qt_metacall@QTimer@@UAEHW4Call@QMetaObject@@HPAPAX@Z1653 ?qt_metacast@QTimer@@UAEPAXPBD@Z1C87 ?timerEvent@QTimer@@MAEXPAVQTimerEvent@@@Z1AA6 ?shared_null@QListData@@2UData@1@B1BD7 ?staticMetaObject@QTimer@@2UQMetaObject@@B9A ??0QChar@@QAE@UQLatin1Char@@@Z455 ??4QString@@QAEAAV0@ABV0@@ZA79 ?constData@QString@@QBEPBVQChar@@XZ886 ?arg@QString@@QBE?AV1@KHHVQChar@@@ZF99 ?indexOf@QString@@QBEHVQChar@@HW4CaseSensitivity@Qt@@@ZF9A ?indexOf@QString@@QBEHVQLatin1String@@HW4CaseSensitivity@Qt@@@ZF94 ?indexOf@QString@@QBEHABV1@HW4CaseSensitivity@Qt@@@Z1245 ?lastIndexOf@QString@@QBEHVQChar@@HW4CaseSensitivity@Qt@@@Z1357 ?mid@QString@@QBE?AV1@HH@Z1B7F ?startsWith@QString@@QBE_NVQLatin1String@@W4CaseSensitivity@Qt@@@Z1DEA ?toUpper@QString@@QHAE?AV1@XZEDA ?fromWCharArray@QString@@SA?AV1@PB_WH@Z1CFA ?toInt@QString@@QBEHPA_NH@Z1FD ??0QString@@QAE@HW4Initialization@Qt@@@Z869 ?appendLatin1To@QAbstractConcatenable@@KAXPBDHPAVQChar@@@Z56 ??0QByteArray@@QAE@$$QAV0@@ZCA5 ?dispose@QListData@@SAXPAUData@1@@Z570 ??8@YA_NABVQString@@0@Z1C85 ?timerEvent@QObject@@MAEXPAVQTimerEvent@@@Z1AFC ?skip@QIODevicePrivate@@UAE_J_J@Z1AEC ?size@QIODevice@@UBE_JXZ18B1 ?seek@QIODevice@@UAE_N_J@Z180F ?reset@QIODevice@@UAE_NXZ1535 ?putCharHelper@QIODevicePrivate@@UAE_ND@Z14B5 ?pos@QIODevice@@UBE_JXZ148F ?peek@QIODevicePrivate@@UAE_JPAD_J@Z148E ?peek@QIODevicePrivate@@UAE?AVQByteArray@@_J@ZD9B ?eventFilter@QObject@@UAE_NPAV1@PAVQEvent@@@ZD89 ?event@QObject@@UAE_NPAVQEvent@@@ZC9A ?disconnectNotify@QObject@@MAEXABVQMetaMethod@@@Z133A ?metaObject@QTimer@@UBEPBUQMetaObject@@XZ2C3 ??1Connection@QMetaObject@@QAE@XZB62 ?customEvent@QObject@@MAEXPAVQEvent@@@ZA65 ?connectNotify@QObject@@MAEXABVQMetaMethod@@@Z9A9 ?childEvent@QObject@@MAEXPAVQChildEvent@@@Z316 ??1QIODevicePrivate@@UAE@XZ11B ??0QIODevicePrivate@@QAE@XZ9D0 ?clear@QRingBuffer@@QAEXXZ1955 ?setErrorString@QIODevice@@IAEXABVQString@@@Z16EE ?readLineData@QIODevice@@MAE_JPAD_J@Z118 ??0QIODevice@@IAE@AAVQIODevicePrivate@@PAVQObject@@@Z944 ?canReadLine@QIODevice@@UBE_NXZ927 ?bytesToWrite@QIODevice@@UBE_JXZ922 ?bytesAvailable@QIODevice@@UBE_JXZ8AA ?atEnd@QIODevice@@UBE_NXZ9ED ?close@QIODevice@@UAEXXZ1444 ?open@QIODevice@@UAE_NV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z1149 ?isReadable@QIODevice@@QBE_NXZ1132 ?isOpen@QIODevice@@QBE_NXZ315 ??1QIODevice@@UAE@XZ15FA ?qt_metacall@QIODevice@@UAEHW4Call@QMetaObject@@HPAPAX@Z1637 ?qt_metacast@QIODevice@@UAEPAXPBD@ZCCB ?dynamicMetaObject@QObjectData@@QBEPAUQMetaObject@@XZ1126 ?isNull@QString@@QBE_NXZ453 ??4QString@@QAEAAV0@$$QAV0@@Z356 ??1QString@@QAE@XZ1FA ??0QString@@QAE@ABV0@@Z203 ??0QString@@QAE@XZ2E0 ??1QByteArray@@QAE@XZ58 ??0QByteArray@@QAE@HD@Z5C ??0QByteArray@@QAE@XZ7BA ?activate@QMetaObject@@SAXPAVQObject@@PBU1@HPAPAX@Z1E38 ?tr@QMetaObject@@QBE?AVQString@@PBD0H@Z1F9D ?warning@QMessageLogger@@QBAXPBDZZ16B ??0QMessageLogger@@QAE@PBDH0@Z4B ??0QBasicMutex@@QAE@XZ1BB8 ?staticMetaObject@QIODevice@@2UQMetaObject@@BSETUPAPI.dll1000927C Import Address Table1000CD90 Import Name Table0 time date stamp0 Index of first forwarder reference80 CM_Get_Parent52 CM_Get_DevNode_Status55 CM_Get_Device_IDW172 SetupDiGetDeviceRegistryPropertyW191 SetupDiOpenDevRegKey154 SetupDiGetClassDevsW13D SetupDiDestroyDeviceInfoList140 SetupDiEnumDeviceInfoADVAPI32.dll10009000 Import Address Table1000CB14 Import Name Table0 time date stamp0 Index of first forwarder reference25B RegCloseKey28C RegOpenKeyExW299 RegQueryValueExW27D RegEnumValueWMSVCP140.dll100090C4 Import Address Table1000CBD8 Import Name Table0 time date stamp0 Index of first forwarder reference28E ?_Xlength_error@std@@YAXPBD@ZKERNEL32.dll10009014 Import Address Table1000CB28 Import Name Table0 time date stamp0 Index of first forwarder referenceBF CreateEventW5D8 WaitForSingleObjectEx4C6 ResetEvent516 SetEvent110 DeleteCriticalSection35F InitializeCriticalSectionAndSpinCount3BD LeaveCriticalSection131 EnterCriticalSection4E1 SetCommTimeouts4E0 SetCommState4DF SetCommMask4DD SetCommBreak43E PurgeComm1D5 GetCommTimeouts2AE GetProcAddress1D2 GetCommModemStatus15D EscapeCommFunction84 ClearCommError83 ClearCommBreak57D Sleep580 SleepEx72 CancelIoEx11D DeviceIoControl532 SetLastError261 GetLastError86 CloseHandle613 WriteFileEx474 ReadFileExCB CreateFileW278 GetModuleHandleW37F IsDebuggerPresent5AD UnhandledExceptionFilter1D4 GetCommState386 IsProcessorFeaturePresent217 GetCurrentProcess58C TerminateProcess44D QueryPerformanceCounter218 GetCurrentProcessId21C GetCurrentThreadId2E9 GetSystemTimeAsFileTime11E DisableThreadLibraryCalls363 InitializeSListHead56D SetUnhandledExceptionFilterVCRUNTIME140.dll100092A0 Import Address Table1000CDB4 Import Name Table0 time date stamp0 Index of first forwarder reference46 memcpy1 _CxxThrowException10 __CxxFrameHandler347 memmove21 __std_exception_copy22 __std_exception_destroy48 memset35 _except_handler4_common25 __std_type_info_destroy_listapi-ms-win-crt-runtime-l1-1-0.dll100092D8 Import Address Table1000CDEC Import Name Table0 time date stamp0 Index of first forwarder reference19 _configure_narrow_argv35 _initialize_narrow_environment36 _initialize_onexit_table41 _seh_filter_dll24 _execute_onexit_table1F _crt_atexit17 _cexit38 _initterm39 _initterm_e3E _register_onexit_function3B _invalid_parameter_noinfo_noreturnapi-ms-win-crt-heap-l1-1-0.dll100092C8 Import Address Table1000CDDC Import Name Table0 time date stamp0 Index of first forwarder reference8 _callnewh19 malloc18 freeSummary1000 .data6000 .rdata1000 .reloc1000 .rsrc8000 .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.dllFile Type: DLLSection contains the following exports for Qt5SerialPort.dll00000000 characteristicsFFFFFFFF time date stamp0.00 version1 ordinal base95 number of functions95 number of namesordinal hint RVA name1 0 00001010 ??0QSerialPort@@QAE@ABVQSerialPortInfo@@PAVQObject@@@Z2 1 00001080 ??0QSerialPort@@QAE@ABVQString@@PAVQObject@@@Z3 2 000010F0 ??0QSerialPort@@QAE@PAVQObject@@@Z4 3 00002AD0 ??0QSerialPortInfo@@AAE@ABVQSerialPortInfoPrivate@@@Z5 4 00002AF0 ??0QSerialPortInfo@@QAE@ABV0@@Z6 5 00002B30 ??0QSerialPortInfo@@QAE@ABVQSerialPort@@@Z7 6 00002B60 ??0QSerialPortInfo@@QAE@ABVQString@@@Z8 7 00002D70 ??0QSerialPortInfo@@QAE@XZ9 8 00001350 ??1QSerialPort@@UAE@XZ10 9 00002DF0 ??1QSerialPortInfo@@QAE@XZ11 A 00002E30 ??4QSerialPortInfo@@QAEAAV0@ABV0@@Z12 B 0000A524 ??_7QSerialPort@@6B@13 C 00001410 ??_FQSerialPort@@QAEXXZ14 D 000014A0 ?atEnd@QSerialPort@@UBE_NXZ15 E 00006220 ?availablePorts@QSerialPortInfo@@SA?AV?$QList@VQSerialPortInfo@@@@XZ16 F 000014B0 ?baudRate@QSerialPort@@QBEHV?$QFlags@W4Direction@QSerialPort@@@@@Z17 10 000014F0 ?baudRateChanged@QSerialPort@@QAEXHV?$QFlags@W4Direction@QSerialPort@@@@@Z18 11 00001540 ?breakEnabledChanged@QSerialPort@@QAEX_N@Z19 12 00001570 ?bytesAvailable@QSerialPort@@UBE_JXZ20 13 00001580 ?bytesToWrite@QSerialPort@@UBE_JXZ21 14 000015B0 ?canReadLine@QSerialPort@@UBE_NXZ22 15 000015C0 ?clear@QSerialPort@@QAE_NV?$QFlags@W4Direction@QSerialPort@@@@@Z23 16 00001670 ?clearError@QSerialPort@@QAEXXZ24 17 000016B0 ?close@QSerialPort@@UAEXXZ25 18 00001720 ?d_func@QSerialPort@@AAEPAVQSerialPortPrivate@@XZ26 19 00001720 ?d_func@QSerialPort@@ABEPBVQSerialPortPrivate@@XZ27 1A 00001730 ?d_func@QSerialPortInfo@@AAEPAVQSerialPortInfoPrivate@@XZ28 1B 00001730 ?d_func@QSerialPortInfo@@ABEPBVQSerialPortInfoPrivate@@XZ29 1C 00001740 ?dataBits@QSerialPort@@QBE?AW4DataBits@1@XZ30 1D 00001750 ?dataBitsChanged@QSerialPort@@QAEXW4DataBits@1@@Z31 1E 00001780 ?dataErrorPolicy@QSerialPort@@QBE?AW4DataErrorPolicy@1@XZ32 1F 00001790 ?dataErrorPolicyChanged@QSerialPort@@QAEXW4DataErrorPolicy@1@@Z33 20 000017C0 ?dataTerminalReadyChanged@QSerialPort@@QAEX_N@Z34 21 00002EA0 ?description@QSerialPortInfo@@QBE?AVQString@@XZ35 22 000017F0 ?error@QSerialPort@@QAEXW4SerialPortError@1@@Z36 23 00001820 ?error@QSerialPort@@QBE?AW4SerialPortError@1@XZ37 24 00001830 ?errorOccurred@QSerialPort@@QAEXW4SerialPortError@1@@Z38 25 00001860 ?flowControl@QSerialPort@@QBE?AW4FlowControl@1@XZ39 26 00001870 ?flowControlChanged@QSerialPort@@QAEXW4FlowControl@1@@Z40 27 000018A0 ?flush@QSerialPort@@QAE_NXZ41 28 00003BF0 ?handle@QSerialPort@@QBEPAXXZ42 29 00002F10 ?hasProductIdentifier@QSerialPortInfo@@QBE_NXZ43 2A 00002F20 ?hasVendorIdentifier@QSerialPortInfo@@QBE_NXZ44 2B 00001920 ?isBreakEnabled@QSerialPort@@QBE_NXZ45 2C 000072C0 ?isBusy@QSerialPortInfo@@QBE_NXZ46 2D 00001930 ?isDataTerminalReady@QSerialPort@@QAE_NXZ47 2E 00001950 ?isNull@QSerialPortInfo@@QBE_NXZ48 2F 00001960 ?isRequestToSend@QSerialPort@@QAE_NXZ49 30 00001980 ?isSequential@QSerialPort@@UBE_NXZ50 31 00007320 ?isValid@QSerialPortInfo@@QBE_NXZ51 32 00002F30 ?manufacturer@QSerialPortInfo@@QBE?AVQString@@XZ52 33 00001990 ?metaObject@QSerialPort@@UBEPBUQMetaObject@@XZ53 34 000019B0 ?open@QSerialPort@@UAE_NV?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z54 35 00001AC0 ?parity@QSerialPort@@QBE?AW4Parity@1@XZ55 36 00001AD0 ?parityChanged@QSerialPort@@QAEXW4Parity@1@@Z56 37 00001B00 ?pinoutSignals@QSerialPort@@QAE?AV?$QFlags@W4PinoutSignal@QSerialPort@@@@XZ57 38 00001B90 ?portName@QSerialPort@@QBE?AVQString@@XZ58 39 00002FA0 ?portName@QSerialPortInfo@@QBE?AVQString@@XZ59 3A 00003000 ?productIdentifier@QSerialPortInfo@@QBEGXZ60 3B 00001BB0 ?qt_metacall@QSerialPort@@UAEHW4Call@QMetaObject@@HPAPAX@Z61 3C 00001C70 ?qt_metacast@QSerialPort@@UAEPAXPBD@Z62 3D 00001CD0 ?qt_static_metacall@QSerialPort@@CAXPAVQObject@@W4Call@QMetaObject@@HPAPAX@Z63 3E 00002110 ?readBufferSize@QSerialPort@@QBE_JXZ64 3F 00002120 ?readData@QSerialPort@@MAE_JPAD_J@Z65 40 00002130 ?readLineData@QSerialPort@@MAE_JPAD_J@Z66 41 00002150 ?requestToSendChanged@QSerialPort@@QAEX_N@Z67 42 00002180 ?sendBreak@QSerialPort@@QAE_NH@Z68 43 00003010 ?serialNumber@QSerialPortInfo@@QBE?AVQString@@XZ69 44 00002210 ?setBaudRate@QSerialPort@@QAE_NHV?$QFlags@W4Direction@QSerialPort@@@@@Z70 45 000022F0 ?setBreakEnabled@QSerialPort@@QAE_N_N@Z71 46 000023D0 ?setDataBits@QSerialPort@@QAE_NW4DataBits@1@@Z72 47 00002450 ?setDataErrorPolicy@QSerialPort@@QAE_NW4DataErrorPolicy@1@@Z73 48 00002520 ?setDataTerminalReady@QSerialPort@@QAE_N_N@Z74 49 00002690 ?setFlowControl@QSerialPort@@QAE_NW4FlowControl@1@@Z75 4A 00002710 ?setParity@QSerialPort@@QAE_NW4Parity@1@@Z76 4B 00002790 ?setPort@QSerialPort@@QAEXABVQSerialPortInfo@@@Z77 4C 000027C0 ?setPortName@QSerialPort@@QAEXABVQString@@@Z78 4D 000027F0 ?setReadBufferSize@QSerialPort@@QAEX_J@Z79 4E 00002820 ?setRequestToSend@QSerialPort@@QAE_N_N@Z80 4F 00002920 ?setSettingsRestoredOnClose@QSerialPort@@QAEX_N@Z81 50 00002970 ?setStopBits@QSerialPort@@QAE_NW4StopBits@1@@Z82 51 000029F0 ?settingsRestoredOnClose@QSerialPort@@QBE_NXZ83 52 00002A00 ?settingsRestoredOnCloseChanged@QSerialPort@@QAEX_N@Z84 53 00003080 ?standardBaudRates@QSerialPortInfo@@SA?AV?$QList@H@@XZ85 54 0000F000 ?staticMetaObject@QSerialPort@@2UQMetaObject@@B86 55 00002A30 ?stopBits@QSerialPort@@QBE?AW4StopBits@1@XZ87 56 00002A40 ?stopBitsChanged@QSerialPort@@QAEXW4StopBits@1@@Z88 57 000030A0 ?swap@QSerialPortInfo@@QAEXAAV1@@Z89 58 000030C0 ?systemLocation@QSerialPortInfo@@QBE?AVQString@@XZ90 59 00002A70 ?tr@QSerialPort@@SA?AVQString@@PBD0H@Z91 5A 00002A70 ?trUtf8@QSerialPort@@SA?AVQString@@PBD0H@Z92 5B 00003130 ?vendorIdentifier@QSerialPortInfo@@QBEGXZ93 5C 00002A90 ?waitForBytesWritten@QSerialPort@@UAE_NH@Z94 5D 00002AA0 ?waitForReadyRead@QSerialPort@@UAE_NH@Z95 5E 00002AB0 ?writeData@QSerialPort@@MAE_JPBD_J@ZSummary1000 .data6000 .rdata1000 .reloc1000 .rsrc8000 .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.exeThere is an import table in .idata at 0x408000The Import Tables (interpreted .idata section contents)vma: Hint Time Forward DLL FirstTable Stamp Chain Name Thunk00008000 00008064 00000000 00000000 00008568 0000814cDLL Name: KERNEL32.dllvma: Hint/Ord Member-Name Bound-To8234 207 DeleteCriticalSection824c 236 EnterCriticalSection8264 279 ExitProcess8272 300 FindClose827e 304 FindFirstFileA8290 321 FindNextFileA82a0 352 FreeLibrary82ae 388 GetCommandLineA82c0 510 GetLastError82d0 529 GetModuleHandleA82e4 577 GetProcAddress82f6 734 InitializeCriticalSection8312 814 LeaveCriticalSection832a 817 LoadLibraryA833a 1140 SetUnhandledExceptionFilter8358 1173 TlsGetValue8366 1213 VirtualProtect8378 1215 VirtualQuery00008014 000080b0 00000000 00000000 00008580 00008198DLL Name: msvcrt.dllvma: Hint/Ord Member-Name Bound-To8388 80 _strdup8392 82 _stricoll00008028 000080bc 00000000 00000000 00008610 000081a4DLL Name: msvcrt.dllvma: Hint/Ord Member-Name Bound-To839e 88 __getmainargs83ae 119 __mb_cur_max83be 131 __p__environ83ce 133 __p__fmode83dc 153 __set_app_type83ee 219 _cexit83f8 285 _errno8402 324 _fpreset840e 350 _fullpath841a 417 _iob8422 422 _isctype842e 689 _onexit8438 698 _pctype8442 753 _setmode844e 1083 abort8456 1091 atexit8460 1098 calloc846a 1131 free8472 1142 fwrite847c 1187 malloc8486 1194 mbstowcs8492 1199 memcpy849c 1208 printf84a6 1211 putchar84b0 1212 puts84b8 1220 realloc84c2 1227 setlocale84ce 1229 signal84d8 1242 strcoll84e2 1249 strlen84ec 1277 tolower84f6 1284 vfprintf8502 1325 wcstombs0000803c 00008144 00000000 00000000 00008620 0000822cDLL Name: license.dllvma: Hint/Ord Member-Name Bound-To8510 0 get_license00008050 00000000 00000000 00000000 00000000 00000000
看到header信息
main.exe: file format pei-i386Characteristics 0x107relocations strippedexecutableline numbers stripped32 bit wordsTime/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等信息。
a.out: file format elf64-little
a.out
architecture: UNKNOWN!, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000400810Program Header:PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x0000000000400040 align 2**3filesz 0x0000000000000188 memsz 0x0000000000000188 flags r-xINTERP off 0x00000000000001c8 vaddr 0x00000000004001c8 paddr 0x00000000004001c8 align 2**0filesz 0x000000000000001b memsz 0x000000000000001b flags r--LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x0000000000400000 align 2**16filesz 0x0000000000000a7c memsz 0x0000000000000a7c flags r-xLOAD off 0x0000000000000a80 vaddr 0x0000000000410a80 paddr 0x0000000000410a80 align 2**16filesz 0x0000000000000278 memsz 0x00000000000002c0 flags rw-DYNAMIC off 0x0000000000000a98 vaddr 0x0000000000410a98 paddr 0x0000000000410a98 align 2**3filesz 0x00000000000001e0 memsz 0x00000000000001e0 flags rw-NOTE off 0x00000000000001e4 vaddr 0x00000000004001e4 paddr 0x00000000004001e4 align 2**2filesz 0x0000000000000044 memsz 0x0000000000000044 flags r--STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**4filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-Dynamic Section:NEEDED libtest.soNEEDED libc.so.6INIT 0x0000000000400740FINI 0x0000000000400a40INIT_ARRAY 0x0000000000410a80INIT_ARRAYSZ 0x0000000000000008FINI_ARRAY 0x0000000000410a88FINI_ARRAYSZ 0x0000000000000008HASH 0x0000000000400228STRTAB 0x00000000004004e0SYMTAB 0x00000000004002d0STRSZ 0x0000000000000123SYMENT 0x0000000000000018DEBUG 0x0000000000000000PLTGOT 0x0000000000410c88PLTRELSZ 0x00000000000000d8PLTREL 0x0000000000000007JMPREL 0x0000000000400668RELA 0x0000000000400650RELASZ 0x0000000000000018RELAENT 0x0000000000000018VERNEED 0x0000000000400630VERNEEDNUM 0x0000000000000001VERSYM 0x0000000000400604Version References:required from libc.so.6:0x06969197 0x00 02 GLIBC_2.17Sections:
Idx Name Size VMA LMA File off Algn0 .interp 0000001b 00000000004001c8 00000000004001c8 000001c8 2**0CONTENTS, ALLOC, LOAD, READONLY, DATA1 .note.ABI-tag 00000020 00000000004001e4 00000000004001e4 000001e4 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA2 .note.gnu.build-id 00000024 0000000000400204 0000000000400204 00000204 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA3 .hash 000000a4 0000000000400228 0000000000400228 00000228 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA4 .dynsym 00000210 00000000004002d0 00000000004002d0 000002d0 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA5 .dynstr 00000123 00000000004004e0 00000000004004e0 000004e0 2**0CONTENTS, ALLOC, LOAD, READONLY, DATA6 .gnu.version 0000002c 0000000000400604 0000000000400604 00000604 2**1CONTENTS, ALLOC, LOAD, READONLY, DATA7 .gnu.version_r 00000020 0000000000400630 0000000000400630 00000630 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA8 .rela.dyn 00000018 0000000000400650 0000000000400650 00000650 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA9 .rela.plt 000000d8 0000000000400668 0000000000400668 00000668 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA10 .init 00000014 0000000000400740 0000000000400740 00000740 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE11 .plt 000000b0 0000000000400760 0000000000400760 00000760 2**4CONTENTS, ALLOC, LOAD, READONLY, CODE12 .text 00000230 0000000000400810 0000000000400810 00000810 2**3CONTENTS, ALLOC, LOAD, READONLY, CODE13 .fini 00000010 0000000000400a40 0000000000400a40 00000a40 2**2CONTENTS, ALLOC, LOAD, READONLY, CODE14 .rodata 00000028 0000000000400a50 0000000000400a50 00000a50 2**3CONTENTS, ALLOC, LOAD, READONLY, DATA15 .eh_frame 00000004 0000000000400a78 0000000000400a78 00000a78 2**2CONTENTS, ALLOC, LOAD, READONLY, DATA16 .init_array 00000008 0000000000410a80 0000000000410a80 00000a80 2**3CONTENTS, ALLOC, LOAD, DATA17 .fini_array 00000008 0000000000410a88 0000000000410a88 00000a88 2**3CONTENTS, ALLOC, LOAD, DATA18 .jcr 00000008 0000000000410a90 0000000000410a90 00000a90 2**3CONTENTS, ALLOC, LOAD, DATA19 .dynamic 000001e0 0000000000410a98 0000000000410a98 00000a98 2**3CONTENTS, ALLOC, LOAD, DATA20 .got 00000010 0000000000410c78 0000000000410c78 00000c78 2**3CONTENTS, ALLOC, LOAD, DATA21 .got.plt 00000060 0000000000410c88 0000000000410c88 00000c88 2**3CONTENTS, ALLOC, LOAD, DATA22 .data 00000010 0000000000410ce8 0000000000410ce8 00000ce8 2**3CONTENTS, ALLOC, LOAD, DATA23 .bss 00000048 0000000000410cf8 0000000000410cf8 00000cf8 2**3ALLOC24 .comment 0000002f 0000000000000000 0000000000000000 00000cf8 2**0CONTENTS, READONLY25 .debug_aranges 00000110 0000000000000000 0000000000000000 00000d30 2**4CONTENTS, READONLY, DEBUGGING26 .debug_info 00000452 0000000000000000 0000000000000000 00000e40 2**0CONTENTS, READONLY, DEBUGGING27 .debug_abbrev 00000183 0000000000000000 0000000000000000 00001292 2**0CONTENTS, READONLY, DEBUGGING28 .debug_line 0000028a 0000000000000000 0000000000000000 00001415 2**0CONTENTS, READONLY, DEBUGGING29 .debug_frame 00000068 0000000000000000 0000000000000000 000016a0 2**3CONTENTS, READONLY, DEBUGGING30 .debug_str 0000026c 0000000000000000 0000000000000000 00001708 2**0CONTENTS, READONLY, DEBUGGING31 .debug_loc 00000143 0000000000000000 0000000000000000 00001974 2**0CONTENTS, READONLY, DEBUGGING32 .debug_ranges 000000d0 0000000000000000 0000000000000000 00001ac0 2**4CONTENTS, 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