Esempio n. 1
0
        protected void AccountLogin(byte type, List <byte> data)
        {
            if (ClientlessBot.debugging)
            {
                Console.WriteLine("{0}: [BNCS] Logging into the account", m_owner.Account);
            }
            UInt32      client_token = (uint)System.Environment.TickCount;
            List <byte> hash         = Bsha1.DoubleHash(client_token, m_owner.ServerToken, m_owner.Password);

            byte[] packet = BuildPacket((byte)0x3a, BitConverter.GetBytes(client_token), BitConverter.GetBytes(m_owner.ServerToken), hash, System.Text.Encoding.ASCII.GetBytes(m_owner.Account), zero);

            PrintPacket(packet);

            m_stream.Write(packet, 0, packet.Length);
        }
Esempio n. 2
0
        protected void RealmList(byte type, List <byte> data)
        {
            UInt32 count  = BitConverter.ToUInt32(data.ToArray(), 8);
            Int32  offset = 12;

            if (ClientlessBot.debugging)
            {
                Console.WriteLine("{0}: [BNCS] List of realms:", m_owner.Account);
            }

            for (ulong i = 1; i <= count; i++)
            {
                offset += 4;
                String realmTitle       = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
                String realmDescription = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] {1}. {2}, {3}", m_owner.Account, i, realmTitle, realmDescription);
                }

                if (m_owner.Realm == null && i == 1)
                {
                    if (ClientlessBot.debugging)
                    {
                        Console.WriteLine("{0}: [BNCS] No realm was specified in the ini so we're going to connect to {1}", m_owner.Account, realmTitle);
                    }
                    m_owner.Realm = realmTitle;
                }
            }

            if (m_owner.LoggedIn)
            {
                //make_game();
            }
            else
            {
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Logging on to the realm {1}", m_owner.Account, m_owner.Realm);
                }

                UInt32 clientToken = 1;
                byte[] packet      = BuildPacket((byte)0x3e, BitConverter.GetBytes(clientToken), Bsha1.DoubleHash(clientToken, m_owner.ServerToken, "password"), System.Text.Encoding.ASCII.GetBytes(m_owner.Realm), zero);

                byte[] temp = System.Text.Encoding.ASCII.GetBytes(m_owner.Realm);

                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("\tSize of realm string: {0}", temp.Length);

                    Console.WriteLine("\tWriting to Stream: ");
                    for (int i = 0; i < packet.Length; i++)
                    {
                        if (i % 8 == 0 && i != 0)
                        {
                            Console.Write(" ");
                        }
                        if (i % 16 == 0 && i != 0)
                        {
                            Console.WriteLine("");
                        }
                        Console.Write("{0:X2} ", packet[i]);
                    }
                    Console.WriteLine("");
                }
                m_stream.Write(packet, 0, packet.Length);
            }
        }
Esempio n. 3
0
        public static bool GetD2KeyHash(string cdkey, ref uint clientToken, uint serverToken, ref List <byte> output, ref List <byte> publicValue)
        {
            ulong checksum = 0;
            ulong n, n2, v, v2;
            char  c1, c2, c;

            String manipulatedKey = cdkey;

            for (int i = 0; i < cdkey.Length; i += 2)
            {
                char[] tmpBuffer = manipulatedKey.ToCharArray();
                c1 = (char)AlphaMap[cdkey[i]];
                n  = (ulong)c1 * 3;
                c2 = (char)AlphaMap[cdkey[i + 1]];
                n  = (ulong)c2 + 8 * n;

                if (n >= 0x100)
                {
                    n -= 0x100;
                    ulong temp = (ulong)1 << (i >> 1);
                    checksum |= temp;
                }
                n2               = n;
                n2             >>= 4;
                tmpBuffer[i]     = ConvertToHexDigit(n2);
                tmpBuffer[i + 1] = ConvertToHexDigit(n);

                manipulatedKey = new string(tmpBuffer);
            }

            v = 3;

            for (int i = 0; i < 16; i++)
            {
                n  = ConvertFromHexDigit(manipulatedKey[i]);
                n2 = v * 2;
                n ^= n2;
                v += n;
            }

            v &= 0xFF;
            if (v != checksum)
            {
                return(false);
            }

            for (int i = 15; i >= 0; i--)
            {
                c = manipulatedKey[i];
                if (i > 8)
                {
                    n = (ulong)i - 9;
                }
                else
                {
                    n = 0xF - (ulong)(8 - i);
                }
                n &= 0xF;

                c2 = manipulatedKey[(int)n];
                char[] tmpBuffer = manipulatedKey.ToCharArray();
                tmpBuffer[i]   = c2;
                tmpBuffer[n]   = c;
                manipulatedKey = new string(tmpBuffer);
            }

            v2 = 0x13AC9741;

            for (int i = 15; i >= 0; i--)
            {
                c = char.ToUpper(manipulatedKey[i]);
                char[] tmpBuffer = manipulatedKey.ToCharArray();
                tmpBuffer[i] = c;


                if (c <= '7')
                {
                    v            = v2;
                    c2           = (char)(v & 0xFF);
                    c2          &= (char)7;
                    c2          ^= c;
                    v          >>= 3;
                    tmpBuffer[i] = c2;
                    v2           = v;
                }
                else if (c < 'A')
                {
                    c2           = (char)i;
                    c2          &= (char)1;
                    c2          ^= c;
                    tmpBuffer[i] = c2;
                }
                manipulatedKey = new string(tmpBuffer);
            }

            string hexString = manipulatedKey.Substring(2, 6);
            UInt32 num       = UInt32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);

            publicValue = new List <byte>(BitConverter.GetBytes(num));

            List <byte> hashData = new List <byte>(BitConverter.GetBytes(clientToken));

            hashData.AddRange(BitConverter.GetBytes(serverToken));


            hashData.AddRange(BitConverter.GetBytes(UInt32.Parse(manipulatedKey.Substring(0, 2), System.Globalization.NumberStyles.HexNumber)));

            hashData.AddRange(BitConverter.GetBytes(num));
            hashData.AddRange(BitConverter.GetBytes((int)0));
            hashData.AddRange(BitConverter.GetBytes(UInt32.Parse(manipulatedKey.Substring(8, 8), System.Globalization.NumberStyles.HexNumber)));

            output = Bsha1.GetHash(hashData);

            return(true);
        }