How to retrieve a block of binary from .text section in an executable?
I know objcopy can help by using:
objcopy --only-section=.text --output-target binary a.out a.out.bin
But it would be much better if I can realize the same goal within a function call using BFD library. Is there any way to call objcopy using function calls?
You probably are looking for function in binutils / bfd libs. You can find doc at http://www.delorie.com/gnu/docs/binutils/bfd_toc.html and I think the function you are looking for is:
whose doc can be find at http://www.delorie.com/gnu/docs/binutils/bfd_57.html