Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Silkroad Online > SRO Coding Corner
You last visited: Today at 10:02

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Sending a simple packet with nuconnector

Discussion on Sending a simple packet with nuconnector within the SRO Coding Corner forum part of the Silkroad Online category.

Closed Thread
 
Old   #1
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
[HELP]Sending a simple packet with nuconnector



I've noticed that sending packets to silkroad is not a thing only a few people can do. I'm interested in sending the sitting packet to the silkroad server with the help of nuconnector (using C#). How can this be achieved? I understand that the hard work is done by the nuconnector, but how to connect to it and how to send the packet?

Not experienced programmer, so a working code would be really appreciated.

Trying to learn this stuff, but I really don´t know how. Right now, I'm learning from TCP networking tutorials and C# ebooks.


Regards,
Vanapapi
Vanapapi is offline  
Old 07/09/2013, 00:31   #2
 
elite*gold: 1000
Join Date: Apr 2012
Posts: 1,003
Received Thanks: 208
Connect to the proxy via a tcp socket. Sniff the correct packet. Send the previously sniffed packet. Done.
qkuh is offline  
Thanks
1 User
Old 07/09/2013, 23:14   #3
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
Quote:
Originally Posted by qkuh View Post
Connect to the proxy via a tcp socket. Sniff the correct packet. Send the previously sniffed packet. Done.
Thank you for the answer, I'll look into that. Although connecting to the proxy is my main concern, there are no guides available, yet so many people here seem to know how to do it.
Vanapapi is offline  
Old 07/10/2013, 00:18   #4
 
Kazuyaš's Avatar
 
elite*gold: 0
Join Date: Apr 2007
Posts: 449
Received Thanks: 236
here is a source of an old autoit app i made just for proof of concept.
you get the idea of how to do it.

Code:
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>
#include <ToolbarConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Test Packet Sender", 282, 250, 518, 275)
$Menu1 = GUICtrlCreateMenu("Menu")
$Menu_Button1 = GUICtrlCreateMenuItem("Connect", $Menu1)
$Menu_Button2 = GUICtrlCreateMenuItem("Disconnect", $Menu1)
$Menu_Button3 = GUICtrlCreateMenuItem("Exit", $Menu1)
$Edit1 = GUICtrlCreateEdit("", 8, 92, 265, 105, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_READONLY))
_GUICtrlEdit_AppendText($Edit1, "Welcome To Kazuya's iSRO Packet Sender" & @CRLF)
GUICtrlSetBkColor($Edit1, 0xFFFFFF)
$Button1 = GUICtrlCreateButton("Sit/Stand", 103, 25, 75, 25)
$Button4 = GUICtrlCreateButton("Kill SRO", 103, 55, 75, 25)
$Status1 = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetText($Status1, "Status: Disconnected")
GUISetState(@SW_SHOW)

Global $Socket, $op, $dat

; -------------------------------------------------------------------------------- ;
; credits: jremy
Func InjectPacket($opcode, $data)
	$size = Hex(StringLen($data) / 2, 4)
	$size = StringMid($size, 3, 2) & StringMid($size, 1, 2)
	$opcode = StringMid($opcode, 3, 2) & StringMid($opcode, 1, 2)
	$packet = _HexToString($size & $opcode & "0100" & $data)
	TCPSend($Socket, $packet)
EndFunc
; -------------------------------------------------------------------------------- ;

While 1
	$msg = GUIGetMsg($Form1)
	Switch($msg)
		Case $GUI_EVENT_CLOSE
			ExitLoop
		Case $Menu_Button1 
			Connect_nuConnector()
		Case $Menu_Button2
			Disconnect_nuConnector()
		Case $Menu_Button3
			Close_App()
		Case $Button1 
			Char_Sit_Stand()
		Case $Button4
			Kill_SRO()
	EndSwitch
WEnd

; Simple Log MSG Function For Packets/Opcodes
Func Send_MSG()
	_GUICtrlEdit_AppendText($Edit1, "Injecting:  [" & $op & "]" & " (" & $dat & ")" & @CRLF)
EndFunc

