• Welcome to Valhalla Legends Archive.
 

0x50 with C# Problem

Started by PhoeNix_FasT, August 15, 2007, 01:10 PM

Previous topic - Next topic

PhoeNix_FasT

Im new to C# (learning it for 2 Month now) and i tried the simpliest thing : Sending 0x50 and receive an answer.
For this i use MBNCSUtil ( using MBNCSUtil; )
This is what i wrote

            IPHostEntry ip = Dns.GetHostByName("useast.battle.net");
            IPAddress[] ips = ip.AddressList;
            IPAddress battleNetIP = ips[0];

            richTextBox1.AppendText("Address of useast.battle.net : " + battleNetIP + "\n");

            m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEnd = new IPEndPoint(battleNetIP, battleNetPort);
            try
            {
                m_clientSocket.Connect(ipEnd);
            }
            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            if(m_clientSocket.Connected)
                richTextBox1.AppendText("Connected\n");

            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertInt32(0);             
            pck0x50.InsertDwordString("IX86"); 
            pck0x50.InsertDwordString("D2XP"); 
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertDwordString("", 0);   
            pck0x50.InsertCString("USA");       
            pck0x50.InsertCString("United States");

            byte[] byteData = new byte[32];

            try
            {
                m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None);   
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received :" + i + "\n");

Its my first time i try to use Sockets in C#. Anyways .. i = 0, means i received 0 bytes.
What did i do wrong ?

brew

#1
Did you send the 0x01 protocol byte first? And I'm assuming pck0x50.InsertDwordString("D2XP"); 
reverses and concatinates "D2XP" to the buffer, amirite? Not to mention you're missing the verbyte dword (comes right after the client id) Also .... er... "pck0x50.InsertInt32(0);             
            pck0x50.InsertDwordString("", 0);   " Are you sure you have the basic format of the 0x50 packet down?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

PhoeNix_FasT

#2
0x01 ? Sorry didnt find that
I had a look right here : http://ersan.us/src/bnetdocs/sequence.html

it says:

SEND ->   SID_AUTH_INFO   (0x50)
RECV <-   SID_PING   (0x25)
RECV <-   SID_AUTH_INFO   (0x50)

So would it be enough with

BncsPacket pck0x01 = new BncsPacket((byte)0x01);

and then send this packet ?

Hdx

No, its not a packet, its jsut a raw byte, i assume your packetbuffer adds the header info (0xff id length)
Which you wont need for the protocol byte.
As he also said, you're missing the version byte in your 0x50 build, fix that.
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

PhoeNix_FasT

            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertInt32(0);             
            pck0x50.InsertDwordString("IX86"); 
            pck0x50.InsertDwordString("D2XP");
            pck0x50.InsertByte(0x0A);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertInt32(0);             
            pck0x50.InsertDwordString("", 0);   
            pck0x50.InsertCString("USA");       
            pck0x50.InsertCString("United States");

            byte[] byteData = new byte[511];

            try
            {
                m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None);
                richTextBox1.AppendText("Sending 0x50\n");
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received :" + i + "\n");


