| 105 | } |
| 106 | |
| 107 | static bool FindVFunc(void *handle, void **vtable, const char* vtable_end, const char *class_function, const char *params, VOffset *offsets) |
| 108 | { |
| 109 | Dl_info d; |
| 110 | |
| 111 | int linux_offset = -1; |
| 112 | int windows_offset = -1; |
| 113 | |
| 114 | int overloads = 0; |
| 115 | int location = 0; |
| 116 | int start_offset = -1; |
| 117 | |
| 118 | for (int i=0; i< 1000; i++) |
| 119 | { |
| 120 | void *FuncPtr = vtable[i]; |
| 121 | |
| 122 | int status = dladdr(FuncPtr, &d); |
| 123 | |
| 124 | if (!status) |
| 125 | { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | if (i > 1 && strncmp(d.dli_sname, vtable_end, strlen(vtable_end)) == 0) |
| 130 | { |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | char *name = cplus_demangle(d.dli_sname, DMGL_PARAMS); |
| 135 | |
| 136 | if (name == NULL) |
| 137 | { |
| 138 | printf("Demangling failed\n"); |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | char *foundfunction = strpbrk(name, ":"); |
| 143 | |
| 144 | if (foundfunction == NULL) |
| 145 | { |
| 146 | //printf("Couldnt split function\n"); |
| 147 | free(name); |
| 148 | continue; |
| 149 | } |
| 150 | |
| 151 | //Skip both ':' chars |
| 152 | foundfunction += 2; |
| 153 | |
| 154 | |
| 155 | if (strncmp(foundfunction, class_function, strlen(class_function)) == 0 && foundfunction[strlen(class_function)] == '(') |
| 156 | { |
| 157 | //printf("Symbol: %s Demangled: %s Offset: %i\n", d.dli_sname, name, i); |
| 158 | |
| 159 | //We have a pointer to a function, but it may be overloaded. |
| 160 | overloads++; |
| 161 | |
| 162 | if (start_offset == -1) |
| 163 | { |
| 164 | start_offset = i-1; |