; Menu 1
Func Connect_nuConnector()
	If FileExists("nuConnector.exe") Then
		Run("nuConnector.exe", "", @SW_HIDE)
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Opened" & @CRLF)
	Else
		_GUICtrlEdit_AppendText($Edit1, "Error - Cannont Locate nuConnector." & @CRLF)
	EndIf
	Sleep(1500)
	TCPStartup()
	$Socket = TCPConnect("127.0.0.1", 22580)
	If $Socket = @error Then 
		_GUICtrlEdit_AppendText($Edit1, "Error - Cannont Connect To nuConnector." & @CRLF)
	Else
		_GUICtrlStatusBar_SetText($Status1, "Status: Connected")
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Connected" & @CRLF)
	EndIf
EndFunc

; Menu 2
Func Disconnect_nuConnector()
	If ProcessExists("nuConnector.exe") Then 
		TCPCloseSocket($Socket)
		TCPShutdown()
		ProcessClose("nuConnector.exe")
		_GUICtrlStatusBar_SetText($Status1, "Status: Disconnected")
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Disconnected/Closed" & @CRLF)
	EndIf
EndFunc

; Menu 3
Func Close_App()
	Exit
	ProcessClose("Autoit3.exe")
EndFunc

; Button 1
Func Char_Sit_Stand()
	$op = "704F"
	$dat = "04"
	InjectPacket($op, $dat)
	Send_MSG()
	Sleep(1000)
EndFunc

; Button 4
Func Kill_SRO()
	If ProcessExists("SRO_Client.exe") Then
		ProcessClose("SRO_Client.exe")
		_GUICtrlEdit_AppendText($Edit1, "SRO Closed")
	Else
		_GUICtrlEdit_AppendText($Edit1, "SRO Isnt Open")
	EndIf
EndFunc
Kazuyaš is offline  
Thanks
1 User
Old 07/10/2013, 18:29   #5
 
Schickl's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,064
Received Thanks: 539
You just have to connect to nuconnector and you'll get all(well not all to be exact) packets
Schickl is offline  
Old 07/10/2013, 22:19   #6
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
Quote:
Originally Posted by Schickl View Post
You just have to connect to nuconnector and you'll get all(well not all to be exact) packets
That's the point, everyone says: "Oh, it's easy, just connect to the nuconnector and send the packet." Could you provide a working example please?

It might be easy for an experienced programmer, but it's quite complicated for a beginner.

Quote:
Originally Posted by Kazuyaš View Post
here is a source of an old autoit app i made just for proof of concept.
you get the idea of how to do it.

Code:
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>
#include <ToolbarConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <GuiEdit.au3>

$Form1 = GUICreate("Test Packet Sender", 282, 250, 518, 275)
$Menu1 = GUICtrlCreateMenu("Menu")
$Menu_Button1 = GUICtrlCreateMenuItem("Connect", $Menu1)
$Menu_Button2 = GUICtrlCreateMenuItem("Disconnect", $Menu1)
$Menu_Button3 = GUICtrlCreateMenuItem("Exit", $Menu1)
$Edit1 = GUICtrlCreateEdit("", 8, 92, 265, 105, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_READONLY))
_GUICtrlEdit_AppendText($Edit1, "Welcome To Kazuya's iSRO Packet Sender" & @CRLF)
GUICtrlSetBkColor($Edit1, 0xFFFFFF)
$Button1 = GUICtrlCreateButton("Sit/Stand", 103, 25, 75, 25)
$Button4 = GUICtrlCreateButton("Kill SRO", 103, 55, 75, 25)
$Status1 = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetText($Status1, "Status: Disconnected")
GUISetState(@SW_SHOW)

Global $Socket, $op, $dat

; -------------------------------------------------------------------------------- ;
; credits: jremy
Func InjectPacket($opcode, $data)
	$size = Hex(StringLen($data) / 2, 4)
	$size = StringMid($size, 3, 2) & StringMid($size, 1, 2)
	$opcode = StringMid($opcode, 3, 2) & StringMid($opcode, 1, 2)
	$packet = _HexToString($size & $opcode & "0100" & $data)
	TCPSend($Socket, $packet)
EndFunc
; -------------------------------------------------------------------------------- ;

While 1
	$msg = GUIGetMsg($Form1)
	Switch($msg)
		Case $GUI_EVENT_CLOSE
			ExitLoop
		Case $Menu_Button1 
			Connect_nuConnector()
		Case $Menu_Button2
			Disconnect_nuConnector()
		Case $Menu_Button3
			Close_App()
		Case $Button1 
			Char_Sit_Stand()
		Case $Button4
			Kill_SRO()
	EndSwitch
