如何仅提取ELF部分的原始内容? [英] How to extract only the raw contents of an ELF section?
问题描述
我尝试了以下操作,但是生成的文件仍然是ELF,而不仅仅是部分内容.
I've tried the following, but the resulting file is still an ELF and not purely the section content.
$ objcopy --only-section=<name> <infile> <outfile>
我只想要本节的内容.是否有任何实用程序可以做到这一点?有什么想法吗?
I just want the contents of the section. Is there any utility that can do this? Any ideas?
推荐答案
围绕objdump
和dd
的细微改动:
IN_F=/bin/echo
OUT_F=./tmp1.bin
SECTION=.text
objdump -h $IN_F |
grep $SECTION |
awk '{print "dd if='$IN_F' of='$OUT_F' bs=1 count=$[0x" $3 "] skip=$[0x" $6 "]"}' |
bash
objdump -h
产生可预测的输出,该输出在elf文件中包含节偏移.我做了awk
来为shell生成dd
命令,因为dd
不支持十六进制数字.并将命令输入到shell.
The objdump -h
produces predictable output which contains section offset in the elf file. I made the awk
to generate a dd
command for the shell, since dd
doesn't support hexadecimal numbers. And fed the command to shell.
过去,由于很少需要手动执行所有操作,因此无需编写任何脚本.
In past I did all that manually, without making any scripts, since it is rarely needed.
这篇关于如何仅提取ELF部分的原始内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!