如何提取 obj 文件中的所有部分
How to extract all of the sections in an obj file
我正在 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
部分无法提取?如何提取此部分?
Why can't the section .strtab be extracted?
可能是因为 binutils 中的 this bug。
How can I extract this section?
尝试:
readelf -x.strtab main.o
我正在 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
部分无法提取?如何提取此部分?
Why can't the section .strtab be extracted?
可能是因为 binutils 中的 this bug。
How can I extract this section?
尝试:
readelf -x.strtab main.o