0

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

4
  • objdump ? Commented Jun 1, 2018 at 22:19
  • Does that give raw machine code of a specific function? Commented 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. Commented Jun 1, 2018 at 22:32
  • See also: readelf. Commented Jun 1, 2018 at 22:35

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.