Пример #1
0
        internal override PacketWriter GetWriter()
        {
            PacketWriter writer = new PacketWriter((ushort)(1 + 103));

            writer.Write(PacketID);

            writer.Write(pattern1);
            writer.Write(pattern2);
            writer.Write(pattern3);
            writer.WriteStringFixed(CharName, 30);
            writer.Write(unknown0);
            writer.Write((int)ClientFlags);
            writer.Write(unknown1);
            writer.Write(LoginCount);
            writer.Write((byte)Profession);
            writer.Skip(15); //unknown2[15];

            writer.Write(RaceAndGender.ToByte());

            writer.Write(Stats.Strength);
            writer.Write(Stats.Dexterity);
            writer.Write(Stats.Intelligence);

            writer.Write(StartSkills.Length > 0 ? (byte)StartSkills[0].Skill : (byte)0);
            writer.Write(StartSkills.Length > 0 ? (byte)StartSkills[0].Value : (byte)0);
            writer.Write(StartSkills.Length > 1 ? (byte)StartSkills[1].Skill : (byte)0);
            writer.Write(StartSkills.Length > 1 ? (byte)StartSkills[1].Value : (byte)0);
            writer.Write(StartSkills.Length > 2 ? (byte)StartSkills[2].Skill : (byte)0);
            writer.Write(StartSkills.Length > 2 ? (byte)StartSkills[2].Value : (byte)0);

            writer.Write((ushort)SkinColor);
            writer.Write((ushort)HairStyle);
            writer.Write((ushort)HairColor);
            writer.Write((ushort)FacialHairStyle);
            writer.Write((ushort)FacialHairColor);

            writer.Write(StartLocationIndex);
            writer.Write(unknown3);
            writer.Write(CharSlotNum);

            byte[] addressbytes = ClientIP.GetAddressBytes();
            writer.Write(addressbytes[0]);
            writer.Write(addressbytes[1]);
            writer.Write(addressbytes[2]);
            writer.Write(addressbytes[3]);

            writer.Write((ushort)ShirtColor);
            writer.Write((ushort)PantsColor);

            return(writer);
        }
Пример #2
0
        public void MakeKeepAlivePacket(out byte[] data, int type, int ran)
        {
            if (type == 0)
            {
                data    = new byte[38];
                data[0] = 0xff;
                Buffer.BlockCopy(md5a, 0, data, 1, 16);
                Buffer.BlockCopy(tail, 0, data, 20, 16);
                data[36] = (byte)(ran >> 8);
                data[37] = (byte)(ran & 0xFFFFFFFF);
            }
            else
            {
                data    = new byte[40];
                data[0] = 0x07;
                data[1] = 0x00;
                data[2] = 0x28;
                data[4] = 0x0b;
                data[5] = (byte)(2 * type - 1);
                // keepaliveVer
                data[6]  = 0xdc;
                data[7]  = 0x02;
                data[9]  = (byte)(ran >> 8);
                data[10] = (byte)(ran);
                Buffer.BlockCopy(flux, 0, data, 16, 4);
                if (type == 2)
                {
                    Buffer.BlockCopy(ClientIP.GetAddressBytes(), 0, data, 28, 4);
                }
            }
#if DEBUG
            OnLog.Invoke("alive", data, true);
#else
            OnLog.Invoke("alive", "Sending keep-alive-" + type.ToString() + " packet...", false);
#endif
        }
