#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.6.0
Author: Frayzer
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <string.au3>
Global $sBuffer, $rBuffer
Global $iSize, $iIndex
;Example function: Write a notice!
NewPacket(0x3026, 1); OpCode 0x3026 Security 2 (to server) 1 (to client) for SrProxy
AppendByte(7); Chat type
AppendString("Hello World!", True); Message (unicode)
;Sending the packet..
$socket = TCPConnect("127.0.0.1", 9000)
If @error Then Exit
TCPSend($socket, GetPacket())
#region PacketWriter
Func NewPacket($sValue, $iValue)
Local $sTemp = Hex($sValue)
$sBuffer = ""
$iSize = 0
$sBuffer &= StringLeft(ReverseHex(Hex($sValue)), 4);length
$sBuffer &= StringLeft(ReverseHex(Hex($iValue)), 4);security
EndFunc ;==>NewPacket
Func AppendByte($sValue)
$sBuffer &= StringRight(Hex($sValue), 2)
$iSize += 1
EndFunc ;==>AppendByte
Func AppendWord($sValue)
$sBuffer &= StringLeft(ReverseHex(Hex($sValue)), 4)
$iSize += 2
EndFunc ;==>AppendWord
Func AppendDWord($sValue)
$sBuffer &= StringLeft(ReverseHex(Hex($sValue)), 8)
$iSize += 4
EndFunc ;==>AppendDWord
Func AppendString($sString, $Unicode = false)
Local $iLength = StringLen($sString)
If $Unicode Then
$sBuffer &= _StringToHexExt($sString, True)
$iSize += $iLength * 4
Else
$sBuffer &= _StringToHexExt($sString)
$iSize += $iLength * 2
EndIf
EndFunc ;==>AppendString
Func GetPacket()
Local $sTemp = "0x"
$sTemp &= StringLeft(ReverseHex(Hex($iSize)), 4)
$sTemp &= $sBuffer
Return $sTemp
EndFunc ;==>GetPacket
#endregion
#region PacketReader
Func BeginParse($sString)
$iIndex = 1
$rBuffer = StringMid($sString, 13)
Return Dec(StringMid($sString, 3, 2) & StringMid($sString, 1, 2))
EndFunc ;==>BeginParse
Func ReadByte()
Local $result = Dec(StringMid($rBuffer, $iIndex, 2))
$iIndex += 2
Return $result
EndFunc ;==>ReadByte
Func ReadWord()
Local $result = Dec(ReverseHex(StringMid($rBuffer, $iIndex, 4)))
$iIndex += 4
Return $result
EndFunc ;==>ReadWord
Func ReadDWord()
Local $result = Dec(ReverseHex(StringMid($rBuffer, $iIndex, 8)))
$iIndex += 8
Return $result
EndFunc ;==>ReadDWord
Func ReadString($iLength, $Unicode = False)
Local $result, $string = ""
If $Unicode Then
For $i = 0 To $iLength - 1
$string &= StringMid($rBuffer, $iIndex + $i * 4, 2)
Next
$iIndex += $iLength * 4
Else
$string = StringMid($rBuffer, $iIndex, $iLength * 2)
$iIndex += $iLength * 2
EndIf
$result = _HexToString($string)
Return $result
EndFunc ;==>ReadString
#endregion
Func ReverseHex($sString)
Local $sTemp, $len
For $i = StringLen($sString) + 1 To 1 Step -2
$sTemp &= StringMid($sString, $i, 2)
Next
Return $sTemp
EndFunc ;==>ReverseHex
Func _StringToHexExt($sString, $Unicode = False)
Local $string
If $Unicode Then
For $i = 1 To StringLen($sString)
$string &= _StringToHex(StringMid($sString, $i, 1)) & "00"
Next
Else
For $i = 1 To StringLen($sString)
$string &= _StringToHex(StringMid($sString, $i, 1))
Next
EndIf
Return $string
EndFunc ;==>_StringToHexExt