Rev 2999 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2999 | Rev 3562 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
2 | * Copyright (c) 2008 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup rtld rtld |
29 | /** @addtogroup rtld rtld |
30 | * @brief |
30 | * @brief |
31 | * @{ |
31 | * @{ |
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | #include <string.h> |
38 | #include <string.h> |
39 | 39 | ||
40 | #include <elf_dyn.h> |
40 | #include <elf_dyn.h> |
41 | #include <dynamic.h> |
41 | #include <dynamic.h> |
- | 42 | #include <rtld.h> |
|
42 | 43 | ||
43 | void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info) |
44 | void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info) |
44 | { |
45 | { |
45 | elf_dyn_t *dp = dyn_ptr; |
46 | elf_dyn_t *dp = dyn_ptr; |
46 | 47 | ||
47 | void *d_ptr; |
48 | void *d_ptr; |
48 | elf_word d_val; |
49 | elf_word d_val; |
49 | 50 | ||
50 | elf_word soname_idx; |
51 | elf_word soname_idx; |
51 | elf_word rpath_idx; |
52 | elf_word rpath_idx; |
52 | 53 | ||
53 | printf("memset\n"); |
54 | DPRINTF("memset\n"); |
54 | memset(info, 0, sizeof(info)); |
55 | memset(info, 0, sizeof(info)); |
55 | 56 | ||
56 | soname_idx = 0; |
57 | soname_idx = 0; |
57 | rpath_idx = 0; |
58 | rpath_idx = 0; |
58 | 59 | ||
59 | printf("pass 1\n"); |
60 | DPRINTF("pass 1\n"); |
60 | while (dp->d_tag != DT_NULL) { |
61 | while (dp->d_tag != DT_NULL) { |
61 | d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias); |
62 | d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias); |
62 | d_val = dp->d_un.d_val; |
63 | d_val = dp->d_un.d_val; |
63 | 64 | ||
64 | switch (dp->d_tag) { |
65 | switch (dp->d_tag) { |
65 | 66 | ||
66 | case DT_PLTRELSZ: info->plt_rel_sz = d_val; break; |
67 | case DT_PLTRELSZ: info->plt_rel_sz = d_val; break; |
67 | case DT_PLTGOT: info->plt_got = d_ptr; break; |
68 | case DT_PLTGOT: info->plt_got = d_ptr; break; |
68 | case DT_HASH: info->hash = d_ptr; break; |
69 | case DT_HASH: info->hash = d_ptr; break; |
69 | case DT_STRTAB: info->str_tab = d_ptr; break; |
70 | case DT_STRTAB: info->str_tab = d_ptr; break; |
70 | case DT_SYMTAB: info->sym_tab = d_ptr; break; |
71 | case DT_SYMTAB: info->sym_tab = d_ptr; break; |
71 | case DT_RELA: info->rela = d_ptr; break; |
72 | case DT_RELA: info->rela = d_ptr; break; |
72 | case DT_RELASZ: info->rela_sz = d_val; break; |
73 | case DT_RELASZ: info->rela_sz = d_val; break; |
73 | case DT_RELAENT: info->rela_ent = d_val; break; |
74 | case DT_RELAENT: info->rela_ent = d_val; break; |
74 | case DT_STRSZ: info->str_sz = d_val; break; |
75 | case DT_STRSZ: info->str_sz = d_val; break; |
75 | case DT_SYMENT: info->sym_ent = d_val; break; |
76 | case DT_SYMENT: info->sym_ent = d_val; break; |
76 | case DT_INIT: info->init = d_ptr; break; |
77 | case DT_INIT: info->init = d_ptr; break; |
77 | case DT_FINI: info->fini = d_ptr; break; |
78 | case DT_FINI: info->fini = d_ptr; break; |
78 | case DT_SONAME: soname_idx = d_val; break; |
79 | case DT_SONAME: soname_idx = d_val; break; |
79 | case DT_RPATH: rpath_idx = d_val; break; |
80 | case DT_RPATH: rpath_idx = d_val; break; |
80 | case DT_SYMBOLIC: info->symbolic = true; break; |
81 | case DT_SYMBOLIC: info->symbolic = true; break; |
81 | case DT_REL: info->rel = d_ptr; break; |
82 | case DT_REL: info->rel = d_ptr; break; |
82 | case DT_RELSZ: info->rel_sz = d_val; break; |
83 | case DT_RELSZ: info->rel_sz = d_val; break; |
83 | case DT_RELENT: info->rel_ent = d_val; break; |
84 | case DT_RELENT: info->rel_ent = d_val; break; |
84 | case DT_PLTREL: info->plt_rel = d_val; break; |
85 | case DT_PLTREL: info->plt_rel = d_val; break; |
85 | case DT_TEXTREL: info->text_rel = true; break; |
86 | case DT_TEXTREL: info->text_rel = true; break; |
86 | case DT_JMPREL: info->jmp_rel = d_ptr; break; |
87 | case DT_JMPREL: info->jmp_rel = d_ptr; break; |
87 | case DT_BIND_NOW: info->bind_now = true; break; |
88 | case DT_BIND_NOW: info->bind_now = true; break; |
88 | 89 | ||
89 | default: break; |
90 | default: break; |
90 | } |
91 | } |
91 | 92 | ||
92 | ++dp; |
93 | ++dp; |
93 | } |
94 | } |
94 | 95 | ||
95 | info->soname = info->str_tab + soname_idx; |
96 | info->soname = info->str_tab + soname_idx; |
96 | info->rpath = info->str_tab + rpath_idx; |
97 | info->rpath = info->str_tab + rpath_idx; |
97 | 98 | ||
98 | /* This will be useful for parsing dependencies later */ |
99 | /* This will be useful for parsing dependencies later */ |
99 | info->dynamic = dyn_ptr; |
100 | info->dynamic = dyn_ptr; |
100 | 101 | ||
101 | printf("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n", |
102 | DPRINTF("str_tab=0x%x, soname_idx=0x%x, soname=0x%x\n", |
102 | (uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname); |
103 | (uintptr_t)info->soname, soname_idx, (uintptr_t)info->soname); |
103 | printf("soname='%s'\n", info->soname); |
104 | DPRINTF("soname='%s'\n", info->soname); |
104 | printf("rpath='%s'\n", info->rpath); |
105 | DPRINTF("rpath='%s'\n", info->rpath); |
105 | printf("hash=0x%x\n", (uintptr_t)info->hash); |
106 | DPRINTF("hash=0x%x\n", (uintptr_t)info->hash); |
106 | 107 | ||
107 | /* |
108 | /* |
108 | * Now that we have a pointer to the string table, |
109 | * Now that we have a pointer to the string table, |
109 | * we can parse DT_NEEDED fields (which contain offsets into it). |
110 | * we can parse DT_NEEDED fields (which contain offsets into it). |
110 | */ |
111 | */ |
111 | 112 | ||
112 | printf("pass 2\n"); |
113 | DPRINTF("pass 2\n"); |
113 | dp = dyn_ptr; |
114 | dp = dyn_ptr; |
114 | while (dp->d_tag != DT_NULL) { |
115 | while (dp->d_tag != DT_NULL) { |
115 | d_val = dp->d_un.d_val; |
116 | d_val = dp->d_un.d_val; |
116 | 117 | ||
117 | switch (dp->d_tag) { |
118 | switch (dp->d_tag) { |
118 | case DT_NEEDED: |
119 | case DT_NEEDED: |
119 | /* Assume just for now there's only one dependency */ |
120 | /* Assume just for now there's only one dependency */ |
120 | info->needed = info->str_tab + d_val; |
121 | info->needed = info->str_tab + d_val; |
121 | printf("needed:'%s'\n", info->needed); |
122 | DPRINTF("needed:'%s'\n", info->needed); |
122 | break; |
123 | break; |
123 | 124 | ||
124 | default: break; |
125 | default: break; |
125 | } |
126 | } |
126 | 127 | ||
127 | ++dp; |
128 | ++dp; |
128 | } |
129 | } |
129 | } |
130 | } |
130 | 131 | ||
131 | /** @} |
132 | /** @} |
132 | */ |
133 | */ |
133 | 134 |