Пример #3
0
 public void WriteTo(Stream writer)
 {
     writer.WriteByte((byte)Operation);
     writer.WriteByte((byte)HardwareType);
     writer.WriteByte((byte)HardwareAddressLength);
     writer.WriteByte((byte)Hops);
     BinaryHelper.Write(writer, TransactionId);
     BinaryHelper.Write(writer, SecondElapsed);
     if (Broadcast)
     {
         BinaryHelper.Write(writer, 0x8000);
     }
     else
     {
         BinaryHelper.Write(writer, (uint)0);
     }
     BinaryHelper.Write(writer, ClientIP.GetAddressBytes());
     BinaryHelper.Write(writer, Your.GetAddressBytes());
     BinaryHelper.Write(writer, NextIP.GetAddressBytes());
     BinaryHelper.Write(writer, RelayAgentIP.GetAddressBytes());
     BinaryHelper.Write(writer, ClientHardwareAddress);
     BinaryHelper.Write(writer, ServerHostName);
     BinaryHelper.Write(writer, BootFileName);
     if (IsDhcpMessage) //Magic cookie
     {
         BinaryHelper.Write(writer, new byte[] { 63, 82, 53, 63 });
     }
     if (Options != null && Options.Count > 0)
     {
         foreach (Option option in Options)
         {
             writer.WriteByte((byte)option.Type);
             option.WriteTo(writer);
         }
     }
 }
