| 167 | } |
| 168 | |
| 169 | void const* ResolveRealFunctionAddress(void const * ptr) |
| 170 | { |
| 171 | auto p = (uint8_t const*)ptr; |
| 172 | |
| 173 | // Unconditional jump |
| 174 | if (p[0] == 0xE9) { |
| 175 | int32_t relOffset = *reinterpret_cast<int32_t const *>(p + 1); |
| 176 | return p + relOffset + 5; |
| 177 | } |
| 178 | |
| 179 | // Resolve function pointer through relocations |
| 180 | auto end = p + 64; |
| 181 | for (; p < end; p++) |
| 182 | { |
| 183 | // Look for the instruction "cmp qword ptr [rip+xxxxxx], 0" |
| 184 | if (p[0] == 0x48 && p[1] == 0x83 && p[2] == 0x3d && p[6] == 0x00 && |
| 185 | // Look for the instruction "jmp xxxx" |
| 186 | p[13] == 0xe9) |
| 187 | { |
| 188 | int32_t relOffset = *reinterpret_cast<int32_t const *>(p + 14); |
| 189 | return p + relOffset + 18; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Could not find any relocations |
| 194 | return ptr; |
| 195 | } |
| 196 | |
| 197 | END_SE() |
no outgoing calls
no test coverage detected