Example #1
0
        public void btnHello_Click(object sender, EventArgs e)
        {
            rtbPacket.Clear();
            rtbEncrypted.Clear();
            rtbDecrypted.Clear();
            List <byte> Packet = new List <byte>();

            Packet.AddInt(1);
            Packet.AddInt(11);
            Packet.AddInt(Config.MajorVersion);
            Packet.AddInt(Config.MinorVersion);
            Packet.AddInt(Config.BuildVersion);
            Packet.AddString(Config.ResourceHash);
            Packet.AddInt(2);
            Packet.AddInt(2);
            byte[] data = Packet.ToArray();
            //byte[] data = new byte[128];
            //MemoryStream stream = new MemoryStream(data);
            //using (var writer = new MessageWriter(stream))
            //{
            //    writer.Write(1);
            //    writer.Write(11);
            //    writer.Write(Config.MajorVersion);
            //    writer.Write(Config.MinorVersion);
            //    writer.Write(Config.BuildVersion);
            //    writer.Write(Config.ResourceHash);
            //    writer.Write(2);
            //    writer.Write(2);
            //}
            encrypted = Crypto.Encrypt(data, 10100, 1, keyPair);
            ReadData(data, 10100);
            Console.WriteLine(ByteArrayToHexString(encrypted));
            sck.Send(encrypted);
            Console.WriteLine(ByteArrayToHexString(data));
            Logger.Write(Encoding.UTF8.GetString(data), PacketInfos.GetPacketName(10100));
            byte[] serverHello = new byte[32768];
            int    received    = sck.Receive(serverHello);

            Array.Resize(ref serverHello, received);
            ushort id;

            using (var reader = new Reader(serverHello))
            {
                id = reader.ReadUInt16();
            }
            switch (id)
            {
            case 20100:
                ClientConfig.SessionKey = serverHello.Skip(11).Take(24).ToArray();
                tbSessionKey.Text       = BitConverter.ToString(ClientConfig.SessionKey).Replace("-", "");
                Console.WriteLine(tbSessionKey.Text);
                rtbPacket.Text = Encoding.UTF8.GetString(data);
                break;

            case 20103:
                ReadData(serverHello, id);
                break;

            default:
                Console.WriteLine($"Unknown response from server.\nID: {id}");
                break;
            }
        }
Example #2
0
        public void btnLogin_Click(object sender, EventArgs e)
        {
            rtbPacket.Clear();
            rtbEncrypted.Clear();
            rtbDecrypted.Clear();
            long id = 12885955392;
            //long id = 167521404572; //Noob
            //token = "dwnegp67n9f7dfhhaes6bs2pfftyrs4anxjjmjg4"; //Noob
            List <byte> Packet = new List <byte>();

            Packet.AddLong(id);
            Packet.AddString(token);
            Packet.AddVInt(Config.MajorVersion);
            Packet.AddVInt(Config.MinorVersion);
            Packet.AddVInt(Config.BuildVersion);
            Packet.AddString(Config.ResourceHash);
            Packet.AddString("");
            Packet.AddString("c0389670ea3b1978");
            Packet.AddString("");
            Packet.AddString("C8817D");
            Packet.AddString("aa3e6cf0-0162-43d3-8719-f3d3b00356b7");
            Packet.AddString("4.4.2");
            Packet.AddBool(true);
            Packet.AddString("");
            Packet.AddString("c0389670ea3b1978");
            Packet.AddString("en-US");
            Packet.AddBool(false);
            Packet.AddBool(false);
            Packet.AddString("");
            Packet.AddBool(false);
            Packet.AddString("");
            Packet.AddVInt(2);
            Packet.AddString("");
            Packet.AddString("");
            Packet.AddString("");
            Packet.AddString("");
            Packet.AddBool(false);
            byte[] data = Packet.ToArray();
            //byte[] data = new byte[4096];
            //MemoryStream stream = new MemoryStream(data);
            //using (var writer = new MessageWriter(stream))
            //{
            //    writer.Write(id);
            //    writer.Write(token);
            //    writer.Write(VInt.WritevInt(Config.MajorVersion));
            //    writer.Write(VInt.WritevInt(Config.MinorVersion));
            //    writer.Write(VInt.WritevInt(Config.BuildVersion));
            //    writer.Write(Config.ResourceHash);
            //    writer.Write("");
            //    writer.Write("c0389670ea3b1978");
            //    writer.Write("");
            //    writer.Write("C8817D");
            //    writer.Write("aa3e6cf0-0162-43d3-8719-f3d3b00356b7");
            //    writer.Write("4.4.2");
            //    writer.Write(true);
            //    writer.Write("");
            //    writer.Write("c0389670ea3b1978");
            //    writer.Write("en-US");
            //    writer.Write(false);
            //    writer.Write(false);
            //    writer.Write("");
            //    writer.Write(false);
            //    writer.Write("");
            //    writer.Write(VInt.WritevInt(2));
            //    writer.Write("");
            //    writer.Write("");
            //    writer.Write("");
            //    writer.Write("");
            //    writer.Write(false);
            //}
            Console.WriteLine($"Payload: \n{ByteArrayToHexString(data)}");
            encrypted = Crypto.Encrypt(data, 10101, 1, keyPair);
            //EnDecrypt.Decrypt(encrypted);
            //ReadData(data,10101);
            sck.Send(encrypted);
            Logger.Write(Encoding.UTF8.GetString(data), PacketInfos.GetPacketName(10101));
            rtbPacket.Text    = ByteArrayToHexString(data);
            rtbEncrypted.Text = ByteArrayToHexString(encrypted);
            byte[] loginResult = new byte[32768];
            int    received    = sck.Receive(loginResult);

            Array.Resize(ref loginResult, received);
            byte[] decrypted;
            using (var reader = new Reader(loginResult))
            {
                var Id = reader.ReadUInt16();
                switch (Id)
                {
                case 20104:
                    Console.WriteLine(Id);
                    Console.WriteLine(BitConverter.ToString(loginResult).Replace("-", ""));
                    decrypted = Crypto.Decrypt(loginResult, keyPair);
                    GetDefinition(Id, decrypted);
                    timer.Enabled      = true;
                    timer.Interval     = 10000;
                    timer.Elapsed     += TimerElapsed;
                    tickTimer.Enabled  = true;
                    tickTimer.Interval = 50;
                    tickTimer.Elapsed += CountTicks;
                    break;

                case 20103:
                    Console.WriteLine(Id);
                    decrypted = Crypto.Decrypt(loginResult, keyPair);
                    GetDefinition(Id, decrypted);
                    break;

                default:
                    Console.WriteLine($"Unknown response from server [{Id}].");
                    Console.WriteLine($"Payload: {BitConverter.ToString(loginResult).Replace("-","")}.");
                    break;
                }
            }
        }