MCPcopy Create free account
hub / github.com/Norbyte/bg3se / ResolveRealFunctionAddress

Function ResolveRealFunctionAddress

CoreLib/Utils.cpp:169–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169void 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
197END_SE()

Callers 8

SetWrapperMethod · 0.85
SetPreHookMethod · 0.85
SetPostHookMethod · 0.85
SetPrePostHookMethod · 0.85
InitializeMethod · 0.85
FindOsirisGlobalsMethod · 0.85
FindDebugFlagsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected