ELF(Executable and Linkable Format)形式のファイルはバイナリのため、テキストデータのように簡単に参照することはできません。
ELFの情報を読み取ることができる「readelf」コマンドがあり、それを利用します。
ヘッダーを取得したい場合は、「-h」オプションを使用します。
以下では「cat」コマンドの情報を確認します。
まずは、「cat」コマンドのファイル形式を確認します。
1 2 3 |
# file /bin/cat /bin/cat: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped # |
「ELF」となっていることがわかります。
続いて、「/bin/cat」のヘッダー情報を確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# readelf -h /bin/cat ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x401850 Start of program headers: 64 (bytes into file) Start of section headers: 46520 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 9 Size of section headers: 64 (bytes) Number of section headers: 32 Section header string table index: 31 # |
ヘッダー情報を確認できました!