A simple Hooking class
So lately many people have been asking how to hook and Fallen is going to write a tutorial soon, but i just wanted to release a part of my hooking class. It's very simple and contains only the most basic type of hook which is the jmp hook and i threw in a function to NOP addies as well. Again it's very simple, but i made it to give you guys that want to learn how to hook a simple idea of how the idea works.
Here is the class:
To implement it you simply declare a variable of type Hook and then use the functions like so:
Note that in order to use the JMP method you need to do it in a spot with atleast 5 bytes because the JMP is 0xE9 (1-byte) then the address of your function which is 4 bytes.
This isn't really a tutorial it's just some source code for you guys to study and learn from. Again it's very simple but you can combine it with other methods and it's very useful. Hope you learned something.
Here is the class:
Code:
class Hook
{
public:
void NOP(DWORD* dwaddress, DWORD dwlen);
void JMP(DWORD* dwaddress, DWORD* dwyouraddress, DWORD dwlen);
};
void Hook::NOP(DWORD* dwaddress, DWORD dwlen)
{
DWORD dwOldProtect;
VirtualProtect((void*)dwaddress, dwlen, PAGE_EXECUTE_READWRITE, &dwOldProtect);
BYTE *pAddie = (BYTE*)dwaddress;
*pAddie = 0x90;
for(DWORD i = 0x1; i < dwlen; i++)
*(pAddie + i) = 0x90;
VirtualProtect((void*)dwaddress, dwlen, dwOldProtect, NULL);
}
void Hook::JMP(DWORD* dwaddress, DWORD* dwyouraddress, DWORD dwlen)
{
DWORD dwOldProtect;
DWORD dwRealAddie = (DWORD)dwyouraddress - (DWORD)dwaddress - 5;
VirtualProtect((void*)dwaddress, dwlen, PAGE_EXECUTE_READWRITE, &dwOldProtect);
BYTE* pAddie = (BYTE*)dwaddress;
*pAddie = 0xE9;
pAddie++;
dwaddress = (DWORD*)pAddie;
*dwaddress = dwRealAddie;
for(DWORD i = 0x4; i < dwlen; i++)
*(pAddie + i) = 0x90;
VirtualProtect((void*)dwaddress, dwlen, dwOldProtect, NULL);
}
Code:
Hook hook; hook.NOP((DWORD*)(address), (how_many_bytes_to_nop)); hook.JMP((DWORD*)(address), (DWORD*)(your function), (how many bytes));
This isn't really a tutorial it's just some source code for you guys to study and learn from. Again it's very simple but you can combine it with other methods and it's very useful. Hope you learned something.





![=]](/forum/images/emotions/=].gif)