Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objdump to extract contents of text segment to a binary format

Tags:

linux

objdump

How do we use objdump to output to a binary file?

This is definitely not the right way to do so:

objdump -s -j .text /path/firmware.ko > /content.bin

as it is only presenting text format. I only require the bytes of the text segment to be extracted and to be set in binary forms.

like image 290
Ursa Major Avatar asked Jan 03 '14 07:01

Ursa Major


People also ask

What is objdump used for?

objdump displays information about one or more object files. The options control what particular information to display. This information is mostly useful to programmers who are working on the compilation tools, as opposed to programmers who just want their program to compile and work.

What is objdump C?

Objdump displays information about one or more object files, either on their own, or inside libraries. It is commonly used as a disassembler, but it can also display information about file headers, symbol tables, relocations, debugging directives and more.

Which command would you use to Dissassemble a object file?

Passing --disassemble=SYMBOL to objdump will disassemble only the specified function. No need to pass the start address and the end address.


2 Answers

We have to specify the file format explicitly using the -I.

objcopy -I #file type format# -j #ELF segment contents to copy# -O #data type to output, binary, etc# #input file# #output file#

eg.

 
objcopy -I elf32-little -j .text -O binary firmware.ko content.bin 
like image 89
2 revs Avatar answered Oct 01 '22 21:10

2 revs


You can use objcopy instead

objcopy -O binary --only-section=.text /path/firmware.ko /content.bin
like image 45
tristan Avatar answered Oct 01 '22 21:10

tristan