Thread: Logging Packets

Results 1 to 4 of 4
  1. #1
    Jabberwock's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    1,735
    Reputation
    191
    Thanks
    15,692
    My Mood
    Relaxed

    Logging Packets

    Hi I need help with something, I want to log the packets that are sent from the game.

    I have done a hook, and it seems to be working well.
    The thing is, when I try to read it from a txt file, I see some unique letters and such.
    So I figured I have to convert the second perameter of the send function from Winsock.dll to hex.

    How can I achive this?

    This is my fake function:

    Code:
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s - %d\n", buf, len);
        fclose(pSendLogFile);
    
        return pSend(s, buf, len, flags);
    }
    I think I succeeded.

    Code:
    std::string displayText;
    char buffer[32];
    unsigned short nStrLength;
    short j;
    
    //-----------------------
    
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
    	displayText = "";
    
    	for (j = 0; j < len; j++)
    	{
    		
    		sprintf_s(buffer, "%0.2X", buf[j]);
    
    		nStrLength = strlen(buffer);
    		displayText.push_back(buffer[nStrLength-2]);
    		displayText.push_back(buffer[nStrLength-1]);
    		displayText.push_back(' ');
    	}
    
    	displayText.pop_back();
    
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s", displayText);
    	fprintf(pSendLogFile, " - %d\n", len);
        fclose(pSendLogFile);
    
    	return pSend(s, buf, len, flags);
    }
    Found it on the web.
    Last edited by Jabberwock; 09-03-2012 at 12:25 PM.
    Even familiar landscapes will
    reveal a different kind of beauty
    if you change your viewpoint.
    Where these new encounters
    and new bonds will lead you...
    Such dazzling golden days.
    I, too, look forward to
    what I might behold.

  2. #2
    giniyat101's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Location
    Not telling.
    Posts
    1,935
    Reputation
    130
    Thanks
    1,380
    My Mood
    Dead
    do something like that:
    Code:
    int buf_len = len*4; //should be enough i guess
    char * buffer = new char char[buf_len]; 
    ZeroMemory(buffer, buf_len); //just incase
    for (int i=0; i<len; i+= 8)
    {
        for (int j=0; j<8; j++)
        {
            if ((i+j) > len) break;
            if (j != 0) sprintf_s(buffer, buf_len", "%s ", buffer);
            sprintf_s(buffer, buf_len, "%s%02X", buffer, (BYTE)buf[i+j]);
        }
        sprintf_s(buffer, buf_len, "%s\n", buffer);
    }
    delete [] buffer;
    Last edited by giniyat101; 09-03-2012 at 06:42 PM.


     



    [img]https://i43.photobucke*****m/albums/e367/DeteSting/Steam-update.gif[/img]

  3. The Following User Says Thank You to giniyat101 For This Useful Post:

    Jabberwock (09-04-2012)

  4. #3
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    Quote Originally Posted by Jabberwo0ck View Post
    Hi I need help with something, I want to log the packets that are sent from the game.

    I have done a hook, and it seems to be working well.
    The thing is, when I try to read it from a txt file, I see some unique letters and such.
    So I figured I have to convert the second perameter of the send function from Winsock.dll to hex.

    How can I achive this?

    This is my fake function:

    Code:
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s - %d\n", buf, len);
        fclose(pSendLogFile);
    
        return pSend(s, buf, len, flags);
    }
    I think I succeeded.

    Code:
    std::string displayText;
    char buffer[32];
    unsigned short nStrLength;
    short j;
    
    //-----------------------
    
    int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
    {
    	displayText = "";
    
    	for (j = 0; j < len; j++)
    	{
    		
    		sprintf_s(buffer, "%0.2X", buf[j]);
    
    		nStrLength = strlen(buffer);
    		displayText.push_back(buffer[nStrLength-2]);
    		displayText.push_back(buffer[nStrLength-1]);
    		displayText.push_back(' ');
    	}
    
    	displayText.pop_back();
    
        fopen_s(&pSendLogFile, "C:\\SendLog.txt", "a+");
        fprintf(pSendLogFile, "%s", displayText);
    	fprintf(pSendLogFile, " - %d\n", len);
        fclose(pSendLogFile);
    
    	return pSend(s, buf, len, flags);
    }
    Found it on the web.
    You shouldn't convert anything. Write in the data raw, then open it with a a hex-editor; the data could be anything. You need to open the file with the 'b' flag, as it is a raw binary file.

    Also, use fstream. It's a lot less of a pain in the ass.

    Code:
    std::fsteam fLog("test.txt", fstream::out | fstream::binary);
    fLog.write(pData, ulDataLen);
    Since you have no means of seperating the messages reasonably, you're better off just leaving it in a stream(write all calls in the same file) unless you know how to figure out the length of each message programatically. Sometimes, the length parameter is the length of the entire message, but a lot of the time the messages are composed of several calls to this function and the app has its internal method of determining the length of the messages.
    Last edited by radnomguywfq3; 09-04-2012 at 02:41 AM.



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  5. The Following User Says Thank You to radnomguywfq3 For This Useful Post:

    Jabberwock (09-04-2012)

  6. #4
    Jabberwock's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    1,735
    Reputation
    191
    Thanks
    15,692
    My Mood
    Relaxed
    I realized the game uses the UDP connection. The TCP is only for buying items or the chat.

    Anyway, what I want to do is get a specific packet that does something unique. Like jumping and other stuff, so I can use it and change the length of the jump by editing that packet.
    When simply logging the packets I can't distinguish between them and there are a lot of packets in a second. I think 400 per second.

    Thanks about the tips.

    I tried with a hex editor, it's not an option for me. As I need to make chamges in real time to the packets.

    Now the code is this:

    Code:
    int WINAPI MySendTo(SOCKET s, const char* buf, int len, int flags, const struct sockaddr *to, int tolen)
    {
    	int buf_len = len * 8; //should be enough i guess
    	char *buffer = new char[buf_len];
    	ZeroMemory(buffer, buf_len); //just incase
    
    	for (int i = 0; i < len; i += 8)
    	{
    		for (int j = 0; j < 8; j++)
    		{
    			if ((i + j) > len) break;
    
    			if (j != 0) sprintf_s(buffer, buf_len, "%s ", buffer);
    
    			sprintf_s(buffer, buf_len, "%s%02X", buffer, (BYTE)buf[i + j]);
    		}
    
    		sprintf_s(buffer, buf_len, "%s ", buffer);
    	}
    
    	sprintf_s(buffer, buf_len, "%s\n", buffer);
    
    	fLog.write(buffer, strlen(buffer));
    
    	delete [] buffer;
    
    	return pSendTo(s, buf, len, flags, to, tolen);
    }
    Last edited by Jabberwock; 09-04-2012 at 06:16 AM.
    Even familiar landscapes will
    reveal a different kind of beauty
    if you change your viewpoint.
    Where these new encounters
    and new bonds will lead you...
    Such dazzling golden days.
    I, too, look forward to
    what I might behold.

  7. The Following User Says Thank You to Jabberwock For This Useful Post:

    giniyat101 (09-04-2012)

Similar Threads

  1. packet editing
    By terence in forum Hack Requests
    Replies: 1
    Last Post: 09-23-2007, 07:51 AM
  2. Packets & Visual Basic
    By BadBob in forum Hack Requests
    Replies: 5
    Last Post: 07-20-2006, 09:28 PM
  3. Boot up Windows before you even log in.
    By Dave84311 in forum General
    Replies: 6
    Last Post: 01-15-2006, 09:10 PM
  4. warrock wpe packet info
    By kvmn8 in forum WarRock - International Hacks
    Replies: 0
    Last Post: 01-04-2006, 08:36 PM
  5. Sugestion--Post Saved packets (WR)
    By wardo1926 in forum General Game Hacking
    Replies: 12
    Last Post: 01-03-2006, 10:41 AM