1

I want to use objdump to disassemble an ELF to "clean" assembly that can be assembled directly. However, the raw output of objdump contains descriptive text such as:

Disassembly of section .text:

0000000000002c00 <__grow_type_table>:
    2c00:       41 55                   push   %r13
    2c02:       41 54                   push   %r12
    2c04:       ba 00 10 00 00          mov    $0x1000,%edx

So I'm wondering is there an option to generate clean code?

qweruiop
  • 3,156
  • 6
  • 31
  • 55
  • 1
    No, objdump and disassemblers in general aren't designed to produce output that can be reassembled back into the original code. Not only is there that extra output (which could be easily cut out) there's various things missing. Also note that even it did produce assembly output that could recreate the input, it wouldn't be very useful. Information is lost when a assembly file is translated into an object file and again more information is lost when the object files are linked to create an executable. It won't give you something you can easily edit to do something different. – Ross Ridge Sep 22 '16 at 21:30
  • Agner Fog's `objconv` disassembler produces output in valid NASM, YASM, MASM, or GNU syntax, with extra info in comments. But no dialect of x86 asm allows specifying all the encoding choices to guarantee that the result is byte-for-byte identical, or even that the instructions are all the same size. The code might depend on having a wider-than-necessary encoding for something (e.g. `jmp rel32` instead of `jmp rel8`) in some special sections. (e.g. that will be modified during runtime dynamic linking). This is the same point Ross made. – Peter Cordes Sep 23 '16 at 02:10

0 Answers0