Rev 2999 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2999 | Rev 3562 | ||
---|---|---|---|
Line 37... | Line 37... | ||
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 | ||
Line 48... | Line 49... | ||
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) { |
Line 96... | Line 97... | ||
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 |