How to disassemble a binary executable in Linux to get the assembly code?

后端 未结 9 1320
情歌与酒
情歌与酒 2020-11-28 02:57

I was told to use a disassembler. Does gcc have anything built in? What is the easiest way to do this?

9条回答
  •  难免孤独
    2020-11-28 03:19

    You can come pretty damn close (but no cigar) to generating assembly that will reassemble, if that's what you are intending to do, using this rather crude and tediously long pipeline trick (replace /bin/bash with the file you intend to disassemble and bash.S with what you intend to send the output to):

    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
    

    Note how long this is, however. I really wish there was a better way (or, for that matter, a disassembler capable of outputting code that an assembler will recognize), but unfortunately there isn't.

提交回复
热议问题