# Include "elf. H"
# Include <stdio. h>
Int main (INT argc, char * argv [])
{
File * FP;
Int I = 0;
Int FD = 0;
Elf64_ehdr EHDR;
If (FP = fopen (argv [1], "R") = NULL)
{
Perror ("open ");
Return-1;
}
Else
{
Printf ("% s \ n", argv [1]);
FD = fread (& EHDR, 1, sizeof (elf64_ehdr), FP );
If (FD = sizeof (elf64_ehdr ))
{
If (EHDR. e_ident [ei_mag0]! = Elfmag0 |
EHDR. e_ident [ei_mag1]! = Elfmag1 |
EHDR. e_ident [ei_mag2]! = Elfmag2 |
EHDR. e_ident [ei_mag3]! = Elfmag3 ){
Perror ("the file is not a valid ELF File ");
Return-1;
}
Printf ("Number of table items in section header table % LD \ n", (long INT) EHDR. e_shnum); // Number of segment Headers
}
Elf64_shdr shdr [EHDR. e_shnum];
Fseek (FP, EHDR. e_shoff, 0 );
For (I = 0; I <EHDR. e_shnum; I ++)
{
Fread (& shdr [I], EHDR. e_shentsize, 1, FP );
Printf ("Table item (segment header) points to the segment address % LD \ n", (long INT) shdr [I]. sh_offset );
}
Fclose (FP );
}
Return 0;
}
Check whether the opened file is an elf file. If yes, the number of partitions in the table in the header table is output, and the address of the Section pointed to by the partitions in each table.