Code:
//==========================================================================
// by The1domo swtor winsock2 hooking :)
//==========================================================================
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <io.h>
#include <fcntl.h>
#include <fcntl.h>
#include "detours.h"
//==========================================================================
// to create a Console for write to
//==========================================================================
void createConsole( )
{
AllocConsole();
int hConHandle;
long lStdHandle;
FILE *fp;
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
}
//==========================================================================
// the original connect Function call
//==========================================================================
int (WINAPI* connect_t)(SOCKET,const struct sockaddr*,int,int);
//==========================================================================
// the original WSARecv Function call
//==========================================================================
DWORD (WINAPI* WSARecv_t)(SOCKET,LPWSABUF,DWORD,DWORD,int);
//==========================================================================
// write to the Console windows
//==========================================================================
void msg2(char* str)
{
std::cout << " " << std::endl;
std::cout << "msg: " << str << std::endl;
std::cout << " " << std::endl;
}
//==========================================================================
// the hooked Function to Detour
//==========================================================================
// a hook_connect Function call
//==========================================================================
int WINAPI hook_connect(SOCKET s, const struct sockaddr *name, int namelen, int a4)
{
_asm pushad;
msg2("ATTEMPTED CONNECT !!!!!!!!!!!!!!!!");
_asm popad;
return connect_t(s, name, namelen, a4);
}
//==========================================================================
// a hook_WSARecv Function call
//==========================================================================
DWORD WINAPI hook_WSARecv(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, DWORD a4, int a5)
{
_asm pushad;
if( lpBuffers && lpBuffers->buf && lpBuffers->len > 0 )
{
char szShit[24] = { 0 };
sprintf( szShit, "0x%X", (DWORD)lpBuffers->buf );
msg2(szShit);
}
_asm popad;
return WSARecv_t(s, lpBuffers, dwBufferCount, a4, a5);
}
//==========================================================================
// Hooking Thread
//==========================================================================
DWORD WINAPI Thread(LPVOID)
{
// exe base address
DWORD swtor = (DWORD)GetModuleHandle("swtor.exe");
// Detour for a hooked Function call
connect_t = (int(WINAPI*)(SOCKET,const struct sockaddr*,int,int))DetourFunction((PBYTE)swtor+0x603590, (PBYTE)hook_connect);
WSARecv_t = (DWORD(WINAPI*)(SOCKET,LPWSABUF,DWORD,DWORD,int))DetourFunction((PBYTE)swtor+0x62C7C0, (PBYTE)hook_WSARecv);
// create a Console for write to
createConsole( );
// test write to Console
std::cout << "Attached to Process" << std::endl;
return 0;
}
//==========================================================================
// DllMain
//==========================================================================
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpvReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
// Create a Thread to use by the hook
CreateThread(NULL,NULL,Thread,NULL,NULL,NULL);
}
return TRUE;
}
//==========================================================================
now if anyone sees anything wrong with this or would like to help on my project to parse the packets and give them decrypted I be much appreciated if you can post in this thread all criticism is accepted thank you