2015-06-06 18:19:10 +02:00
|
|
|
// BlitzPointer - Adding Pointers to Blitz.
|
2015-12-30 05:11:33 +01:00
|
|
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
2015-06-06 18:19:10 +02:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
// Idea take from Code by Noodoby<http://www.blitzforum.de/forum/viewtopic.php?t=31651>
|
2015-12-30 05:11:33 +01:00
|
|
|
// New Code by Xaymar<http://xaymar.com>
|
2015-05-17 11:54:23 +02:00
|
|
|
|
2015-06-20 16:20:03 +02:00
|
|
|
#pragma once
|
2015-05-17 11:54:23 +02:00
|
|
|
#include "BlitzPointer.h"
|
|
|
|
|
|
2015-06-20 15:08:27 +02:00
|
|
|
DLL_METHOD intptr_t DLL_CALL BP_GetReturnAddress() {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_GetReturnAddress=_BP_GetReturnAddress@0")
|
2015-12-30 06:19:44 +01:00
|
|
|
intptr_t BasePointer, ReturnAddress;
|
2015-05-17 11:54:23 +02:00
|
|
|
|
|
|
|
|
__asm { //ASM. Do touch if suicidal.
|
2015-12-30 06:19:44 +01:00
|
|
|
mov BasePointer, ebp; // Store current BasePointer
|
2015-05-17 11:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-30 06:19:44 +01:00
|
|
|
// Blitz uses X86 Call-Near (E8) instructions to call its own functions.
|
|
|
|
|
// We can simply deduce the Return Address like this because of that.
|
2016-02-06 00:16:32 +01:00
|
|
|
//-- Parent_EBP = *EBP
|
|
|
|
|
//-- Parent_RP = Parent_EBP + 16
|
2016-02-06 00:22:24 +01:00
|
|
|
ReturnAddress = *(intptr_t*)((*(intptr_t*)BasePointer) + 16);
|
2015-12-30 06:19:44 +01:00
|
|
|
|
2015-05-17 11:54:23 +02:00
|
|
|
return ReturnAddress;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 18:32:16 +01:00
|
|
|
DLL_METHOD intptr_t DLL_CALL BP_GetFunctionPointer() {
|
|
|
|
|
#pragma comment(linker, "/EXPORT:BP_GetFunctionPointer=_BP_GetFunctionPointer@0")
|
2015-12-30 06:19:44 +01:00
|
|
|
intptr_t BasePointer, ReturnAddress, FunctionPointer;
|
2015-05-17 11:54:23 +02:00
|
|
|
|
|
|
|
|
__asm { //ASM. Do touch if suicidal.
|
2015-12-30 06:19:44 +01:00
|
|
|
mov BasePointer, ebp; // Store current BasePointer
|
2015-05-17 11:54:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-30 06:19:44 +01:00
|
|
|
// Blitz uses X86 Call-Near (E8) instructions to call its own functions.
|
|
|
|
|
// We can simply deduce the Return Address like this because of that.
|
2016-02-06 00:16:32 +01:00
|
|
|
//-- Parent_EBP = *EBP
|
|
|
|
|
//-- Parent_RP = Parent_EBP + 16
|
|
|
|
|
ReturnAddress = *(intptr_t*)((*(intptr_t*)BasePointer) + 16);
|
|
|
|
|
|
2015-12-30 06:19:44 +01:00
|
|
|
// And since it's a Call-Near, the call is offset to the return address.
|
2016-02-06 00:16:32 +01:00
|
|
|
FunctionPointer = ReturnAddress + *(intptr_t*)(ReturnAddress - 4);
|
2015-05-17 11:54:23 +02:00
|
|
|
|
2015-12-30 06:19:44 +01:00
|
|
|
return FunctionPointer;
|
2015-05-17 11:54:23 +02:00
|
|
|
}
|
2016-01-04 03:43:35 +01:00
|
|
|
|
2016-02-06 18:32:16 +01:00
|
|
|
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable) {
|
|
|
|
|
#pragma comment(linker, "/EXPORT:BP_GetVariablePointer=_BP_GetVariablePointer@4")
|
2015-12-30 06:24:35 +01:00
|
|
|
intptr_t BasePointer;
|
2015-12-30 04:12:21 +01:00
|
|
|
|
|
|
|
|
__asm { //ASM. Do touch if suicidal.
|
2015-12-30 06:24:35 +01:00
|
|
|
mov BasePointer, ebp; // Store current BasePointer
|
2015-12-30 04:12:21 +01:00
|
|
|
}
|
2015-12-30 04:14:53 +01:00
|
|
|
|
2016-02-06 18:32:16 +01:00
|
|
|
// The Variable pointer that is used is at -9 bytes offset to the return address of this function.
|
|
|
|
|
return *(intptr_t*)(*(intptr_t*)(BasePointer + 4) - 9);
|
2015-06-20 15:08:27 +02:00
|
|
|
}
|
2015-12-30 05:11:33 +01:00
|
|
|
|
2016-02-06 18:32:16 +01:00
|
|
|
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointerType(int32_t pVariable) {
|
|
|
|
|
#pragma comment(linker, "/EXPORT:BP_GetVariablePointerType=_BP_GetVariablePointerType@4")
|
2015-12-30 06:24:35 +01:00
|
|
|
intptr_t BasePointer;
|
2015-12-30 05:11:33 +01:00
|
|
|
|
|
|
|
|
__asm { //ASM. Do touch if suicidal.
|
2015-12-30 06:24:35 +01:00
|
|
|
mov BasePointer, ebp; // Store current BasePointer
|
2015-12-30 05:11:33 +01:00
|
|
|
}
|
|
|
|
|
|
2016-02-06 18:32:16 +01:00
|
|
|
// The Variable pointer that is used is at -11 bytes offset to the return address of this function.
|
|
|
|
|
return *(intptr_t*)(*(intptr_t*)(BasePointer + 4) - 11);
|
2015-12-30 05:11:33 +01:00
|
|
|
}
|
2015-06-20 15:08:27 +02:00
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction0(BP_BlitzFunction0_t lpFunctionPointer) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction0=_BP_CallFunction0@4")
|
2015-06-20 15:08:27 +02:00
|
|
|
return lpFunctionPointer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction1(BP_BlitzFunction1_t lpFunctionPointer, int32_t p1) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction1=_BP_CallFunction1@8")
|
2015-06-20 15:08:27 +02:00
|
|
|
return lpFunctionPointer(p1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction2(BP_BlitzFunction2_t lpFunctionPointer, int32_t p1, int32_t p2) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction2=_BP_CallFunction2@12")
|
2015-06-20 15:08:27 +02:00
|
|
|
return lpFunctionPointer(p1, p2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction3(BP_BlitzFunction3_t lpFunctionPointer, int32_t p1, int32_t p2, int32_t p3) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction3=_BP_CallFunction3@16")
|
2015-06-20 15:08:27 +02:00
|
|
|
return lpFunctionPointer(p1, p2, p3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction4(BP_BlitzFunction4_t lpFunctionPointer, int32_t p1, int32_t p2, int32_t p3, int32_t p4) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction4=_BP_CallFunction4@20")
|
2015-06-20 15:08:27 +02:00
|
|
|
return lpFunctionPointer(p1, p2, p3, p4);
|
|
|
|
|
}
|
2015-06-20 23:37:47 +02:00
|
|
|
|
|
|
|
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction5(BP_BlitzFunction5_t lpFunctionPointer, int32_t p1, int32_t p2, int32_t p3, int32_t p4, int32_t p5) {
|
2016-02-06 18:32:16 +01:00
|
|
|
#pragma comment(linker, "/EXPORT:BP_CallFunction5=_BP_CallFunction5@24")
|
2015-06-20 23:37:47 +02:00
|
|
|
return lpFunctionPointer(p1, p2, p3, p4, p5);
|
2016-02-06 18:32:16 +01:00
|
|
|
}
|