Hey ppl so i decided to make this tutorial for all of u that want to start hooking functions using detours..
So first thing ull need is microsoft detours which u can easily find by searching on Google.
The second thing ull need is microsoft visual studio or an equivalent.
And last but definitely not least u will need ur brain
Lets start:
So lets say u are playing a mmorpg and suddenly u wanna hack that game and lets say make ur own bot for packet editing(this is not a full bot tutorial this is only a small part of it), the first thing u wanna do at that point is find out which function u wanna hook(hint use a debugger and find out if it uses ws2_32.dll) if so then the game probably uses the connect function but u shud still check if it does. If thats the case then get ready to hook that function, here we go..
note: the o stands for original, as this is the original function.
Now u can build this dll and inject it in ur game and u shud get a message box every time the connect function is called, u can hook the send/recv functions using the same technique.
Note: Who ever hooks the send/recv functions first gets a cookie
And here we are at the end of the tutorial, i hope it helped you in some way if u have any problems please dont hesitate to pm me or leave a comment below ill be very happy to help u with ur problems, if u encounter any and dont forget to give me sum kudos
Edit: I added the detours lib and includes in the attachments
So first thing ull need is microsoft detours which u can easily find by searching on Google.
The second thing ull need is microsoft visual studio or an equivalent.
And last but definitely not least u will need ur brain
Lets start:
So lets say u are playing a mmorpg and suddenly u wanna hack that game and lets say make ur own bot for packet editing(this is not a full bot tutorial this is only a small part of it), the first thing u wanna do at that point is find out which function u wanna hook(hint use a debugger and find out if it uses ws2_32.dll) if so then the game probably uses the connect function but u shud still check if it does. If thats the case then get ready to hook that function, here we go..
[li]create an empty dll[/li]
[li]include winsock2.h, detours.h and iostream(u never know when ull need it) as well as windows.h like so:[/li]
C++:
#include <WinSock2.h>
#include <Windows.h>
#include <detours.h>
#include <iostream>
- [li] Now what u want to do is get the declaration of the function u want to hook, in this case the connect function, u can find the declaration at msdn
and u declare it as so:[/li]
C++:
int (__stdcall *connect_o)( __in SOCKET s, __in const struct sockaddr_in *name, __in int namelen );
- [li] Now that its declared u want to define it which is really simple..[/li]
C++:
int __stdcall connect_h(__in SOCKET s, __in struct sockaddr_in *name, __in int namelen )
{
MessageBoxA(NULL,"I just made my first hook!!","Hook Tutorial", MB_OK);
return connect_o(s, name, namelen);
}
- [li] Now u want to make A function that represents ur thread..[/li]
C++:
void WINAPI HookApi(LPVOID param)
{
}
- [li]Next u want to get the address of the connect function inside that function that u just created, here is how[/li]
C++:
HANDLE ConnectAddress = GetProcAddress(GetModuleHandleA("ws2_32"), "connect");
- [li]Your next step is making the actual detour which will allow ur function to be called when ever the original is called if that makes sense..[/li]
C++:
if(ConnectAddress)
connect_o = (int (__stdcall *)( __in SOCKET s, __in const struct sockaddr_in *name, __in int namelen ))DetourFunction((PBYTE)ConnectAddress,(PBYTE)connect_h);
- [li]Now for the final step creating the thread and disabling thread library calls, so ur dll main shud like like this[/li]
C++:
bool __stdcall DllMain(HINSTANCE hinst, DWORD _Reason, _In_opt_ LPVOID _Reserved)
{
DisableThreadLibraryCalls(hinst);
CreateThread(0,0,(LPTHREAD_START_ROUTINE)HookApi,0,0,&ThreadID);
return true;
}
Now u can build this dll and inject it in ur game and u shud get a message box every time the connect function is called, u can hook the send/recv functions using the same technique.
Note: Who ever hooks the send/recv functions first gets a cookie
And here we are at the end of the tutorial, i hope it helped you in some way if u have any problems please dont hesitate to pm me or leave a comment below ill be very happy to help u with ur problems, if u encounter any and dont forget to give me sum kudos
Edit: I added the detours lib and includes in the attachments
Attachments
You can download 0 Attachments
-
46.3 KB Views: 145