i injected a dll which i want to use for custom packet sending to my game client. the problem now is how to use it.
the code of the dll is the following:
Code:
#include <Winsock2.h>
#include <Windows.h>
#include <fstream>
#include <detours.h>
#pragma comment(lib, "detours.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;
ofstream out("C:\\logW32sock.txt", ios::out | ios::binary);
DETOUR_TRAMPOLINE(int WINAPI Real_send(SOCKET a0, char* a1, int a2, int a3), send);
DETOUR_TRAMPOLINE(int WINAPI Real_recv(SOCKET a0, char* a1, int a2, int a3), recv);
DETOUR_TRAMPOLINE(int WINAPI Real_connect(SOCKET s,const struct sockaddr *name, int namelen), connect);
void WriteLog(char FAR* buf, bool type);
int WINAPI custom_send(SOCKET sock, char* buf, int len, int flags);
int WINAPI custom_recv(SOCKET sock, char FAR* buf, int len, int flags);
int WINAPI custom_connect(SOCKET s,const struct sockaddr *name, int namelen);
char* TextToHex( char *text)
{
if (!text) return 0;
int len = strlen(text);
char *buffer = new char[2*len]+1;
if (!buffer) return 0;
for (int i=0; i<len; i++)
sprintf( buffer+2*i, "%x", (unsigned int) text[i]);
return buffer;
}
void InjNachricht()//der erstellte Thread
{
MessageBox(0, L"Siehe da! Es klappt :P", L" Whohoo", 0);//4. Eine Message Box
}
void InjNachricht2()//der erstellte Thread
{
MessageBox(0, L"Siehe da! Es klappt2 :P", L" Whohoo", 0);//4. Eine Message Box
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
{
if ( reason == DLL_PROCESS_ATTACH )
{
//3.erstelle einen SubProzess, der die übergebene Funktion ausführt
CreateThread(0, 0, (LPTHREAD_START_ROUTINE) InjNachricht, 0, 0, 0);
DetourFunctionWithTrampoline((PBYTE)Real_send,(PBYTE)custom_send);
DetourFunctionWithTrampoline((PBYTE)Real_recv,(PBYTE)custom_recv);
DetourFunctionWithTrampoline((PBYTE)Real_connect, (PBYTE)custom_connect);
}
else if ( reason == DLL_PROCESS_DETACH )
{
DetourRemove((PBYTE)Real_send,(PBYTE)custom_send);
DetourRemove((PBYTE)Real_recv,(PBYTE)custom_recv);
DetourRemove((PBYTE)Real_connect, (PBYTE)custom_connect);
out.close();
}
return true;
}
SOCKET mysock;
int WINAPI custom_send(SOCKET sock, char* buf, int len, int flags)
{
mysock = sock;
WriteLog (buf, true);
return Real_send(sock, buf, len, flags);
}
int WINAPI custom_recv(SOCKET sock, char FAR* buf, int len, int flags)
{
mysock = sock;
WriteLog (buf, false);
return Real_recv(sock, buf, len, flags);
}
int WINAPI custom_connect(SOCKET s, const struct sockaddr *name, int namelen)
{
return Real_connect(s, name, namelen);
}
void WriteLog(char FAR* buf, bool type)
{
if (type == true)
{
out << "SEND:" << TextToHex(buf) << "Socket" << mysock << "\n\n\n\n";
} else
{
out << "RECIEVED: " << TextToHex(buf) << "Socket" << mysock << "\n\n\n\n";
}
}
my problem now is hpw to call a function to inject packets? i just know how to inject the dll but not how to call funtions of the injected dll. Maybe you can help me.
The Language im trying to call the functions from is c#
thanks in advance
Pain







