| 77 | } |
| 78 | |
| 79 | static void perform_rebinding_with_section(struct rebindings_entry *rebindings, |
| 80 | section_t *section, |
| 81 | intptr_t slide, |
| 82 | nlist_t *symtab, |
| 83 | char *strtab, |
| 84 | uint32_t *indirect_symtab) { |
| 85 | uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1; |
| 86 | void **indirect_symbol_bindings = (void **)((uintptr_t)slide + section->addr); |
| 87 | for (uint i = 0; i < section->size / sizeof(void *); i++) { |
| 88 | uint32_t symtab_index = indirect_symbol_indices[i]; |
| 89 | if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL || |
| 90 | symtab_index == (INDIRECT_SYMBOL_LOCAL | INDIRECT_SYMBOL_ABS)) { |
| 91 | continue; |
| 92 | } |
| 93 | uint32_t strtab_offset = symtab[symtab_index].n_un.n_strx; |
| 94 | char *symbol_name = strtab + strtab_offset; |
| 95 | struct rebindings_entry *cur = rebindings; |
| 96 | while (cur) { |
| 97 | for (uint j = 0; j < cur->rebindings_nel; j++) { |
| 98 | if (strlen(symbol_name) > 1 && |
| 99 | strcmp(&symbol_name[1], cur->rebindings[j].name) == 0) { |
| 100 | if (cur->rebindings[j].replaced != NULL && |
| 101 | indirect_symbol_bindings[i] != cur->rebindings[j].replacement) { |
| 102 | *(cur->rebindings[j].replaced) = indirect_symbol_bindings[i]; |
| 103 | } |
| 104 | indirect_symbol_bindings[i] = cur->rebindings[j].replacement; |
| 105 | goto symbol_loop; |
| 106 | } |
| 107 | } |
| 108 | cur = cur->next; |
| 109 | } |
| 110 | symbol_loop:; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | static void rebind_symbols_for_image(struct rebindings_entry *rebindings, |
| 115 | const struct mach_header *header, |
no outgoing calls
no test coverage detected