Results 1 to 7 of 7
  1. #1
    Vitalka
    Vitalka is offline
    New member
    Join Date
    2011 Dec
    Posts
    5
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0

    Problem with Send packet at hooked recv/send

    Hey guys why this source doesnt work for me? Please help me whats the mistake?

    If the programm start with the injected dll, it crash and i get a windows error. More i dont know.
    Code:
    // 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;
    
    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_send(SOCKET socket, const char* buffer, int length, int flags) 
    {
    	send(Bot, buffer, length, flags);
    	return o_send(socket, buffer, length, flags);
    }
    
    int WINAPI my_recv(SOCKET socket, const char* buffer, int length, int flags) 
    {
    	send(Bot, buffer, length, flags);
    	return o_recv(socket, buffer, length, flags);
    }
    
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved )
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    		//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");
    
    		short status;
    		status=connect(Bot,(SOCKADDR*)(&addr),sizeof(addr));
    		if (status==SOCKET_ERROR)
    		{
    			MessageBox(NULL, TEXT("Bot dont exists"), TEXT("Error"), MB_OK);
    			exit(0);
    		}
    		/////////////////////////////////////////////////////
    		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;
    		break;
    	}
    	return true;
    }
    Last edited by Vitalka; 2012-01-22 at 02:45 PM.

  2. #2
    Awal
    Awal is offline
    Member-in-training Awal's Avatar
    Join Date
    2011 Dec
    Location
    KOREA
    Posts
    124
    Thanks Thanks Given 
    17
    Thanks Thanks Received 
    56
    Thanked in
    11 Posts
    Rep Power
    0
    this is source code packet editor right?
    Sorry for my bad English

  3. #3
    emoisback
    emoisback is offline
    Full member
    Join Date
    2011 Dec
    Location
    Indonesia there i'm
    Posts
    508
    Thanks Thanks Given 
    83
    Thanks Thanks Received 
    244
    Thanked in
    68 Posts
    Rep Power
    13
    may u put your promblem?..
    what's going on with you code?..
    maybe its help someone who want helping you..
    Learn from PGC for Share on PGC..


    For another Stuff i have make try to find it [Please, register to view links]
    If i have help you, please thanks and respect ..

  4. #4
    Vitalka
    Vitalka is offline
    New member
    Join Date
    2011 Dec
    Posts
    5
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0
    It hooks the buffer from recv and send of the ingame function. I need to send the buffer to my application, but the send doesnt work

  5. #5
    Awal
    Awal is offline
    Member-in-training Awal's Avatar
    Join Date
    2011 Dec
    Location
    KOREA
    Posts
    124
    Thanks Thanks Given 
    17
    Thanks Thanks Received 
    56
    Thanked in
    11 Posts
    Rep Power
    0
    the application not work or crashed,may you false/wrong editing try to correct them
    Sorry for my bad English

  6. #6
    Vitalka
    Vitalka is offline
    New member
    Join Date
    2011 Dec
    Posts
    5
    Thanks Thanks Given 
    0
    Thanks Thanks Received 
    0
    Thanked in
    0 Posts
    Rep Power
    0
    its right. its crashing yes

  7. #7
    Sirmabus
    Sirmabus is offline
    New member
    Join Date
    2010 Jul
    Posts
    20
    Thanks Thanks Given 
    2
    Thanks Thanks Received 
    10
    Thanked in
    4 Posts
    Rep Power
    0
    As soon as you start the application you should have a window of time where you can connect a debugger to your application.
    Just put a hardware break point on "send" and trace the code.

    Also if there is some problem attaching a debugger before your target makes it's first send(), you can try just putting a "int3" break in your hook which might allow you to attach JIT (just in time) debugger.

    The easiest way to solve such problems is just look at it in a debugger.

Similar Threads

  1. Problem using Ollydbg
    By smbogdan in forum General Programming
    Replies: 4
    Last Post: 2012-01-29, 02:45 AM
  2. [Help] Can't send keys to game via extern program
    By d4rk_sasuke in forum Martial Empires
    Replies: 2
    Last Post: 2012-01-11, 04:17 PM
  3. The problem with
    By carlos147 in forum Trash Bin
    Replies: 0
    Last Post: 2011-06-07, 02:04 PM
  4. Problem with connection to global
    By ruchenkov in forum Aika Online
    Replies: 2
    Last Post: 2010-11-30, 05:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •