Well you don't call MyConnect what you do is hook the function so when conquer calls connect, it calls MyConnect instead so what you need to do is that once the dll is injected you used the APIHook function to hook the connect function like this
Code:
APIHook((DWORD)GetProcAddress(GetModuleHandle("Ws2_32.dll"), "connect"), (DWORD)MyConnect, (DWORD)OrigConnect);
or here's the whole bunch of code even though I attached the files.
Code:
//Needs -lws2_32 linker argument
#pragma comment(lib, "libws2_32.a")
#define HAWK_WIN32
#define LOGFILE "hook.log"
#include <stdio.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <process.h>
typedef SOCKET (WINAPI *PSOCKET)(int af, int type, int protocol);
typedef int (WINAPI *PCONNECT)(SOCKET s, const struct sockaddr_in *address, int namelen);
PSOCKET OrigSocket;
PCONNECT OrigConnect;
SYSTEMTIME st;
int conch; //0 = free, 1 = connect has it, 2 = send has it, 3 = recv has it
//4 = WSASend has it, 5 = WSARecv has it
void MessageFunc(void *msgbuf)
{
#if defined(HAWK_WIN32)
MessageBox(NULL, msgbuf, "Message", 0);
#elif defined(HAWK_CONSOLE)
printf("%s\n", msgbuf);
#endif
}
//===========================CONNECT===========================
int WINAPI __stdcall MyConnect(SOCKET s, const struct sockaddr_in *address, int namelen)
{
if(address->sin_port == htons(9959))
{
struct sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 9958 );
return OrigConnect(s, &clientService, sizeof(clientService));
} else if(address->sin_port == htons(5816))
{
struct sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 5816 );
return OrigConnect(s, &clientService, sizeof(clientService));
}
else
{
return OrigConnect(s, address, namelen);
}
}
DWORD APIHook(DWORD HookFunc, DWORD MyFunc, DWORD OrigFunc)
{
unsigned char NewData[5], DetourJump[5], OldData[5];
DWORD OldProtect;
int i;
unsigned char* HookFuncPtr = (unsigned char*) HookFunc;
unsigned char* HookDetour = (unsigned char*) malloc(25);
for(i = 0; i < 25; i++)
HookDetour[i] = 0x90; //NOP
NewData[0] = 0xE9; //JMP (near)
*(PDWORD)&NewData[1] = (DWORD)((DWORD)MyFunc - ((DWORD)HookFunc + 5));
DetourJump[0] = 0xE9;
*(PDWORD)&DetourJump[1] = (DWORD)((DWORD)HookFunc - ((DWORD)HookDetour + 14 + 5));
VirtualProtectEx(GetCurrentProcess(), (void*)HookFunc, 10, PAGE_EXECUTE_WRITECOPY, &OldProtect);
for(i = 0; i < 5; i++)
{
OldData[i] = HookFuncPtr[i];
HookFuncPtr[i] = NewData[i];
}
VirtualProtectEx(GetCurrentProcess(), (void*)HookFunc, 10, OldProtect, NULL);
VirtualProtectEx(GetCurrentProcess(), (void*)HookDetour, 25, PAGE_EXECUTE_WRITECOPY, &OldProtect);
for(i = 0; i < 5; i++)
HookDetour[i] = OldData[i];
HookDetour[24-5] = DetourJump[0];
HookDetour[24-4] = DetourJump[1];
HookDetour[24-3] = DetourJump[2];
HookDetour[24-2] = DetourJump[3];
HookDetour[24-1] = DetourJump[4];
HookDetour[24] = 0xC3; //RET
VirtualProtectEx(GetCurrentProcess(), (void*)HookDetour, 25, OldProtect, NULL);
OrigFunc = (DWORD)HookDetour;
return OrigFunc;
}
DWORD WINAPI Inject(HINSTANCE hInst /*LPVOID lparam*/)
{
WSADATA wsaData;
WSAStartup(MAKEWORD(1,1), &wsaData);
//Create log file, existing log files will be deleted automatically with CREATE_ALWAYS
HANDLE hdn = CreateFile(LOGFILE, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hdn);
*(PDWORD)&OrigConnect = APIHook((DWORD)GetProcAddress(GetModuleHandle("Ws2_32.dll"), "connect"), (DWORD)MyConnect, (DWORD)OrigConnect);
//FreeLibraryAndExitThread(hInst, 0);
}
BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
Inject(hInst);
break;
default:
break;
}
return TRUE;
}