How to extract only the raw contents of an ELF section?

后端 未结 4 514
说谎
说谎 2020-12-01 04:16

I\'ve tried the following, but the resulting file is still an ELF and not purely the section content.

$ objcopy --only-section=  &l         


        
4条回答
  •  自闭症患者
    2020-12-01 05:17

    Rather inelegant hack around objdump and 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
    

    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.

提交回复
热议问题