【问题标题】:How to extract all of the sections in an obj file如何提取obj文件中的所有部分
【发布时间】:2020-02-20 06:46:36
【问题描述】:

我正在使用 X86_64 Ubuntu 机器。我知道我们可以使用该命令从 obj 文件中提取某些部分。

假设我有一个名为main.o 的obj 文件,现在我可以执行以下操作:

me@my-machine:~/tmp$ readelf -S main.o

There are 13 section headers, starting at offset 0x428:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000000000  00000040
       0000000000000055  0000000000000000  AX       0     0     1
  [ 2] .rela.text        RELA             0000000000000000  00000318
       0000000000000078  0000000000000018   I      11     1     8
  [ 3] .data             PROGBITS         0000000000000000  00000098
       0000000000000008  0000000000000000  WA       0     0     4
  [ 4] .bss              NOBITS           0000000000000000  000000a0
       0000000000000004  0000000000000000  WA       0     0     4
  [ 5] .rodata           PROGBITS         0000000000000000  000000a0
       0000000000000004  0000000000000000   A       0     0     1
  [ 6] .comment          PROGBITS         0000000000000000  000000a4
       0000000000000036  0000000000000001  MS       0     0     1
  [ 7] .note.GNU-stack   PROGBITS         0000000000000000  000000da
       0000000000000000  0000000000000000           0     0     1
  [ 8] .eh_frame         PROGBITS         0000000000000000  000000e0
       0000000000000058  0000000000000000   A       0     0     8
  [ 9] .rela.eh_frame    RELA             0000000000000000  00000390
       0000000000000030  0000000000000018   I      11     8     8
  [10] .shstrtab         STRTAB           0000000000000000  000003c0
       0000000000000061  0000000000000000           0     0     1
  [11] .symtab           SYMTAB           0000000000000000  00000138
       0000000000000180  0000000000000018          12    11     8
  [12] .strtab           STRTAB           0000000000000000  000002b8
       000000000000005d  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

然后我可以借助命令objdump提取一些部分,例如,

me@my-machine:~/tmp$ objdump -s -j .data main.o

main.o:     file format elf64-x86-64

Contents of section .data:
 0000 54000000 55000000                    T...U...

如我们所见,我在这里提取了.data 部分。

但是,如果我尝试提取另一个部分,它似乎无法按预期工作。

me@my-machine:~/tmp$ objdump -s -j .strtab main.o

main.o:     file format elf64-x86-64

objdump: section '.strtab' mentioned in a -j option, but not found in any input file

为什么不能提取部分.strtab?如何提取此部分?

【问题讨论】:

    标签: linux elf objdump readelf


    【解决方案1】:

    为什么 .strtab 部分无法提取?

    可能是因为 binutils 中的this bug

    如何提取此部分?

    试试:

    readelf -x.strtab main.o
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 2019-10-04
      • 2023-01-25
      • 1970-01-01
      • 2021-12-18
      相关资源
      最近更新 更多