elf.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <libelf.h>
00003 
00004 extern int errno;
00005 
00006 
00007 main(argc,argv)
00008 int argc;
00009 char *argv[];
00010 {
00011   char *fname;
00012   int elfd;
00013   Elf *elf;
00014   Elf32_Ehdr *ehdr;
00015   Elf_Scn *scn;
00016   Elf_Data *data;
00017   int i,j;
00018   char *cp;
00019 
00020   fname=argv[1];
00021   elfd=open(fname, 0);
00022   if (elfd<=0) { fprintf(stderr, "open error %d\n", errno); exit(2);}
00023   elf_version(EV_CURRENT);
00024   elf=elf_begin(elfd, ELF_C_READ, 0);
00025   printf("elf=%d\n", elf);
00026   if (elf==0) printf("%s\n", elf_errmsg(elf_errno()));
00027   ehdr=elf32_getehdr(elf);
00028   printf("elfhdr=%x\n", ehdr);
00029   printf("e_ident=");
00030   for (i=0; i<16; i++) {
00031     printf("%2x ", ehdr->e_ident[i]);}
00032   printf("\ne_type= %d\n", ehdr->e_type);
00033   printf("e_machine= %d\n", ehdr->e_machine);
00034   printf("e_version= %d\n", ehdr->e_version);
00035   printf("e_entry= 0x%x\n", ehdr->e_entry);
00036   printf("e_phoff= 0x%x\n", ehdr->e_phoff);
00037   printf("e_shoff= 0x%x\n", ehdr->e_shoff);
00038   printf("e_flags= 0x%x\n", ehdr->e_flags);
00039   printf("e_ehsize= 0x%x\n", ehdr->e_ehsize);
00040   printf("e_phentsize= %d\n", ehdr->e_phentsize);
00041   printf("e_phnum= %d\n", ehdr->e_phnum);
00042   printf("e_shentsize= %d\n", ehdr->e_shentsize);
00043   printf("e_shnum= %d\n", ehdr->e_shnum);
00044   printf("e_shstrndx= %d\n", ehdr->e_shstrndx);
00045 
00046   scn= elf_getscn(elf, ehdr->e_shstrndx);
00047   printf("string section = %x\n", scn);
00048   data=0; 
00049   data=elf_getdata(scn, data);
00050   i=data->d_size;
00051   cp=data->d_buf;
00052   while (i-->0) {
00053     printf("%c", *cp);
00054     if (*cp == 0) printf("\n");
00055     cp++;}
00056 
00057   elf_end(elf);
00058   }
00059 
00060 


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Mar 9 2017 04:57:49