Jump to content

TCPSend()


Ranmaru
 Share

Recommended Posts

Is it possible to send this kind of data from AutoIt?

Message ID: 0x50

Message Name: SID_AUTH_INFO

(DWORD)      Protocol ID (0)
(DWORD)      Platform ID 
(DWORD)      Product ID 
(DWORD)      Version Byte
(DWORD)      Product language
(DWORD)      Local IP for NAT compatibility*
(DWORD)      Time zone bias*
(DWORD)      Locale ID*
(DWORD)      Language ID*
(STRING)     Country abreviation 
(STRING)     Country

I got this stuff from here: http://ersan.us/src/bnetdocs/content9626.html?Code=2

As far as I know the TCPSend() sends the data in string, but can also send binary data and I am not familiar with this at all.

The answer I'm looking for is if sending this type of data is possible in AutoIt or not.

Any help as to how it could be actually done would be greatly appreciated.

- Thanks in advance, Ran.

Link to comment
Share on other sites

Demo send/recv binary data:

Server (open receiving port) side (start first):

;SERVER!! Start Me First !!!!!!!!!!!!!!!
#include <GUIConstants.au3>

Global $szIPADDRESS = "127.0.0.1"
Global $nPORT = 33891

; Start The TCP Services
TCPStartup()

; Create a Listening "SOCKET".
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
If $MainSocket = -1 Then Exit

; Create a GUI for messages
Global $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
Global $edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()

; Initialize a variable to represent a connection
Global $ConnectedSocket = -1

;Wait for and Accept a connection
Do
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1

; Get IP of client connecting
Global $szIP_Accepted = SocketToIP($ConnectedSocket)

; GUI Message Loop
Global $msg
While 1
    Global $recv
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop

    ; Try to receive (up to) 2048 bytes
    $recv = TCPRecv($ConnectedSocket, 2048, 1) ; 1 = binary only
    If @error Then ExitLoop

    ; Update the edit control with what we have received
    If $recv <> "" Then 
        $nLen = BinaryLen($recv)
        For $n = 1 To $nLen Step 4
            $msg &= "0x" & Hex(BinaryMid($recv, $n, 4), 8) & @CRLF
        Next
    EndIf
    GUICtrlSetData($edit, $msg)
WEnd

If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

TCPShutdown()


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    Local $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int_ptr", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc   ;==>SocketToIP

In the client InputBox, enter something all Hex, i.e. "0123456789ABCDEF0123456789" and you should see it on the server's edit box.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok thanks PsaltyDS, I think this is what I'm looking for, just don't know how to format my messages.

I've been reading about the Binary and Hex functions that you've used in there, however what I don't understand is how am I supposed to format this message to send to a server.

(DWORD)      Protocol ID (0)
(DWORD)      Platform ID 
(DWORD)      Product ID 
(DWORD)      Version Byte
(DWORD)      Product language
(DWORD)      Local IP for NAT compatibility*
(DWORD)      Time zone bias*
(DWORD)      Locale ID*
(DWORD)      Language ID*
(STRING)     Country abreviation 
(STRING)     Country

There's a certain server that requires me to send this type of a message, what I'd like to do is connect to the server and send this authorization message and continue with the connection. All the messages sent to and from the server are formatted as this, I don't understand what I'm supposed to do here and what makes this message's message id 0x50 :/

Platform ID and Product ID are actually DWORDS, even though they look like strings. For example, if you cast the sequence of bytes "SEXP" to a DWORD, you will have the correct value to send to Battle.net as the Program ID for Starcraft Broodwar. If you can't get your head around this, just reverse the 4 bytes and insert them as a string with no null-terminator, ie: "PXES". The same applies to Platform ID - which will be "IX86" (or, as a string, "68XI") for most people.

What is the difference between a DWORD and a String?

/edit

the format above is:

(DWORD) Protocol ID (0)

(DWORD) Platform ID

(DWORD) Program ID

i logged packets from my broodwar and i got

FF 50 3A 00 00 00 00 00 36 38 58 49 50 58 45 53 C9 00 00 00 53 55 6E 65 18 2F A9 C1 F0 00 00 00

where it beings with 50, i dont know what the 3A is for then 4 bytes (protocol ID) 00 00 00 00 then an extra 00? then 36 38 58 49 (68XI) 50 58 45 53 (PXES)

anyone know what the 3A and the extra 00 are for?

Perhaps this helps in explaining what it is that I'm trying to achieve? Edited by Ranmaru
Link to comment
Share on other sites

/edit

Perhaps this helps in explaining what it is that I'm trying to achieve?

First 4 bytes (FF 50 3A 00) - packet header, which consists of:

byte 0xFF (always)

byte message code (0x50)

word packet length (0x003A)

and then all the things for message 0x50:

dword protocol ID (0),

dword platform ID (IX86)

dword program ID (SEXP)

etc...

"be smart, drink your wine"

Link to comment
Share on other sites

Perhaps this helps in explaining what it is that I'm trying to achieve?

First 4 bytes (FF 50 3A 00) - packet header, which consists of:

byte 0xFF (always)

byte message code (0x50)

word packet length (0x003A)

and then all the things for message 0x50:

dword protocol ID (0),

dword platform ID (IX86)

dword program ID (SEXP)

etc...

Thanks for reply Siao, this helped me understand this quite a bit more.

I will post again once I've tried this when I get home in a couple of hours.

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...