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?
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.
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With