I'm trying to read content of a file into a struct. The struct looks like this:
typedef struct{
unsigned char e_ident[EI_NIDENT] ;
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;
extern Elf32_Ehdr elfH;
It's basically an ELF header file. So, anyways i want to load content of a file into this structure.
The function looks like this.
Elf32_Ehdr elfH;
int load(char* fname){
FILE* file = fopen(fname,"r");
if(NULL == file) return 0;
fread(&elfH, 1, 52, file);
fclose(file);
return 1;
}
As it seems it's not working correctly. The content of elfH is not as expected. What might be the problem? Should i