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.

Source: Internet
Author: User
# 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.