How can I extract the raw machine code of a function from a .o object file? Built from gnu c++ using g++. File format is 32-bit relocatable LSB ELF, architecture i386. Any thoughts? Thanks in advance
-
objdump ?Paul R– Paul R2018-06-01 22:19:00 +00:00Commented Jun 1, 2018 at 22:19
-
Does that give raw machine code of a specific function?user5718553– user57185532018-06-01 22:22:05 +00:00Commented Jun 1, 2018 at 22:22
-
Click on the link to the man page above - there is an option to disassemble, and you can probably find an option to just dump the raw bytes too. Be aware though that since .o files have not been linked there will be placeholders for function/data addresses etc which need to be resolved at link time.Paul R– Paul R2018-06-01 22:32:46 +00:00Commented Jun 1, 2018 at 22:32
-
See also: readelf.Paul R– Paul R2018-06-01 22:35:22 +00:00Commented Jun 1, 2018 at 22:35
Add a comment
|
1 Answer
objdump -dw mybinary
The above command always works, but objdump provides more human friendly results if you compile with debugging enabled, namely the g++ -g option.
1 Comment
Peter Cordes
I like
objdump -drwC -Mintel. -r gives symbol-relocation info, which is necessary in a .o because addresses of external symbols are still all-zero (or actually an offset relative to some symbol), not a real address. -C is C++ name demangling.