Reputation: 53
In PE (for windows) it is possible to read the headers/sections of that structure by #include<windows.h>
and can use the struct PIMAGE_DOS_HEADER
to read the dos header in any PE file, for example.
How can i do that for ELF header in FreeBSD/Linux? What kind of preprocessor need to be added at the head of the C/C++ code? and Is there any difference between FreeBSD and Linux in term of the structure of ELF?
Upvotes: 4
Views: 1532
Reputation: 104080
I can't vouch for FreeBSD, but on Linux there are a lot of details in the elf(5)
manpage:
NAME
elf - format of Executable and Linking Format (ELF) files
SYNOPSIS
#include <elf.h>
DESCRIPTION
The header file <elf.h> defines the format of ELF executable
binary files. Amongst these files are normal executable
files, relocatable object files, core files and shared
libraries.
...
When I needed to understand ELF, I found nothing more useful than the MuppetLabs Tiny Executable walk-through. I'm sure many of the techniques are out-of-date (and were never a good idea), but they explained things very well.
Upvotes: 1
Reputation: 21566
Look at the sources of readelf. Or just google. For example, this http://www.scribd.com/doc/7027807/ELF-Format looks promising.
If you just want existing code, try http://www.linux.com/learn/docs/man/2838-elf5.
Upvotes: 2