WEnd

; Simple Log MSG Function For Packets/Opcodes
Func Send_MSG()
	_GUICtrlEdit_AppendText($Edit1, "Injecting:  [" & $op & "]" & " (" & $dat & ")" & @CRLF)
EndFunc

; Menu 1
Func Connect_nuConnector()
	If FileExists("nuConnector.exe") Then
		Run("nuConnector.exe", "", @SW_HIDE)
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Opened" & @CRLF)
	Else
		_GUICtrlEdit_AppendText($Edit1, "Error - Cannont Locate nuConnector." & @CRLF)
	EndIf
	Sleep(1500)
	TCPStartup()
	$Socket = TCPConnect("127.0.0.1", 22580)
	If $Socket = @error Then 
		_GUICtrlEdit_AppendText($Edit1, "Error - Cannont Connect To nuConnector." & @CRLF)
	Else
		_GUICtrlStatusBar_SetText($Status1, "Status: Connected")
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Connected" & @CRLF)
	EndIf
EndFunc

; Menu 2
Func Disconnect_nuConnector()
	If ProcessExists("nuConnector.exe") Then 
		TCPCloseSocket($Socket)
		TCPShutdown()
		ProcessClose("nuConnector.exe")
		_GUICtrlStatusBar_SetText($Status1, "Status: Disconnected")
		_GUICtrlEdit_AppendText($Edit1, "nuConnector: Disconnected/Closed" & @CRLF)
	EndIf
EndFunc

; Menu 3
Func Close_App()
	Exit
	ProcessClose("Autoit3.exe")
EndFunc

; Button 1
Func Char_Sit_Stand()
	$op = "704F"
	$dat = "04"
	InjectPacket($op, $dat)
	Send_MSG()
	Sleep(1000)
EndFunc

; Button 4
Func Kill_SRO()
	If ProcessExists("SRO_Client.exe") Then
		ProcessClose("SRO_Client.exe")
		_GUICtrlEdit_AppendText($Edit1, "SRO Closed")
	Else
		_GUICtrlEdit_AppendText($Edit1, "SRO Isnt Open")
	EndIf
EndFunc
Thanks for the code. I partly understood it, I have to create TCP client in C# and connect it to the nuconnector with the right IP and PORT. How do you know the right ones?

Secondly I got lost at the:
Code:
Func InjectPacket($opcode, $data)
	$size = Hex(StringLen($data) / 2, 4)
	$size = StringMid($size, 3, 2) & StringMid($size, 1, 2)
	$opcode = StringMid($opcode, 3, 2) & StringMid($opcode, 1, 2)
	$packet = _HexToString($size & $opcode & "0100" & $data)
	TCPSend($Socket, $packet)
EndFunc
What is happening here?

Thirdly, you use a function TCPSend(mainsocket, data). How can I do this in C#? I think I have to get a stream, create a binarywriter and then send the data, how would it look like?

EDIT: Do I have to patch my client in order for this to work? And does nuconnector say something like bot connected, if you connect to it?
Vanapapi is offline  
Old 07/11/2013, 11:16   #7
 
elite*gold: 1000
Join Date: Apr 2012
Posts: 1,003
Received Thanks: 208
I can help you with connecting to NuConnector or phConnector (preferred) in C#.
PM me with your Skype name
qkuh is offline  
Old 07/11/2013, 13:21   #8
 
Schickl's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,064
Received Thanks: 539
Quote:
Originally Posted by Vanapapi View Post
That's the point, everyone says: "Oh, it's easy, just connect to the nuconnector and send the packet." Could you provide a working example please?

It might be easy for an experienced programmer, but it's quite complicated for a beginner.
I never used C# so I can't really give you an example
I looked something up, though:
Code:
TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("127.0.0.1", 22580);
Not sure if it really is what you're looking for, but it really looks like it

