Extract the contents of ELF and write to binary file

19,451

Try this:

objcopy -j .text -O binary firmware.ko firmware.text

The file firmware.text should then contain what you want.


UPDATE: The above should work if the firmware file is in the same format that your machine (running objcopy) uses. If it is not the case, you'll be getting:

objcopy: Unable to recognise the format of the input file `firmware-arm.ko'

Then you'll have to specify the format yourself with -I. Using file will tell you what format your firmware is in, e.g.:

$ file firmware-arm.ko
firmware-arm.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), BuildID[sha1]=0xec2e703615d915dd1cad09ecc12ff7d57ef186a5, not stripped

And then (for this case where you have an ELF 32 little endian) you'll need:

objcopy -j .text -O binary -I elf32-little firmware-arm.ko firmware-arm.text
Share:
19,451

Related videos on Youtube

Ursa Major
Author by

Ursa Major

I hope to help people and make this world a better place for our present and future generations.

Updated on September 18, 2022

Comments

  • Ursa Major
    Ursa Major over 1 year

    I have been trying to extract the contents of a firmware and putting it to a binary file, but with no success.

    I see the right hex contents, but am not sure how to laid them in bits into a file.

    objdump -s -j .text firmware.ko | tail -n +5 | awk '{print "dd if='firmware.ko' of='content.bin' bs=1 count=$["$2 $3 $4 $5 "]"}'
    
  • Ursa Major
    Ursa Major over 10 years
    I could not just objcopy as objcopy: Unable to recognise the format of the input file
  • nickie
    nickie over 10 years
    If objdump works, I cannot see why objcopy should not work. What is the format of your file? You can specify it with -I if you know it, e.g. -I elf64-x86-64.
  • Ursa Major
    Ursa Major over 10 years
    Using objdump -s -j firmware.ko. It states that it is > file format elf32-little Using file formware.ko. It states that it is ELF 32-bit LSB relocatable, ARM, version 1 (SYSV) Thank you, @nickie.
  • Ursa Major
    Ursa Major over 10 years
    I used objcopy -I elf32-little -j .text -O binary firmware.ko content.bin I think it works now. Thank you, @nickie. You saved the day.
  • nickie
    nickie over 10 years
    Assuming you're also running objcopy on your ARM machine, I don't think you'd need anything special. If not, I'd suggest -I elf32-arm but I don't know if your objcopy supports that.
  • nickie
    nickie over 10 years
    OK, I think I've figured this out. I'm updating the answer...
  • nickie
    nickie over 10 years
    Just to make sure my comment above does not confuse anybody: I don't know if an elf32-arm format is recognized by any version of objcopy. If not, try elf32-little, this should work.