I can disassemble raw binary file using the following command:
> aarch64-linux-gnu-objdump -m aarch64 -b binary -D file.bin
Can I achieve the same effect with llvm-objdump
and how? Maybe any other tool from LLVM toolchain?
I can disassemble raw binary file using the following command:
> aarch64-linux-gnu-objdump -m aarch64 -b binary -D file.bin
Can I achieve the same effect with llvm-objdump
and how? Maybe any other tool from LLVM toolchain?
The easiest way I've found to do this using only LLVM tools is to first objcopy
the binary into an ELF and then objdump
the ELF.
llvm-objcopy -I binary -O elf64-littleaarch64 --rename-section=.data=.text,code file.bin file.elf
Let's go through this option-by-option:
-I binary
: specifies that the input is in raw binary, rather than ELF, form.-O elf64-littleaarch64
(LLVM 10+1): specifies that the binary is to be interpreted as AArch64 machine code.--rename-section=.data=.text,code
: specifies that the section named .data
that automatically gets created when copying from a binary file should instead be named .text
and marked as executable code. This allows disassembly with -d
to work later.llvm-objdump -d file.elf
This one's pretty self-explanatory (and the same as you'd write with GNU objdump
). -d
says to disassemble all code sections, and the only code section is the one that we marked using --rename-section
in the previous step.
1This command is for LLVM 10 and above. LLVM 10 has removed the binary-specific -B
option in favor of specifying your output target with the -O
option. For LLVM 9 and below, you'd use -B aarch64
.