Linux二进制文件查看器 readelf

查看二进制文件的所有信息

readelf -a test.so

获取到这样的信息

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64                                     # 64位ELF文件
  Data:                              2's complement, little endian             # 小端
  Version:                           1 (current)                               # ELF版本1
  OS/ABI:                            UNIX - System V                           # 操作系统UNIX System V,Linux也是
  ABI Version:                       0                                         # ABI版本未指定
  Type:                              DYN (Shared object file)                  # 动态链接库文件,可以被其他程序夹在共享
  Machine:                           Advanced Micro Devices X86-64             # 目标平台X86-64
  Version:                           0x1
  Entry point address:               0x8ce0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          263040 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         35
  Section header string table index: 34
  
Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .note.gnu.build-i NOTE             00000000000001c8  000001c8
       0000000000000024  0000000000000000   A       0     0     4
  [ 2] .gnu.hash         GNU_HASH         00000000000001f0  000001f0
       0000000000000788  0000000000000000   A       3     0     8
  [ 3] .dynsym           DYNSYM           0000000000000978  00000978
       0000000000001ab8  0000000000000018   A       4     1     8
  [ 4] .dynstr           STRTAB           0000000000002430  00002430
       0000000000003380  0000000000000000   A       0     0     1
  [ 5] .gnu.version      VERSYM           00000000000057b0  000057b0
       000000000000023a  0000000000000002   A       3     0     2
  [ 6] .gnu.version_r    VERNEED          00000000000059f0  000059f0

查看编译器版本

readelf  -p .comment  libtest.so

得到这样的信息

String dump of section '.comment':
  [     0]  GCC: (GNU) 8.3.1 20190311 (Red Hat 8.3.1-3)

可以发现,这个编译器是Red Hat(如CentOS)上的 8.3.1 GNU GCC编译器执行编译的

查看动态链接信息

readelf -d libtest.so

可以获得类似如下信息

Dynamic section at offset 0x18d98 contains 30 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libasan.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libcttmetrics_sg1.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x7e00
 0x000000000000000d (FINI)               0x15260
 0x0000000000000019 (INIT_ARRAY)         0x218d38
 0x000000000000001b (INIT_ARRAYSZ)       24 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x218d50
 0x000000000000001c (FINI_ARRAYSZ)       16 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x1f0
 0x0000000000000005 (STRTAB)             0x2430
 0x0000000000000006 (SYMTAB)             0x978
 0x000000000000000a (STRSZ)              13184 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x219000
 0x0000000000000002 (PLTRELSZ)           5640 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x67f8
 0x0000000000000007 (RELA)               0x5a90
 0x0000000000000008 (RELASZ)             3432 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x59f0
 0x000000006fffffff (VERNEEDNUM)         4
 0x000000006ffffff0 (VERSYM)             0x57b0
 0x000000006ffffff9 (RELACOUNT)          128
 0x0000000000000000 (NULL)               0x0

查看符号表

readelf -s <file>      # 查看符号表(包括动态符号表)

得到以下输出

Symbol table '.dynsym' contains 285 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZSt20__throw_length_erro@GLIBCXX_3.4 (2)
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND calloc
     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_init
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND memcpy
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _Znwm
     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_stack_malloc_2
     7: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     8: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNKSs5c_strEv@GLIBCXX_3.4 (2)
     9: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_stack_malloc_1
    10: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_rethrow@CXXABI_1.3 (3)
    11: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNKSs4sizeEv@GLIBCXX_3.4 (2)
    12: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (2)
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_report_load4_noabo
    14: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv
    15: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSsC1ERKSs@GLIBCXX_3.4 (2)
    16: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND opendir

只获取动态符号表

readelf --dyn-syms <file>  # 仅查看动态符号表(.dynsym)

获得以下内容

Symbol table '.dynsym' contains 285 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZSt20__throw_length_erro@GLIBCXX_3.4 (2)
     2: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND calloc
     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_init
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND memcpy
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _Znwm
     6: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_stack_malloc_2
     7: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     8: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNKSs5c_strEv@GLIBCXX_3.4 (2)
     9: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_stack_malloc_1
    10: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_rethrow@CXXABI_1.3 (3)
    11: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNKSs4sizeEv@GLIBCXX_3.4 (2)
    12: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (2)
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __asan_report_load4_noabo
    14: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZdlPv
    15: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSsC1ERKSs@GLIBCXX_3.4 (2)
    16: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND opendir
posted on 2025-04-15 10:19  风惊庭前叶  阅读(27)  评论(0)    收藏  举报