diff --git a/BlitzPointer/BlitzPointer.cpp b/BlitzPointer/BlitzPointer.cpp index d136cf7..d7b0663 100644 --- a/BlitzPointer/BlitzPointer.cpp +++ b/BlitzPointer/BlitzPointer.cpp @@ -3,32 +3,31 @@ #include "BlitzPointer.h" -DLL_EXPORT uint32_t BlitzPointer_GetReturnAddress() { - unsigned int StackPointer, ReturnAddress; +DLL_EXPORT int32_t BlitzPointer_GetReturnAddress() { + int32_t StackPointer, ReturnAddress; __asm { //ASM. Do touch if suicidal. - mov StackPointer, esp // Store current Stack Pointer - 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. + mov StackPointer, esp; // Store current Stack Pointer + 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. } return ReturnAddress; } - -DLL_EXPORT uint32_t BlitzPointer_GetFunctionPointer() { - unsigned int StackPointer, ReturnAddress; +DLL_EXPORT int32_t BlitzPointer_GetFunctionPointer() { + int32_t StackPointer, ReturnAddress; __asm { //ASM. Do touch if suicidal. - mov StackPointer, esp // Store current Stack Pointer - 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. + mov StackPointer, esp; // Store current Stack Pointer + 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. } - // let's look backwards in memory for the function signature (0x53 0x56 0x57 0x55 0x89 0xE5) for at most one megabyte. + // Let's look backwards in memory for the function signature (0x53 0x56 0x57 0x55 0x89 0xE5) for at most one megabyte. uint8_t* startPtr = (uint8_t*)ReturnAddress; uint8_t* endPtr = (uint8_t*)(ReturnAddress - 1048576); for (uint8_t* curPtr = startPtr; curPtr != endPtr; curPtr--) { @@ -37,21 +36,45 @@ DLL_EXPORT uint32_t BlitzPointer_GetFunctionPointer() { if (*(curPtr + 2) == 0x57) // push edi if (*(curPtr + 3) == 0x55) // push ebp if (*(curPtr + 4) == 0x89 && *(curPtr + 5) == 0xE5) // mov ebp,esp - return (uint32_t)curPtr; + return (int32_t)curPtr; } return 0; } -__declspec(naked) uint32_t __BlitzPointer_CallFunction() { - __asm { - jmp eax - } -} +// Defines for easier function generation. +#define CALLFUNCTION_DECL_BEGIN(NAME) DLL_EXPORT int32_t BlitzPointer_CallFunction##NAME(intptr_t ipFunctionPointer +#define CALLFUNCTION_DECL_PARAMETER(TYPE, NAME) , TYPE NAME +#define CALLFUNCTION_DECL_END() ) +#define CALLFUNCTION_DECL_IMPLEMENT() ) { int32_t result; +#define CALLFUNCTION_IMPL_SAFEGUARD() if (!ipFunctionPointer) return NULL; +#define CALLFUNCTION_IMPL_PREPARE(COUNT) __asm { sub esp, COUNT * 4; } +#define CALLFUNCTION_IMPL_PARAMETER(INDEX, NAME) __asm { mov eax, [ NAME ]; mov [esp - INDEX * 4], eax; } +#define CALLFUNCTION_IMPL_CALL() __asm { call dword ptr[ipFunctionPointer]; } +#define CALLFUNCTION_IMPL_RETURN() __asm { mov [result], eax }; return result; } -DLL_EXPORT uint32_t BlitzPointer_CallFunction0(uint32_t fpFunctionPointer) { +// Call Function with 0 parameter. +CALLFUNCTION_DECL_BEGIN(I0) +CALLFUNCTION_DECL_IMPLEMENT() +CALLFUNCTION_IMPL_SAFEGUARD() +CALLFUNCTION_IMPL_CALL() +CALLFUNCTION_IMPL_RETURN() + +// Call Function with 1 parameter. +/*CALLFUNCTION_DECL_BEGIN(I1) +CALLFUNCTION_DECL_PARAMETER(int32_t, p1) +CALLFUNCTION_DECL_IMPLEMENT() +CALLFUNCTION_IMPL_SAFEGUARD() +//CALLFUNCTION_IMPL_PREPARE(1) +//CALLFUNCTION_IMPL_PARAMETER(0, p1) +CALLFUNCTION_IMPL_CALL() +CALLFUNCTION_IMPL_RETURN()*/ + + +/* +DLL_EXPORT uint32_t BlitzPointer_CallFunction0(intptr_t fpFunctionPointer) { if (!fpFunctionPointer) - return 0; + return NULL; __asm { call dword ptr[fpFunctionPointer]; @@ -62,10 +85,9 @@ DLL_EXPORT uint32_t BlitzPointer_CallFunction0(uint32_t fpFunctionPointer) { } return rv; } - DLL_EXPORT uint32_t BlitzPointer_CallFunction1(uint32_t fpFunctionPointer, uint32_t p1) { if (!fpFunctionPointer) - return 0; + return NULL; __asm { sub esp, 0x4; @@ -79,7 +101,6 @@ DLL_EXPORT uint32_t BlitzPointer_CallFunction1(uint32_t fpFunctionPointer, uint3 } return rv; } - DLL_EXPORT uint32_t BlitzPointer_CallFunction2(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2) { if (!fpFunctionPointer) return 0; @@ -98,7 +119,6 @@ DLL_EXPORT uint32_t BlitzPointer_CallFunction2(uint32_t fpFunctionPointer, uint3 } return rv; } - DLL_EXPORT uint32_t BlitzPointer_CallFunction3(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3) { if (!fpFunctionPointer) return 0; @@ -119,7 +139,6 @@ DLL_EXPORT uint32_t BlitzPointer_CallFunction3(uint32_t fpFunctionPointer, uint3 } return rv; } - DLL_EXPORT uint32_t BlitzPointer_CallFunction4(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4) { if (!fpFunctionPointer) return 0; @@ -207,3 +226,4 @@ DLL_EXPORT uint32_t BlitzPointer_CallFunctionS4(uint32_t fpFunctionPointer, uint } return *((uint32_t*)(returnvalue + 4)); } +*/ \ No newline at end of file diff --git a/BlitzPointer/BlitzPointer.h b/BlitzPointer/BlitzPointer.h index a4e1b32..0db1956 100644 --- a/BlitzPointer/BlitzPointer.h +++ b/BlitzPointer/BlitzPointer.h @@ -1,15 +1,4 @@ #include "dllmain.h" -DLL_EXPORT uint32_t BlitzPointer_GetReturnAddress(); -DLL_EXPORT uint32_t BlitzPointer_GetFunctionPointer(); - -DLL_EXPORT uint32_t BlitzPointer_CallFunction0(uint32_t fpFunctionPointer); -DLL_EXPORT uint32_t BlitzPointer_CallFunction1(uint32_t fpFunctionPointer, uint32_t p1); -DLL_EXPORT uint32_t BlitzPointer_CallFunction2(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2); -DLL_EXPORT uint32_t BlitzPointer_CallFunction3(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3); -DLL_EXPORT uint32_t BlitzPointer_CallFunction4(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4); -DLL_EXPORT uint32_t BlitzPointer_CallFunctionS0(uint32_t fpFunctionPointer); -DLL_EXPORT uint32_t BlitzPointer_CallFunctionS1(uint32_t fpFunctionPointer, uint32_t p1); -DLL_EXPORT uint32_t BlitzPointer_CallFunctionS2(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2); -DLL_EXPORT uint32_t BlitzPointer_CallFunctionS3(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3); -DLL_EXPORT uint32_t BlitzPointer_CallFunctionS4(uint32_t fpFunctionPointer, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4); \ No newline at end of file +DLL_EXPORT int32_t BlitzPointer_GetReturnAddress(); +DLL_EXPORT int32_t BlitzPointer_GetFunctionPointer(); \ No newline at end of file diff --git a/BlitzPointer/BlitzPointer.vcxproj b/BlitzPointer/BlitzPointer.vcxproj index 928cdb5..fc4b64a 100644 --- a/BlitzPointer/BlitzPointer.vcxproj +++ b/BlitzPointer/BlitzPointer.vcxproj @@ -5,6 +5,14 @@ Debug Win32 + + Preprocess-Preview + Win32 + + + Preprocess + Win32 + Release Win32 @@ -21,6 +29,12 @@ v120 Unicode + + DynamicLibrary + true + v120 + Unicode + DynamicLibrary false @@ -28,12 +42,18 @@ false Unicode + + v120 + + + + @@ -44,12 +64,21 @@ .dll true + + $(SolutionDir)\Build\$(ProjectName)\$(Configuration)\ + $(SolutionDir)\Intermediate\$(ProjectName)\$(Configuration)\ + .dll + true + $(SolutionDir)\Build\$(ProjectName)\$(Configuration)\ $(SolutionDir)\Intermediate\$(ProjectName)\$(Configuration)\ .dll true + + .dll + Level3 @@ -73,6 +102,40 @@ false + true + true + + + true + 1.0 + + + + + + + Level3 + Disabled + + + $(SolutionDir);$(ProjectDir) + false + Default + MultiThreaded + false + true + false + false + 4Bytes + true + true + + + false + + + false + false true @@ -106,6 +169,7 @@ Default false + false false @@ -118,6 +182,17 @@ + + + true + + + + + true + _WINDLL;%(PreprocessorDefinitions) + +