I am trying to implement a functionality similar to objcopy where bytes of a binary file (specifically the .text section) will be printed out using open()
and read()
. How would I set the buffer sizes and iterate till the end of a .text
section so that I don't read more bytes than I have to in order to avoid errors?
C program to open binary elf files, read from them, and print them out (like objcopy)
1.1k Views Asked by Aaron Li At
1
Here is how you read a file using
open()
andread()
.P.S I used
fopen()
andfread()
instead ofopen()
andread()
because I am currently working with a Windows machine. However, the results will be the same for either.Update: For interpreting ELF files specifically, I would recommend taking a look at the following resources:
Check out the following code snippet. It shows how you can interpret an ELF file.
I would also recommend checking out the elfutils library, which can be found here.