0

The closest I could get to answering my own question here is with this long chain of pipes through grep, sed, cut, tr, grep, and back again (in this example “bash” could be replaced with anything):

objdump --no-show-raw-insn -Matt,att-mnemonic -Dz /bin/bash | grep -v "file format" | grep -v "(bad)" | sed '1,4d' | cut -d' ' -f2- | cut -d '<' -f2 | tr -d '>' | cut -f2- | sed -e "s/of\ section/#Disassembly\ of\ section/" | grep -v "\.\.\." > bash.S

This, however, comes with the drawback of stripping some assembly lines out of the code and also syntactically malforming some other lines that happen to start in the first field and not the second. There has to be a better, cleaner way to do this.

realkstrawn93
  • 722
  • 1
  • 6
  • 13
  • 1
    If this is for x86, use a disassembler that makes ready-to-assemble output: Agner Fog's `objconv` which supports AT&T, NASM, or MASM output syntaxes. [How to disassemble a binary executable in Linux to get the assembly code?](//stackoverflow.com/a/33978857) – Peter Cordes Nov 15 '19 at 08:45

1 Answers1

0

Okay, objconv definitely works. Doesn’t have the means to disassemble Windows executables the way objdump does, but still works marvelously on Linux executables. UPDATE: Looked at the manpage — it actually does disassemble Windows executables too.

realkstrawn93
  • 722
  • 1
  • 6
  • 13