Quote:
Thanks for the code. I partly understood it, I have to create TCP client in C# and connect it to the nuconnector with the right IP and PORT. How do you know the right ones?
IP is the localhost(because it's running on your PC) and Port is 22580
That's just a random port the creator of nuconnector used
Oh and remote connections don't work(I think; I remember it listening on localhost only; not sure though)

Quote:
EDIT: Do I have to patch my client in order for this to work? And does nuconnector say something like bot connected, if you connect to it?
Yes you have to.
The client has to connect to localhost as well(port is the original one, Joymax uses)

And yes nuconnector notifies you when you connect to it
It waits for the bot to connect and then for the client
Schickl is offline  
Thanks
1 User
Old 07/11/2013, 13:58   #9
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
Quote:
Originally Posted by Schickl View Post
I never used C# so I can't really give you an example
I looked something up, though:
Code:
TcpClient tcpClient = new TcpClient ();
tcpClient.Connect ("127.0.0.1", 22580);
Used the exact same thing in my code. But didn't really progress before, because the nuconnector didn't say anything and I don't have the knowledge send anything.

EDIT: Phconnector (now nuconnector too) says, that I'm connected to the proxy(used the same method), now, how to send the packet?

EDIT2: Now I got a code like this, but it's not working:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

namespace Connecting_to_nuconnector
{
    class Program
    {

        /*Found it on MSDN: http://msdn.microsoft.com/en-us/library/ms145128.aspx needed for socket.beginconnect*/
        public static void ConnectCallback1(IAsyncResult ar)
        {
            allDone.Set();
            Socket socketclient = (Socket)ar.AsyncState;
            socketclient.EndConnect(ar);
        }

        public static ManualResetEvent allDone = new ManualResetEvent(false);

        static void Main(string[] args)
        {
            
            //Create the array to get the size of the data 
            byte[] array = new byte[200];
            BinaryWriter bw = new BinaryWriter(new MemoryStream(array));
            bw.Write((byte)0x04);
            ushort size = (ushort)array.Length;
            bw.Close();

            //Create second array to send
            byte[] array2 = new byte[200];
            BinaryWriter bw2 = new BinaryWriter(new MemoryStream(array2));
            bw2.Write((ushort)size);                 /size
            bw2.Write((ushort)0x704F);             /opcode
            bw2.Write((ushort)0x0100);             /direction
            bw2.Write((ushort)0x04);                /data
            bw2.Close();

            //Create a socket
            Socket socketclient = new Socket(AddressFamily.InterNetwork,
                SocketType.Stream, ProtocolType.Tcp);

            IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
            IPEndPoint remoteEP = new IPEndPoint(ipAddress, 22580);

            socketclient.BeginConnect("127.0.0.1", 22580, new AsyncCallback(ConnectCallback1), socketclient);

            allDone.WaitOne();

            while (true)
            {
            socketclient.Send(array2);

            Console.WriteLine("Array sent");

            Console.ReadLine();
            }
        }
    }
}
EDIT3: qkuh fixed it for me. EDIT4: Sit part still not working.
Vanapapi is offline  
Old 07/13/2013, 20:17   #10
 
Kazuyaš's Avatar
 
elite*gold: 0
Join Date: Apr 2007
Posts: 449
Received Thanks: 236
you should post your final source. so we can see how its done
Kazuyaš is offline  
Old 07/13/2013, 21:25   #11
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
Quote:
Originally Posted by Kazuyaš View Post
you should post your final source. so we can see how its done
Don't worry, I will post it here(want others to learn from this thread as well), but still working on that with qkuh (he said he'll show me mistakes, but coded almost everything ). He made me a code which receives packets from the server, and if you press enter, it exits. It works without the media patcher and it can be launched during the game, as long as proxy is connected.

The problem right now is, that the sit packet isn't working(which was the whole point of this thread). When he can, he'll show me what's wrong with my code. Does anyone else know what's wrong? Wanted to make it as simple as possible to understand sending a sit packet, but I think here is some unnecessary parts that I plan to remove, so that other beginners can understand.

Doesn't make the character sit, so any help on sending the sitting packet still appreciated!

As of now, the code is:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;                           
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;     /*Some librarys probably not needed, gonna remove them*/

namespace Sending_a_packet
{
    class Program
    {
        private static ManualResetEvent connectDone = new ManualResetEvent(false);
        private static Socket socketclient = null;

