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
Related videos on Youtube
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, 2022Comments
-
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 "]"}'
-
Ciro Santilli Путлер Капут 六四事 over 8 years
-
-
Ursa Major over 10 yearsI could not just objcopy as objcopy: Unable to recognise the format of the input file
-
nickie over 10 yearsIf
objdump
works, I cannot see whyobjcopy
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 over 10 yearsUsing 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 over 10 yearsI 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 over 10 yearsAssuming 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 yourobjcopy
supports that. -
nickie over 10 yearsOK, I think I've figured this out. I'm updating the answer...
-
nickie over 10 yearsJust to make sure my comment above does not confuse anybody: I don't know if an
elf32-arm
format is recognized by any version ofobjcopy
. If not, tryelf32-little
, this should work.