- Simplify assembler instructions so that we mess around less.

This commit is contained in:
Michael Dirks
2015-12-30 06:24:35 +01:00
parent 88122a928a
commit 57c310b0fc
+7 -15
View File
@@ -55,34 +55,26 @@ DLL_METHOD intptr_t DLL_CALL BP_GetFunctionPointer()
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable) DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable)
{ {
intptr_t StackPointer, ReturnAddress; intptr_t BasePointer;
__asm { //ASM. Do touch if suicidal. __asm { //ASM. Do touch if suicidal.
mov StackPointer, esp; // Store current Stack Pointer mov BasePointer, ebp; // Store current BasePointer
mov esp, ebp; // On X86, EBP[0] is our own function and EBP[1] is the return address.
add esp, 4; // Which means that we can just take it from there into our own variable.
pop ReturnAddress; // Just like this.
mov esp, [StackPointer]; // And then reset the Stack Pointer.
} }
// The Variable pointer that is used is at -9 bytes offset to the return address. // The Variable pointer that is used is at -9 bytes offset to the return address.
return *reinterpret_cast<int32_t*>(ReturnAddress - 9); return *reinterpret_cast<int32_t*>(*reinterpret_cast<intptr_t*>(BasePointer + 4) - 9);
} }
#pragma comment(linker, "/EXPORT:BP_GetVariablePointer=_BP_GetVariablePointer@4") #pragma comment(linker, "/EXPORT:BP_GetVariablePointer=_BP_GetVariablePointer@4")
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointerType( int32_t pVariable ) { DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointerType( int32_t pVariable ) {
intptr_t StackPointer, ReturnAddress; intptr_t BasePointer;
__asm { //ASM. Do touch if suicidal. __asm { //ASM. Do touch if suicidal.
mov StackPointer, esp; // Store current Stack Pointer mov BasePointer, ebp; // Store current BasePointer
mov esp, ebp; // On X86, EBP[0] is our own function and EBP[1] is the return address.
add esp, 4; // Which means that we can just take it from there into our own variable.
pop ReturnAddress; // Just like this.
mov esp, [StackPointer]; // And then reset the Stack Pointer.
} }
// The Variable pointer that is used is at -9 bytes offset to the return address. // The Variable pointer that is used is at -11 bytes offset to the return address.
return *reinterpret_cast<int32_t*>(ReturnAddress - 11); return *reinterpret_cast<int32_t*>(*reinterpret_cast<intptr_t*>(BasePointer + 4) - 11);
} }
#pragma comment(linker, "/EXPORT:BP_GetVariablePointerType=_BP_GetVariablePointerType@4") #pragma comment(linker, "/EXPORT:BP_GetVariablePointerType=_BP_GetVariablePointerType@4")