Пример #4
0
        public byte[] MakeLoginPacket(byte[] salt, out byte[] data, out int len)
        {
            int pwlen = Password.Length;

            byte[] mac = MAC.GetAddressBytes();
            byte[] md5_src;
            data = new byte[400];

            int i = 0;

            // Begin
            data[i++] = 0x03;
            data[i++] = 0x01;
            data[i++] = 0x00;
            data[i++] = (byte)(Username.Length + 20);

            // MD5 A
            md5_src    = new byte[6 + pwlen];
            md5_src[0] = 3;
            md5_src[1] = 1;
            Buffer.BlockCopy(salt, 0, md5_src, 2, 4);
            Buffer.BlockCopy(Encoding.Default.GetBytes(Password), 0, md5_src, 6, pwlen);
            md5a = MD5(md5_src);
            Buffer.BlockCopy(md5a, 0, data, 4, 16);
            i += 16;

            // Username
            Buffer.BlockCopy(Encoding.Default.GetBytes(Username), 0, data, i, Username.Length);
            i += Username.Length > 36 ? Username.Length : 36;

            // CONTROLCHECKSTATUS ADAPTERNUM
            data[i++] = 0x20;
            data[i++] = 0x03;

            /* (data[4:10].encode('hex'),16)^mac */
            Buffer.BlockCopy(md5a, 0, data, i, 6);
            for (int j = 0; j < 6; j++)
            {
                data[i + j] ^= mac[j];
            }
            i += 6;

            // MD5 B
            md5_src    = new byte[9 + pwlen];
            md5_src[0] = 1;
            Buffer.BlockCopy(Encoding.Default.GetBytes(Password), 0, md5_src, 1, pwlen);
            Buffer.BlockCopy(salt, 0, md5_src, 1 + pwlen, 4);
            Buffer.BlockCopy(MD5(md5_src), 0, data, i, 16);
            i += 16;

            // Ip number, 1, 2, 3, 4
            data[i++] = 0x01;
            Buffer.BlockCopy(ClientIP.GetAddressBytes(), 0, data, i, 4);
            i += 16;

            // MD5 C
            md5_src = new byte[i + 4];
            Buffer.BlockCopy(data, 0, md5_src, 0, i);
            md5_src[i + 0] = 0x14;
            md5_src[i + 1] = 0x00;
            md5_src[i + 2] = 0x07;
            md5_src[i + 3] = 0x0b;
            Buffer.BlockCopy(MD5(md5_src), 0, data, i, 8);
            i += 8;

            // IPDOG(0x01) 0x00*4
            data[i++] = 0x01;
            i        += 4;

            // Host Name
            md5_src = Encoding.Default.GetBytes(HostName);
            Buffer.BlockCopy(md5_src, 0, data, i, md5_src.Length > 32 ? 32 : md5_src.Length);
            i += 32;

            // primary dns
            Buffer.BlockCopy(PrimaryDNS.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // DHCP Server
            Buffer.BlockCopy(DefaultDHCP.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // secondary dns
            Buffer.BlockCopy(SecondaryDNS.GetAddressBytes(), 0, data, i, 4);
            i += 4;

            // delimeter
            i += 8;

            // unknown os_major os_minor OS_build os_unknown
            data[i++] = 0x94;
            i        += 3;
            data[i++] = 0x06;
            i        += 3;
            data[i++] = 0x02;
            i        += 3;
            data[i++] = 0xf0;
            data[i++] = 0x23;
            i        += 2;
            data[i++] = 0x02;
            i        += 3;

            // unknown string
            data[i++] = 0x44;
            data[i++] = 0x72;
            data[i++] = 0x43;
            data[i++] = 0x4f;
            data[i++] = 0x4d;
            i++;
            data[i++] = 0xcf;
            data[i++] = 0x07;
            data[i++] = 0x68;
            i        += 55;

            // unknown string 2
            data[i++] = 0x33;
            data[i++] = 0x64;
            data[i++] = 0x63;
            data[i++] = 0x37;
            data[i++] = 0x39;
            data[i++] = 0x66;
            data[i++] = 0x35;
            data[i++] = 0x32;
            data[i++] = 0x31;
            data[i++] = 0x32;
            data[i++] = 0x65;
            data[i++] = 0x38;
            data[i++] = 0x31;
            data[i++] = 0x37;
            data[i++] = 0x30;
            data[i++] = 0x61;
            data[i++] = 0x63;
            data[i++] = 0x66;
            data[i++] = 0x61;
            data[i++] = 0x39;
            data[i++] = 0x65;
            data[i++] = 0x63;
            data[i++] = 0x39;
            data[i++] = 0x35;
            data[i++] = 0x66;
            data[i++] = 0x31;
            data[i++] = 0x64;
            data[i++] = 0x37;
            data[i++] = 0x34;
            data[i++] = 0x39;
            data[i++] = 0x31;
            data[i++] = 0x36;
            data[i++] = 0x35;
            data[i++] = 0x34;
            data[i++] = 0x32;
            data[i++] = 0x62;
            data[i++] = 0x65;
            data[i++] = 0x37;
            data[i++] = 0x62;
            data[i++] = 0x31;
            i        += 24;

            // auth version
            data[i++] = 0x68;
            data[i++] = 0x00;

            data[i++] = 0x00;
            data[i++] = (byte)(pwlen);

            // ror password
            for (int k = 0, x; k < pwlen; k++)
            {
                x         = md5a[k] ^ Password[k];
                data[i++] = (byte)(((x << 3) & 0xFF) + (x >> 5));
            }

            data[i++] = 0x02;
            data[i++] = 0x0c;

            // checksum point
            int check_point = i;

            data[i++] = 0x01;
            data[i++] = 0x26;
            data[i++] = 0x07;
            data[i++] = 0x11;

            // 0x00 0x00 mac
            i += 2;
            Buffer.BlockCopy(mac, 0, data, i, 6);
            i += 6;

            // checksum
            ulong sum   = 1234;
            ulong check = 0;

            for (int k = 0; k < i; k += 4)
            {
                check = 0;
                for (int j = 0; j < 4; j++)
                {
                    check = (check << 2) + data[k + j];
                }
                sum ^= check;
            }
            sum = (1968 * sum) & 0xFFFFFFFF;
            for (int j = 0; j < 4; j++)
            {
                data[check_point + j] = (byte)(sum >> (j * 8) & 0x000000FF);
            }


            if (pwlen / 4 != 4)
            {
                i += (pwlen / 4);
            }
            i        += 4;
            data[i++] = 0x60;
            data[i++] = 0xa2;
            i        += 28;
            len       = i;

#if DEBUG
            OnLog.Invoke("mkpkt", data, true);
#else
            OnLog.Invoke("login", "Making login packet...", false);
#endif
            return(data);
        }