Mid-Hook Function Help [Solved]
Well, the other day i found a tutorial on mid function hooking on another forum i got from google and i said to myself, "you need to expand your methods of hooking so you need to learn this". So, i did, and i read the tutorial and i totally understand everything about it, it's just that my test program keeps crashing. Here is my code:
Code:
#include <Windows.h>
#include <iostream>
DWORD retaddie = 0x003814AC;
void MakeJump(BYTE* paddress, DWORD yourfunction, DWORD dwlen);
DWORD base = (DWORD) GetModuleHandleA("Test Programming Ideas.exe");
DWORD dwjmpback = base + 0x114B1;
void MakeJump(BYTE* paddress, DWORD yourfunction, DWORD dwlen)
{
DWORD dwOldProtect, dwBkup, dwRelAddr;
// give the paged memory read/write permissions
VirtualProtect(paddress, dwlen, PAGE_EXECUTE_READWRITE, &dwOldProtect);
// calculate the distance between our address and our target location
// and subtract the 5bytes, which is the size of the jmp
// (0xE9 0xAA 0xBB 0xCC 0xDD) = 5 bytes
dwRelAddr = (DWORD) (yourfunction - (DWORD) paddress) - 5;
// overwrite the byte at pAddress with the jmp opcode (0xE9)
*paddress = 0xE9;
// overwrite the next 4 bytes (which is the size of a DWORD)
// with the dwRelAddr
* ((DWORD*) (paddress + 0x1)) = dwRelAddr;
// overwrite the remaining bytes with the NOP opcode (0x90)
// NOP opcode = No OPeration
for(DWORD x = 0x5; x < dwlen; x++) *(paddress + x) = 0x90;
// restore the paged memory permissions saved in dwOldProtect
VirtualProtect(paddress, dwlen, dwOldProtect, &dwBkup);
return;
}
_declspec (naked) void jumpfunc()
{
_asm
{
push 0
push 0
push 0
push 0
call MessageBoxA
push 56
push 200
call Beep
push 3E8h
JMP [dwjmpback]
}
}
BOOL _stdcall DllMain(HINSTANCE hInst, DWORD msg, LPVOID reserved)
{
char buffer[10];
switch (msg)
{
case DLL_PROCESS_ATTACH:
sprintf(buffer, "%X", (base));
MessageBoxA(0, buffer, "POINT OF DATA OPERATION", MB_OK);
MakeJump((BYTE*)(base + 0x114AC), (DWORD)jumpfunc, 5);
break;
}
}
)