0

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

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

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提取部分?如何提取此部分?

4

1 回答 1

1

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

可能是因为 binutils 中的这个错误

如何提取此部分?

尝试:

readelf -x.strtab main.o
于 2020-02-20T14:48:46.563 回答