THe elf file is static linked
and currently the objdump's output is something like:
Disassembly of section: .init:
xxxxxx
Disassembly of section: .plt:
xxxxxx
Disassembly of section: .text:
xxxxxx
basically what I want to achieve is
"elf-file -(disassemble by objdump)-> assemble file --(re-compile)--> same functionality"
I don't need the re-compiled binary has the binary content same as the original one, only same functionality is enough.
After a quick search, basically the answer is no, and they argued that disassemble file lost some stuff like symbolic information or others, but I think by static link, I can get rid of this issue...
Thank you!
objdump -S -d elf-file
is not usually sufficient, as it lacks.data
section.But it seems that
objdump -S -D elf-file
is sufficient.To try this, I wrote a small x86-64 assembly file that uses
extern printf
, assembled it with YASM without debug symbols and linked with GCC.Then I disassembled it with
objdump -S -D -M intel elf-file >objdump_output.txt
.-M intel
produces the disassembly in Intel format. AT&T would work too, but I prefer Intel format for its clarity.Then I wrote a small
gawk
programobjdump_to_asm
to convert the disassembly produced byobjdump -S -D -M intel elf-file >objdump_output.txt
into a suitable format for YASM. Assumes x86-64 code andmain
as entry point. Can be easily edited to different kinds of environment (x86 is trivial, others may need more work). Usage./objdump_to_asm objdump_output.txt
. Interestingly 1st generation executable has size of 6598 bytes, whereas 2nd generation executable has size of only 6496 bytes. 3rd generation assembly code is identical with the 2nd generation assembly code.Here's the code:
Executing
./objdump_to_asm objdump_output.txt >2nd_generation.asm
produces the following assembly file. Assembles with YASM, links with GCC. The assembled and linked executable is not identical with the original, actually it's 6496 bytes, whereas the original executable has size of 6568 bytes.