MCPcopy Create free account
hub / github.com/clementgallet/libTAS / eh_init_obj

Function eh_init_obj

src/external/elfhacks.cpp:152–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152int eh_init_obj(eh_obj_t *obj)
153{
154 /*
155 ELF spec says in section header documentation, that:
156 "An object file may have only one dynamic section."
157
158 Let's assume it means that object has only one PT_DYNAMIC
159 as well.
160 */
161 int p;
162 obj->dynamic = NULL;
163 for (p = 0; p < obj->phnum; p++) {
164 if (obj->phdr[p].p_type == PT_DYNAMIC) {
165 if (obj->dynamic)
166 return ENOTSUP;
167
168 obj->dynamic = (ElfW(Dyn) *) (obj->phdr[p].p_vaddr + obj->addr);
169 }
170 }
171
172 if (!obj->dynamic)
173 return ENOTSUP;
174
175 /*
176 ELF spec says that program is allowed to have more than one
177 .strtab but does not describe how string table indexes translate
178 to multiple string tables.
179
180 And spec says that only one SHT_HASH is allowed, does it mean that
181 obj has only one DT_HASH?
182
183 About .symtab it does not mention anything about if multiple
184 symbol tables are allowed or not.
185
186 Maybe st_shndx is the key here?
187 */
188 obj->strtab = NULL;
189 obj->hash = NULL;
190 obj->gnu_hash = NULL;
191 obj->symtab = NULL;
192 p = 0;
193 while (obj->dynamic[p].d_tag != DT_NULL) {
194 if (obj->dynamic[p].d_tag == DT_STRTAB) {
195 if (obj->strtab)
196 return ENOTSUP;
197
198 obj->strtab = (const char *) obj->dynamic[p].d_un.d_ptr;
199 } else if (obj->dynamic[p].d_tag == DT_HASH) {
200 if (obj->hash)
201 return ENOTSUP;
202
203 obj->hash = (ElfW(Word) *) obj->dynamic[p].d_un.d_ptr;
204 } else if (obj->dynamic[p].d_tag == DT_GNU_HASH) {
205 if (obj->gnu_hash)
206 return ENOTSUP;
207
208 obj->gnu_hash = (Elf32_Word *) obj->dynamic[p].d_un.d_ptr;
209 } else if (obj->dynamic[p].d_tag == DT_SYMTAB) {

Callers 2

eh_iterate_callbackFunction · 0.85
eh_find_objFunction · 0.85

Calls 1

eh_check_addrFunction · 0.85

Tested by

no test coverage detected