Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objdump, displaying without offsets

Tags:

objdump

When dumping an executable file, I only want the code segment to be printed on the standard output, not offsets and binary form of the code. I cannot achieve it from

man objdump

Is there a way?

like image 733
mustafa.yavuz Avatar asked Dec 17 '11 01:12

mustafa.yavuz


People also ask

What does objdump show?

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.

How do you take apart a ELF file?

Disassembling an ELF-formatted fileUse the --disassemble option to display a disassembled version of the image to stdout . If you use this option with the --output destination option, you can reassemble the output file with armasm. You can use this option to disassemble either an ELF image or an ELF object file.

Which parameter of objdump is used to show all disassembled output of an executable?

Similarly, you can use the -D command-line option to make objdump display assembler contents of all sections, and -S option to make sure the tool intermixes source code with disassembly.

What is the use of objdump in Linux?

objdump is a command-line program for displaying various information about object files on Unix-like operating systems. For instance, it can be used as a disassembler to view an executable in assembly form. It is part of the GNU Binutils for fine-grained control over executables and other binary data.


2 Answers

You can suppress the object code hex dump with

--no-show-raw-insn

If you have jumps in the code then you need the offsets to make sense of them, but if you really want to strip them, filter the code with something like:

objdump -d --no-show-raw-insn myfile.o | perl -p -e 's/^\s+(\S+):\t//;'

Example output:

0000000000000000 <foo>:
retq
lea    0x0(%rsi),%rsi
lea    0x0(%rdi),%rdi
Disassembly of section .gnu.linkonce.t.goo:

0000000000000000 <goo>:
retq
lea    0x0(%rsi),%rsi
lea    0x0(%rdi),%rdi
like image 76
Peeter Joot Avatar answered Oct 01 '22 22:10

Peeter Joot


If you want to achieve same output as Peeter Joot showed but without using Perl command line. Then you can use Grep and Cut tool instead, like shown below.

objdump -d --no-show-raw-insn my_binary_file.o | grep "^ " | cut -f2,3
like image 42
Haseeb Mir Avatar answered Oct 01 '22 22:10

Haseeb Mir