How to retrieve flat binary from an executable file in C

1k Views Asked by At

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?

1

There are 1 best solutions below

0
On

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:

boolean bfd_get_section_contents (bfd *abfd, asection *section,
    PTR location, file_ptr offset,
    bfd_size_type count);

whose doc can be find at http://www.delorie.com/gnu/docs/binutils/bfd_57.html