        /*Found it on MSDN: http://msdn.microsoft.com/en-us/library/ms145128.aspx needed for socket.beginconnect*/
        public static void ConnectCallback(IAsyncResult ar)
        {
            connectDone.Set();
            Socket socketclient = (Socket)ar.AsyncState;

            if (socketclient.Connected)
            {
                Console.WriteLine("Connected");

                //Create the array to get the size of the data 
                byte[] array = new byte[200];
                BinaryWriter bw = new BinaryWriter(new MemoryStream(array));
                bw.Write((byte)0x04);
                ushort size = (ushort)bw.BaseStream.Position;
                bw.Close();




                //Create second array to send
                byte[] array2 = new byte[200];
                BinaryWriter bw2 = new BinaryWriter(new MemoryStream(array2));
                bw2.Write((ushort)size);                 //size
                bw2.Write((ushort)0x704F);             //opcode
                bw2.Write((ushort)0x0100);             //direction
                bw2.Write((ushort)0x04);                //data
                int position = (int)bw2.BaseStream.Position;
                bw2.Close();

                socketclient.Send(array2, position - 2, 0);
                Console.WriteLine("SENT");

                Receive();
            }
            else
            {
                Console.WriteLine("Cannot connect");
            }

            socketclient.EndConnect(ar);
        }

       

        static void Main(string[] args)
        {
           
            //Create a socket
            socketclient = new Socket(AddressFamily.InterNetwork,
                SocketType.Stream, ProtocolType.Tcp);

            socketclient.BeginConnect("127.0.0.1", 23580, new AsyncCallback(ConnectCallback), socketclient);
            connectDone.WaitOne();

            Console.WriteLine("Press enter again");
            Console.ReadLine();
        }

        static void Receive()
        {
            StateObject obj = new StateObject();
            obj.workSocket = socketclient;

            socketclient.BeginReceive(obj.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), obj);
        }

        static void ReceiveCallback(IAsyncResult ar)
        {
            StateObject obj = (StateObject)ar.AsyncState;
            socketclient = obj.workSocket;

            int bytesRead = socketclient.EndReceive(ar);

            if(bytesRead > 0)
            {
                Console.WriteLine(bytesRead + " bytes received!");
                String hexString = BitConverter.ToString(obj.buffer, 0, bytesRead).Replace("-", "");
                Console.WriteLine("[PACKET] " + hexString);
            }

            socketclient.BeginReceive(obj.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), obj);
        }
    }

    public class StateObject 
    {
    // Client socket.
    public Socket workSocket = null;
    // Size of receive buffer.
    public const int BufferSize = 256;
    // Receive buffer.
    public byte[] buffer = new byte[BufferSize];
    // Received data string.
    public StringBuilder sb = new StringBuilder();
    }
}
Probably going post what I learned in the first post once I get it working and understand it.
EDIT: The mistake was in the direction byte, it has to be 0x0001, not 0x0100!! Left the mistake in so you can see it.
Vanapapi is offline  
Old 07/13/2013, 23:32   #12
 
Schickl's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,064
Received Thanks: 539
Quote:
bw2.Write((ushort)0x04); //data
You casted it as ushort, but it has to be a byte
This shouldn't affect anything, though

This part of the code is useless:
Code:
//Create the array to get the size of the data 
                byte[] array = new byte[200];
                BinaryWriter bw = new BinaryWriter(new MemoryStream(array));
                bw.Write((byte)0x04);
                ushort size = (ushort)bw.BaseStream.Position;
                bw.Close();
You can make the size static(works for your example program)
In case you need a dynamic one some time, you should make your own class for Packets
In there you would modify the size every time you add something(seek to the beginning and overwrite the size, or keep it in a variable and write it in your array when you send the packet)

I would make it this way:
Code:
public static void ConnectCallback(IAsyncResult ar)
        {
            connectDone.Set();
            Socket socketclient = (Socket)ar.AsyncState;

            if (socketclient.Connected)
            {
                Console.WriteLine("Connected");

                //Changed the size to the one you really need. Be sure to increase it, if you use bigger packets
                byte[] array2 = new byte[7];  
                BinaryWriter bw2 = new BinaryWriter(new MemoryStream(array2));
                
                //making it static is so much easier right now
                bw2.Write((ushort)1);                 //size
                bw2.Write((ushort)0x704F);             //opcode
                bw2.Write((ushort)0x0100);             //direction

                bw2.Write((byte)0x04);                //data
                //I'm assuming that BinaryWriter.BaseStream.Position is zero based, I'm not sure, though, because I can't find shit about it on the MSDN page(It only says that it's possible to get the position from it, but not if it's zero based or not)
                int position = (int)bw2.BaseStream.Position; 
                bw2.Close();

                socketclient.Send(array2, position, 0);
                Console.WriteLine("SENT");

                Receive();
            }
            else
            {
                Console.WriteLine("Cannot connect");
            }

            socketclient.EndConnect(ar);
        }
