コード例 #1
0
        public void DecryptServer()
        {
            Form1.UpdateBlinkingText("Stage Five Decoding");
            List <byte[]> packets = new List <byte[]>();
            int           k       = 0;
            int           t       = 0;
            int           lnk     = 0;

            byte[] d1 = ConvertDictionary(this.ServerConversation);
            while (t < d1.Length)
            {
                //Form1.WriteLine(string.Format("DEBUG: t = {0} and D1.Length = {1}.", t, d1.Length));
                lnk  = BitConverter.ToInt32(d1, t);
                lnk += 4;
                byte[] bx = new byte[lnk];
                Array.Copy(d1, t + 4, bx, 0, lnk);
                t += lnk + 4;
                if (k == 0)
                {
                    uc = new cryption(bx);
                    uc.decript(bx, 0x19);
                }
                else
                {
                    uc.data = bx;
                    uc.decript();
                }
                // Get the length -4
                Int32  length     = uc.data.Length - 4;
                byte[] p_len      = BitConverter.GetBytes(length);
                byte[] fullPacket = new byte[p_len.Length + uc.data.Length];
                Array.Copy(p_len, fullPacket, p_len.Length);
                Array.Copy(uc.data, 0, fullPacket, 4, uc.data.Length);

                // We have the decoded packets now, so we need to put them back in order
                // that way i can see how the client answers.
                packets.Add(fullPacket);
                WritePaket(fullPacket, PacketOrigin.Server);
                //rt_op.AppendText(FormatBytes(fullPacket));//.Text += FormatBytes(fullPacket);//(uc.data) + "\n";//ByteArrayToHexString(uc.data) + "\n";
                //rt_op.SelectionColor = Color.Red;
                //rt_op.AppendText(NiceHexOutput(fullPacket));
                k++;
            }
            //BuildServerDecodeDic(packets);
            Form1.UpdateBlinkingText("Completed");
            Form1.BlinkLabel(false);
        }
コード例 #2
0
        public void DecodePacket(byte[] packet, PacketOrigin origin)
        {
            int p_len = 0;
            int crc   = 0;

            if (origin == PacketOrigin.Client)
            {
                if (this.ClientPacketsParsed == 0)
                {
                    this.ClientKey = Tools.GlobalFunctions.GetKeyFromKnownPacketID(packet, 14);

                    byte[] toXor = Tools.GlobalFunctions.GetPortionsToXOR(packet, out p_len, out crc, true);
                    byte[] xored = Xor.decrypt(toXor, this.ClientKey);
                    byte[] len   = BitConverter.GetBytes(p_len);
                    byte[] full  = new byte[len.Length + toXor.Length + 8];
                    Array.Copy(len, full, len.Length);
                    Array.Copy(BitConverter.GetBytes(14), 0, full, 4, BitConverter.GetBytes(14).Length);
                    Array.Copy(xored, 0, full, 8, xored.Length);
                    WritePaket(full, PacketOrigin.Client);
                }
                else if (this.ClientKey != null)
                {
                    byte[] toXor = Tools.GlobalFunctions.GetPortionsToXOR(packet, out p_len, out crc);
                    byte[] len   = BitConverter.GetBytes(p_len);
                    byte[] xor   = Xor.decrypt(toXor, this.ClientKey);
                    byte[] full  = new byte[len.Length + toXor.Length + 4];
                    Array.Copy(len, full, len.Length);
                    Array.Copy(xor, 0, full, 4, xor.Length);
                    WritePaket(full, PacketOrigin.Client);
                    //WritePaket(packet, origin);
                }
                this.ClientPacketsParsed++;
            }
            else if (origin == PacketOrigin.Server)
            {
                if (this.ServerPacketsParsed == 1)
                {
                    byte[] p1 = new byte[32];
                    // Get the last 32 bytes
                    Array.Copy(packet, (packet.Length - 32), p1, 0, p1.Length);
                    // This is our server decode packet
                    //int k = 0;
                    int t   = 0;
                    int lnk = 0;
                    #region While
                    while (t < p1.Length)
                    {
                        lnk  = BitConverter.ToInt32(p1, t);
                        lnk += 4;
                        bx   = new byte[lnk];
                        Array.Copy(p1, t + 4, bx, 0, lnk);
                        t += lnk + 4;
                        //if (k == 0)
                        //{
                        this.uc = new cryption(bx);
                        uc.decript(bx, 0x19);
                        //}
                        //else
                        // {

                        // }
                        // Get the length -4
                        Int32  length     = uc.data.Length - 4;
                        byte[] p_len2     = BitConverter.GetBytes(length);
                        byte[] fullPacket = new byte[p_len2.Length + uc.data.Length];
                        Array.Copy(p_len2, fullPacket, p_len2.Length);
                        Array.Copy(uc.data, 0, fullPacket, 4, uc.data.Length);
                        WritePaket(fullPacket, PacketOrigin.Server);

                        //rt_op.AppendText(FormatBytes(fullPacket));//.Text += FormatBytes(fullPacket);//(uc.data) + "\n";//ByteArrayToHexString(uc.data) + "\n";
                        //rt_op.SelectionColor = Color.Red;
                        //rt_op.AppendText(NiceHexOutput(fullPacket));
                    }
                    #endregion
                }
                else if (this.ServerPacketsParsed >= 2)
                {
                    //this.uc.data = packet;
                    // remove first 4
                    byte[] data = new byte[packet.Length - 4];
                    Array.Copy(packet, 4, data, 0, data.Length);
                    //int pos = this.uc.data.Length;
                    //Array.Resize(ref this.uc.data, this.uc.data.Length + packet.Length);
                    //Array.Copy(packet, 0, this.uc.data, pos, packet.Length);
                    //this.uc.data = packet;
                    this.uc.decript(data);
                    //Form1.WriteLine(string.Format("Length of this packet divisible by 4 ? {0}", packet.Length % 4 == 0));
                    WritePaket(this.uc.data, PacketOrigin.Server);
                }
                this.ServerPacketsParsed++;
            }
        }