Extract function bytes from ELF binary file

Viewed 1930

I want to write a python script which extracts a function opcodes from an elf binary knowing its address e.g 0x437310 and size. How can I map this address to the corresponding offset in the binary file to start read from it ?

Using a hex editor I can figure-out that function at 0x437310 starts at offset 0x37310 in the hexdump.

How can I calculate this in a generic way, since the imagebase of a binary is not always the same.

any help will be appreciated

1 Answers
Related