The code above should work.

This part looks wrong:
Code:
socketclient.Send(array2, position - 2, 0);
Why would cut 2 bytes off?
Schickl is offline  
Old 07/14/2013, 00:27   #13
 
elite*gold: 1000
Join Date: Apr 2012
Posts: 1,003
Received Thanks: 208
That's the final code (I helped him)
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace SRPackets
{
    class Program
    {
        private static Socket sock = null;
        private static ManualResetEvent connectDone = new ManualResetEvent(false);

        static void Main(string[] args)
        {
            sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.BeginConnect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 23580), new AsyncCallback(ConnectCallback), sock);
            connectDone.WaitOne();

            Console.ReadLine();
        }

        static void ConnectCallback(IAsyncResult ar)
        {
            sock = (Socket)ar.AsyncState;
            sock.EndConnect(ar);
            connectDone.Set();

            if (sock.Connected)
            {
                   SendSilkroadPacket(0x7034, 0x0100, "0A0100000000000000");
                   Console.WriteLine("Sent.");
            }
        }

        static void SendSilkroadPacket(ushort opcode, ushort direction, string data)
        {
            byte[] arrBuffer = new byte[6 + data.Length / 2];                          //6 bytes -> 2 size, 2 opcode, 2 direction = 6

            BinaryWriter bw = new BinaryWriter(new MemoryStream(arrBuffer));
            bw.Write((ushort)(arrBuffer.Length - 6));
            bw.Write((ushort)opcode);
            bw.Write((ushort)0x0001);
            bw.Write((byte[])StringToByteArray(data));
            bw.Close();

            sock.Send(arrBuffer);
        }

        static byte[] StringToByteArray(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }
    }
}
Quote:
You casted it as ushort, but it has to be a byte
This shouldn't affect anything, though
It's not unimportant. If you cast it to an ushort, 0x0004 will be sent. Otherwise 0x04. But casting it to an ushort is obviously wrong.

Quote:
Why would cut 2 bytes off?
You have to get the size of the data. But the calculation is a bit wrong.
qkuh is offline  
Thanks
1 User
Old 07/14/2013, 11:19   #14
 
Schickl's Avatar
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,064
Received Thanks: 539
Quote:
It's not unimportant. If you cast it to an ushort, 0x0004 will be sent. Otherwise 0x04. But casting it to an ushort is obviously wrong.
If the size is set 1, it doesn't matter
Because of the byte order 0x04 is in the first byte and 0x00 in the second
-> both methods would work that way
Schickl is offline  
Old 07/14/2013, 22:14   #15
 
Vanapapi's Avatar
 
elite*gold: 0
Join Date: Mar 2008
Posts: 111
Received Thanks: 10
GUIDE:HOW TO SEND A PACKET WITH THE HELP OF PHCONNECTOR AND EDXLOADER
In order to make a packet sender to work, we need to send the connection through a proxy, which will take care of the encryption and decryption of the packets(the security basically, except the hackshield, that’s why you can’t use it on isro). And in order to make the proxy work, we need to use a loader(edx loader in the example) which will redirect all the traffic through the proxy.

*This is an example, we will cover setting the ports and selecting the server you like.

