struct DataOffest parseSoHeader(
FILE
*
fp,struct DataOffest off)
{
Elf32_Ehdr header;
int
i
=
0
;
fseek(fp,
0
,SEEK_SET);
fread(&header,
1
,sizeof(header),fp);
printf(
"ELF Header:\n"
);
printf(
" Header Magic: "
);
for
(i
=
0
; i <
16
; i
+
+
)
{
printf(
"%02x "
,header.e_ident[i]);
}
printf(
"\n"
);
printf(
" So File Type: 0x%02x"
,header.e_type);
switch (header.e_type)
{
case
0x00
:
printf(
"(No file type)\n"
);
break
;
case
0x01
:
printf(
"(Relocatable file)\n"
);
break
;
case
0x02
:
printf(
"(Executable file)\n"
);
break
;
case
0x03
:
printf(
"(Shared object file)\n"
);
break
;
case
0x04
:
printf(
"(Core file)\n"
);
break
;
case
0xff00
:
printf(
"(Beginning of processor-specific codes)\n"
);
break
;
case
0xffff
:
printf(
"(Processor-specific)\n"
);
break
;
default:
printf(
"\n"
);
break
;
}
printf(
" Required Architecture: 0x%04x"
,header.e_machine);
if
(header.e_machine
=
=
0x28
)
{
printf(
"(ARM)\n"
);
}
else
{
printf(
"\n"
);
}
printf(
" Version: 0x%02x\n"
,header.e_version);
printf(
" Start Program Address: 0x%08x\n"
,header.e_entry);
printf(
" Program Header Offest: 0x%08x\n"
,header.e_phoff);
off.programheadoffset
=
header.e_phoff;
printf(
" Section Header Offest: 0x%08x\n"
,header.e_shoff);
off.sectionheadoffest
=
header.e_shoff;
printf(
" Processor-specific Flags: 0x%08x\n"
,header.e_flags);
printf(
" ELF Header Size: 0x%04x\n"
,header.e_ehsize);
printf(
" Size of an entry in the program header table: 0x%04x\n"
,header.e_phentsize);
printf(
" Program Header Size: 0x%04x\n"
,header.e_phnum);
off.programsize
=
header.e_phnum;
printf(
" Size of an entry in the section header table: 0x%04x\n"
,header.e_shentsize);
printf(
" Section Header Size: 0x%04x\n"
,header.e_shnum);
off.sectionsize
=
header.e_shnum;
printf(
" String Section Index: 0x%04x\n"
,header.e_shstrndx);
off.shstrtabindex
=
header.e_shstrndx;
return
off;
}