Hey leute war ja paar mal wegen injectet dll hier in C++, sofern ich die DLL so injecte wie in der funktion hier ist der prozess freezed. Vermute mal das NUR die schleife läuft sonst gar nichts, krieg das aber nicht hin, habt ihr einen Vorschlag?
C
- // dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
- #include "stdafx.h"
- //#include <iostream>
- //#include <fstream>
- //#include <string>
- //#include <windows.h>
- //#include <winsock2.h>
- //#pragma comment(lib,"ws2_32.lib")
- using namespace std;
- typedef int (WINAPI* realConnect )(SOCKET s, const struct sockaddr* name, int namelen );
- typedef int (WINAPI* realRecv)(SOCKET socket, const char* buffer, int length, int flags);
- typedef int (WINAPI* realSend)(SOCKET socket, const char* buffer, int length, int flags);
- realSend o_send;
- realRecv o_recv;
- realConnect o_connect;
- SOCKET Bot;
- SOCKET Server;
- SOCKET Client;
- WORD port;
- //int WINAPI my_connect( SOCKET s, const struct sockaddr* name, int namelen)
- //{
- // WORD port = ntohs((*(WORD*)name->sa_data));
- // sockaddr_in *sockaddr = (sockaddr_in*)name;
- // sockaddr->sin_port = htons(16000);
- // if ( port != 80 )
- // {
- // sockaddr->sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
- // }
- // return o_connect(s,name,namelen);
- //}
- int WINAPI my_connect( SOCKET s, const struct sockaddr* name, int namelen)
- {
- port = ntohs((*(WORD*)name->sa_data));
- /*sockaddr_in *sockaddr = (sockaddr_in*)name;*/
- //sockaddr->sin_port = htons(16000);
- //if ( port != 80 )
- //{
- //sockaddr->sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
- //}
- return o_connect(s,name,namelen);
- }
- int WINAPI my_send(SOCKET socket, char* buffer, int length, int flags)
- {
- if ( port != 80 )
- {
- int PacketLenght = *(WORD*)buffer;
- buffer[-1] = 2;
- o_send(Bot, buffer-1, PacketLenght+1, 0);
- }
- Server = socket;
- return o_send(Server, buffer, length, flags);
- }
- int WINAPI my_recv(SOCKET socket, char* buffer, int length, int flags)
- {
- if ( port != 80 )
- {
- int PacketLenght = *(WORD*)buffer;
- buffer[-1] = 1;
- o_send(Bot, buffer-1, PacketLenght+1, 0);
- }
- Client = socket;
- return o_recv(Client, buffer, length, flags);
- }
- void Receiving()
- {
- //Socketpart
- WSADATA wsa;
- WSAStartup(MAKEWORD(2,2), &wsa);
- Bot=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- SOCKADDR_IN addr;
- memset(&addr,0,sizeof(SOCKADDR_IN));
- addr.sin_family=AF_INET;
- addr.sin_port=htons(16000);
- addr.sin_addr.s_addr=inet_addr("127.0.0.1");
- long status;
- status=connect(Bot,(SOCKADDR*)(&addr),sizeof(addr));
- if (status==SOCKET_ERROR)
- {
- MessageBox(NULL, TEXT("Bot dont exists"), TEXT("Error"), MB_OK);
- exit(0);
- }
- char* buffer = 0;
- int lenght = 9999;
- int bytes = -1;
- while (bytes = -1)
- {
- bytes = recv (Bot, buffer, lenght, 0);
- }
- }
- BOOL APIENTRY DllMain( HMODULE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved )
- {
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- /////////////////////////////////////////////////////
- HMODULE hWS32 = LoadLibraryA( "ws2_32.dll" );
- FARPROC pConnect = GetProcAddress(hWS32,"connect");
- FARPROC pSend = GetProcAddress(hWS32,"send");
- FARPROC pRecv = GetProcAddress(hWS32,"recv");
- DetourCreate((LPVOID)pConnect,my_connect,5);
- __asm mov [ o_connect ], eax;
- DetourCreate((LPVOID)pSend,my_send,5);
- __asm mov [ o_send ], eax;
- DetourCreate((LPVOID)pRecv,my_recv,5);
- __asm mov [ o_recv ], eax;
- Receiving();
- break;
- }
- return true;
- }