00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <err.h>
00034 #include <fcntl.h>
00035 #include <gelf.h>
00036 #include <libelf.h>
00037 #include <stdio.h>
00038 #include <stdint.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <ctype.h>
00042 #include <sysexits.h>
00043 #include <unistd.h>
00044
00045 #include "messg.h"
00046 #include "rta.h"
00047 #include "rta_scn.h"
00048
00049 INT Dump_Rta_Scns(const char *elfFile)
00050 {
00051 INT fd;
00052 Elf *e;
00053 char *name, *p, pc[4*sizeof(char)];
00054 Elf_Scn *scn;
00055 Elf_Data *data;
00056 GElf_Shdr shdr;
00057 GElf_Ehdr ehdr;
00058 size_t n, shstrndx, sz;
00059 INT n_rtascn;
00060
00061 if (elf_version(EV_CURRENT) == EV_NONE)
00062 errx(EX_SOFTWARE, "ELF library initialization failed: %s",
00063 elf_errmsg(-1));
00064
00065 if ((fd = open(elfFile, O_RDONLY, 0)) < 0)
00066 err(EX_NOINPUT, "open \%s\" failed", elfFile);
00067
00068 if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
00069 errx(EX_SOFTWARE, "elf_begin() failed: %s.",
00070 elf_errmsg(-1));
00071
00072 if (elf_kind(e) != ELF_K_ELF)
00073 errx(EX_DATAERR, "%s is not an ELF object.", elfFile);
00074
00075 if (gelf_getehdr(e, &ehdr) == NULL)
00076 errx(EX_SOFTWARE, "getehdr() failed: %s.",
00077 elf_errmsg(-1));
00078
00079
00080 shstrndx = ehdr.e_shstrndx;
00081
00082 scn = NULL;
00083 n_rtascn = 0;
00084
00085 while ((scn = elf_nextscn(e, scn)) != NULL) {
00086 if (gelf_getshdr(scn, &shdr) != &shdr)
00087 errx(EX_SOFTWARE, "getshdr() failed: %s.",
00088 elf_errmsg(-1));
00089
00090 if ((name = elf_strptr(e, shstrndx, shdr.sh_name)) == NULL)
00091 errx(EX_SOFTWARE, "elf_strptr() failed: %s.",
00092 elf_errmsg(-1));
00093
00094 if (strncmp(name, RTA_SCN_NAME_PREFIX, RTA_SCN_NAME_PREFIX_LEN) !=0 )
00095 continue;
00096
00097 n_rtascn ++;
00098 printf("Section %-4.4jd %s\n", (uintmax_t) elf_ndxscn(scn),
00099 name);
00100
00101 }
00102
00103 printf("RTA section number in file %s: %d\n", elfFile, n_rtascn);
00104
00105 elf_end(e);
00106 close(fd);
00107 return 0;
00108 }
00109