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
00037 #include <stdio.h>
00038
00039 #include <rtld/elf_dyn.h>
00040 #include <rtld/dynamic.h>
00041 #include <rtld/rtld.h>
00042 #include <rtld/rtld_debug.h>
00043
00044 void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info)
00045 {
00046 elf_dyn_t *dp = dyn_ptr;
00047
00048 void *d_ptr;
00049 elf_word d_val;
00050
00051 elf_word soname_idx;
00052 elf_word rpath_idx;
00053
00054 DPRINTF("memset\n");
00055 memset(info, 0, sizeof(dyn_info_t));
00056
00057 soname_idx = 0;
00058 rpath_idx = 0;
00059
00060 DPRINTF("pass 1\n");
00061 while (dp->d_tag != DT_NULL) {
00062 d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
00063 d_val = dp->d_un.d_val;
00064 DPRINTF("tag=%u ptr=0x%x val=%u\n", (unsigned)dp->d_tag,
00065 (unsigned)d_ptr, (unsigned)d_val);
00066
00067 switch (dp->d_tag) {
00068
00069 case DT_PLTRELSZ: info->plt_rel_sz = d_val; break;
00070 case DT_PLTGOT: info->plt_got = d_ptr; break;
00071 case DT_HASH: info->hash = d_ptr; break;
00072 case DT_STRTAB: info->str_tab = d_ptr; break;
00073 case DT_SYMTAB: info->sym_tab = d_ptr; break;
00074 case DT_RELA: info->rela = d_ptr; break;
00075 case DT_RELASZ: info->rela_sz = d_val; break;
00076 case DT_RELAENT: info->rela_ent = d_val; break;
00077 case DT_STRSZ: info->str_sz = d_val; break;
00078 case DT_SYMENT: info->sym_ent = d_val; break;
00079 case DT_INIT: info->init = d_ptr; break;
00080 case DT_FINI: info->fini = d_ptr; break;
00081 case DT_SONAME: soname_idx = d_val; break;
00082 case DT_RPATH: rpath_idx = d_val; break;
00083 case DT_SYMBOLIC: info->symbolic = true; break;
00084 case DT_REL: info->rel = d_ptr; break;
00085 case DT_RELSZ: info->rel_sz = d_val; break;
00086 case DT_RELENT: info->rel_ent = d_val; break;
00087 case DT_PLTREL: info->plt_rel = d_val; break;
00088 case DT_TEXTREL: info->text_rel = true; break;
00089 case DT_JMPREL: info->jmp_rel = d_ptr; break;
00090 case DT_BIND_NOW: info->bind_now = true; break;
00091
00092 default:
00093 if (dp->d_tag >= DT_LOPROC && dp->d_tag <= DT_HIPROC)
00094 dyn_parse_arch(dp, bias, info);
00095 break;
00096 }
00097
00098 ++dp;
00099 }
00100
00101 info->soname = info->str_tab + soname_idx;
00102 info->rpath = info->str_tab + rpath_idx;
00103
00104
00105 info->dynamic = dyn_ptr;
00106
00107 DPRINTF("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n",
00108 (uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname);
00109 DPRINTF("soname='%s'\n", info->soname);
00110 DPRINTF("rpath='%s'\n", info->rpath);
00111 DPRINTF("hash=0x%x\n", (uintptr_t)info->hash);
00112 DPRINTF("dt_rela=0x%x\n", (uintptr_t)info->rela);
00113 DPRINTF("dt_rela_sz=0x%x\n", (uintptr_t)info->rela_sz);
00114 DPRINTF("dt_rel=0x%x\n", (uintptr_t)info->rel);
00115 DPRINTF("dt_rel_sz=0x%x\n", (uintptr_t)info->rel_sz);
00116
00117
00118
00119
00120
00121
00122 DPRINTF("pass 2\n");
00123 dp = dyn_ptr;
00124 while (dp->d_tag != DT_NULL) {
00125 d_val = dp->d_un.d_val;
00126
00127 switch (dp->d_tag) {
00128 case DT_NEEDED:
00129
00130 info->needed = info->str_tab + d_val;
00131 DPRINTF("needed:'%s'\n", info->needed);
00132 break;
00133
00134 default: break;
00135 }
00136
00137 ++dp;
00138 }
00139 }
00140