Can I disassemble a flat binary file using objdump?
I'm familiar with disassembling a structured binary executable such as an ELF file using:
objdump -d file.elf
But if I have a flat binary file that I know is supposed to be loaded at, e.g., address 0xabcd1000, can I ask objdump to disassemble it? I tried supplying options such as '--start-address=0xabcd1000' but objdump just states that it doesn't recognize the format.
I have other ideas about how to disassemble the file but I wanted to know if objdump could provide a simple solution.
I found the solution to my own question on a different forum. It looks something like this:
I've tested this and it works.
starblue and hlovdal both have parts of the canonical answer. If you want to disassemble raw i8086 code, you usually want Intel syntax, not AT&T syntax, too, so use:
If your code is ELF (or a.out (or (E)COFF)), you can use the short form:
For 32-bit or 64-bit code, omit the
,8086
; the ELF header already includes this information.ndisasm
, as suggested by jameslin, is also a good choice, butobjdump
usually comes with the OS and can deal with all architectures supported by GNU binutils (superset of those supported by GCC), and its output can usually be fed into GNUas
(ndisasm’s can usually be fed intonasm
though, of course).Peter Cordes suggests that “Agner Fog's objconv is very nice. It puts labels on branch targets, making a lot easier to figure out what the code does. It can disassemble into NASM, YASM, MASM, or AT&T (GNU) syntax.”
Multimedia Mike already found out about
--adjust-vma
; thendisasm
equivalent is the-o
option.To disassemble, say,
sh4
code (I used one binary from Debian to test), use this with GNU binutils (almost all other disassemblers are limited to one platform, such as x86 withndisasm
andobjconv
):The
-m
is the machine, and-EL
means Little Endian (forsh4eb
use-EB
instead), which is relevant for architectures that exist in either endianness.