4

I have a file containing ARM v8 binary code. I want to disassemble the file and get the actual assembly code contained in it.

Assuming the file name is tmp.o I run:

/opt/linaro/A64-tools/bin/aarch64-linux-gnu-objdump -b binary -m AARCH64 -D tmp.o

This gives me the correct disassembly. However, the offset for branch instructions assumes that this code sits in address 0x00000000.

If I know that the code will sit in address 0x12345678 in memory:

  1. Is there a way to tell objdump to use this address as the start address?
  2. If not, can I add some header to the binary file that says something like:

    . = 0x12345678

Thanks in Advance..

unixsmurf
  • 5,852
  • 1
  • 33
  • 40
siwesam
  • 463
  • 5
  • 8
  • Do you have enough disk space to simply pad the start of the file with 0x12345678 zero bytes? :P – Notlikethat May 26 '15 at 14:13
  • Unfortunately no disk space and no runtime :( – siwesam May 26 '15 at 14:17
  • this is an object and not a linked binary, you can link the binary to the final address and then disassemble that – old_timer May 26 '15 at 15:20
  • @dwelch this is a dummy object that I created from some memory snapshot. It is not meant to be linked. I need to run disassembly on it in stand alone mode. thanks though. – siwesam May 26 '15 at 16:24
  • I understand that the point was your final address is not applied normally until link time so if there had not been this command line option in objdump then your choice is disassemble the object at base zero and deal with it or link it strictly for the purpose of changing the address for disassembly... – old_timer May 26 '15 at 17:30
  • Correct. My backup plan was to disassemble at base zero, and then manually change the branch addresses in the disassembly. – siwesam May 27 '15 at 07:32

1 Answers1

6

A quick poke around reveals objdump's --adjust-vma option, which seems to do exactly this.

Using the first raw binary which came to hand:

$ aarch64-linux-gnu-objdump -b binary -m aarch64 -D arch/arm64/boot/Image

arch/arm64/boot/Image:     file format binary


Disassembly of section .data:

0000000000000000 <.data>:
       0:       91005a4d        add     x13, x18, #0x16
       4:       140003ff        b       0x1000
...

vs.

$ aarch64-linux-gnu-objdump -b binary -m aarch64 --adjust-vma=0x12345678 -D arch/arm64/boot/Image

arch/arm64/boot/Image:     file format binary


Disassembly of section .data:

0000000012345678 <.data>:
    12345678:   91005a4d        add     x13, x18, #0x16
    1234567c:   140003ff        b       0x12346678
...
Notlikethat
  • 20,095
  • 3
  • 40
  • 77