i is still 0 ..  >:(

Hdx

Where are you sending the protocol byte?
And the verbyte ix 0x0b...
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

brew

Also not to mention that the verbyte is a dword, not a single byte. (see: "Not to mention you're missing the verbyte dword")
are you checking for FD_CLOSE on data arrival? And also checking WSAGetLastError()?
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

PhoeNix_FasT

Ok... i dont give up  :-\
So i updated the 0x50 Packet.
iRes = 58 Bytes (ok seems the packet reached the server)
i still = 0

to brew : FD_CLOSE and WSAGetLastError() is C++ not C#

Here's my Code now

            IPHostEntry ip = Dns.GetHostByName("useast.battle.net");
            IPAddress[] ips = ip.AddressList;
            IPAddress battleNetIP = ips[0];

            m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEnd = new IPEndPoint(battleNetIP, battleNetPort);
            m_clientSocket.Connect(ipEnd);

            BncsPacket pck0x50 = new BncsPacket((byte)0x50);
            pck0x50.InsertDwordString("0");          // (DWORD)       Protocol ID (0)           
            pck0x50.InsertDwordString("IX86");      // (DWORD)       Platform ID
            pck0x50.InsertDwordString("D2XP");      // (DWORD)       Product ID
            pck0x50.InsertDwordString("0x0b");      // (DWORD)       Version Byte
            pck0x50.InsertDwordString("");          // (DWORD)       Product language
            pck0x50.InsertDwordString("");          // (DWORD)       Local IP for NAT compatibility
            pck0x50.InsertDwordString("");          // (DWORD)       Time zone bias
            pck0x50.InsertDwordString("");          // (DWORD)       Locale ID           
            pck0x50.InsertDwordString("");          // (DWORD)       Language ID
            pck0x50.InsertCString("USA");           // (STRING)     Country abreviation   
            pck0x50.InsertCString("United States"); // (STRING)     Country

            byte[] byteData = new byte[511];

            try
            {
                int iRes = m_clientSocket.Send(pck0x50.GetData(), SocketFlags.None);
                richTextBox1.AppendText("0x50 : " + iRes + " Bytes sent\n");
            }

            catch (Exception exp)
            {
                richTextBox1.AppendText("Exception : " + exp.Message + "\n");
                return;
            }

            int i = m_clientSocket.Receive(byteData);
            richTextBox1.AppendText("Bytes Received : " + i + "\n");

EDIT : Is it better to use Network Stream instead of this what i am doing here ?

Hdx

-.-
The verbyte is a dword, not literally "0x0b"
it's actually "\xb\x0\x0\x0"
Also, where is the protocol byte!
I see the protocol version, but not the byte, directly after you create the connection, send a single byte 0x01
Why the HELL are you inserting them all as 'DwordStrings' there is no such thing.
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

brew

Hdx, I think he knows that. Eh... Post us your insert dword string function maybe it's a problem with that? And how do you check for winsock errors in C#, by now if you've made that many errors in your code you probably have gotten ipbanned. But yeah, you still have to send that raw 0x01 byte to battle.net first before sending the 0x50 packet.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

Hdx

Naw, he doesn't know jack, he just PMed me with a bunch of bull, He needs to learn the basics of data handling in his language before he attempts to make a bot.
He still thinks he should use his packetbuffer for the protocol byte after we have all explained to him several times that its just one raw byte to be sent over to connection before anything else.
int i = clientSocket.send("\x1", SocketFlags.None);
How hard is that to comprehend?
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

brew

Guess so, hdx. I'm glad we have this problem solved.
<3 Zorm
Quote[01:08:05 AM] <@Zorm> haha, me get pussy? don't kid yourself quik
Scio te esse, sed quid sumne? :P

MyndFyre

Quote from: Hdx on August 15, 2007, 05:27 PM
Naw, he doesn't know jack, he just PMed me with a bunch of bull, He needs to learn the basics of data handling in his language before he attempts to make a bot.
He still thinks he should use his packetbuffer for the protocol byte after we have all explained to him several times that its just one raw byte to be sent over to connection before anything else.
int i = clientSocket.send("\x1", SocketFlags.None);
How hard is that to comprehend?
~Hdx
Aside from not being C# or .NET-compliant, not too hard, since there's no overload that accepts (String, SocketFlags) in the parameter list.

if (clientSocket.Send(new byte[] { 1 }) != 1) might be an interesting code concept.

Quote from: Hdx on August 15, 2007, 05:03 PM
Why the HELL are you inserting them all as 'DwordStrings' there is no such thing.
As the documentation states:
Quote
This method inserts a string with the maximum length of 4 into the buffer, reversed. This mimics the C-style declarations of 4-character integer literals:

unsigned long int star_product = 'STAR';


which results in
RATS
being in memory.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Hdx

Who says he was using jinx's buffer class?
Anyways, Ya I messed up iy should of been a byte[] but I wrote it off the top of my head so meh.
And I still think they should be treated as the dwords they are not '"Dword String" of value "" '
Which sounds better when reading code, that or 'Dword of value 0'
~Hdx

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

MyndFyre

Quote from: Hdx on August 21, 2007, 02:29 AM
Who says he was using jinx's buffer class?
He did:
Quote from: PhoeNix_FasT on August 15, 2007, 01:10 PM
For this i use MBNCSUtil ( using MBNCSUtil; )
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.