To send a packet to silkroad server with phconnector/nuconnector(going to use phconnector in examples, but there shouldn't be any difference), we need to set the configuration files of the phconnector, so it knows where the data is coming from and where to send it to.

To do that we need to know the IP address and PORT of the server. To get the IP and the PORT, we need to open up edxLoader and add the sro_client to it. After that the edxloader should display the IP address and the port of the server. While the edxloader is still open go ahead and tick “Multiclient” and “Redirect Gateway Server” and set the port to 18000(will cover why we did this). Our edxLoader should look something like this now:

Open up the phconnector configuration file and you should see something like this:

Place your private server's (silkroad europe private server in my example) IP address and port into the config file. You may also enter a host name, or convert the host name into an ip address(google: convert host name into IP address).

Now we need to tell the phconnector, which port the exloader will redirect all the traffic, so the phconnector can listen and accept all the packets. For that we use ListenPort. You can set it to your liking as longs as you have set the edxloader to redirect the traffic to the same port.

Next, we need to set the port that the phconnector will listen and accept a bot connection(and later exchange data). For that we need to configure the BotPort. You can also set it to your liking, because this will be the port that the bot has to connect to, and when you code your own bot, you can tell it which port it needs to connect to. Finally our example configuration file should look like this:

Note: Bot->phconnector and Client(loader)->phconnector communication is done through localhost (127.0.0.1), and that's the reason, why we only set the ip for the private server and not for the bot and edxloader.
Next, we need to understand the basics of Socket programming and sro packet structure. A packet is an array of bytes, which in the case of sro consists of:
size(of the data only) (2bytes)
opcode (2bytes)
direction(some say security byte) (2bytes)
data (x bytes)
And you'll have to place those bytes in the array accordingly: size->opcode->direction->data.

For example, the sit packet:
size 00 01 (because the data is 04)
opcode 70 4f
direction 00 01 (0001 represents client to server (c->s) unencrypted(you can send encrypted packets too)*)
data 04
Which in byte array looks like 00 01 70 4f 00 01 04 . That is what we are going to send to the phconnector. Once we send it, phconnector encrypts it, sends to the server, and makes our character sit.
*Note: Security byte can be either 1,2,3 or 4, but most of the time, you want to use 1.
0x0001 Unencrypted to the Server
0x0002 Unencrypted to the Client

0x0003 Encrypted to the Server
0x0004 Encrypted to the Client

To send the array you need to establish a connection to the phconnector through the localhost and port(which in this example is set to 23580). Then use the Socket.Send method to send the packet. I can't explain any further, because this is the limit of my knowledge. To fully understand this you need to examine the source code provided by qkuh (2 posts up) and become familiar with socket programming.
GOOD ARTICLES ABOUT ASYNCHRONOUS SOCKET CONNECTION:





If you want to know how to sniff the packets, let me know(hint: it can be done with phAnalyzer). Report my mistakes too, please.
Attached Files
File Type: rar Phconnector, Loader, Analyzer, Process Explorer(Virus alerts false positive).rar (5.24 MB, 510 views)
Vanapapi is offline  
Thanks
5 Users
Closed Thread


Similar Threads Similar Threads
c# sending packet
11/22/2011 - .NET Languages - 0 Replies
i enter an online flash game from my app webbrowser tho i cant find out how to send packets trougth it :S. i managed to send packets trought WPE PRO tho i want to code it into my proggy. i dont think i need to hook my own app am i?
Need help sending a packet !
02/28/2010 - Kal Online - 1 Replies
i've got a Question and i hope some1 can help me there is an item at a NPC that u can buy 1 only each time .. and i need to buy 1000000 of it so i need to send the packet to buy this item 1000000 times when i try to sniff the packet to buy this item i got : Packet type : 0x18 format : m arguments : (unknown character) so ... how can i send that (unknown character) as an argument ?? in the code that (unknown character) is displayed from "(DWORD)va_arg(args,DWORD)" when i tried to save...
sending packet at WPe
07/18/2008 - Dekaron - 10 Replies
after sending some packet at WPE my connection to 2moons always got disconnect the moment I send the packet can someone help me regargding this
packet sending
03/31/2008 - RF Online - 4 Replies
now i know how to bypass rf online and now i can run WPE PRO w/o getting detected by fireguard.any1 can help me w/ this packet sniffing?coz i get confused on what packet to capture and send to the server.thanks
sending a packet
11/26/2007 - Conquer Online 2 - 3 Replies
I've captured a packet that I'd like to re-send to do a specific function, but I don't know how to do that. I know it involves 4 encryption keys and a packet id number. My best guess is to send the packet to a proxy that hopefully will forward it to the server properly. Anyone want to offer some tips on what to use?



All times are GMT +1. The time now is 10:05.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.