예제 #1
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     try
     {
         string s = richTextBox1.Text.Trim();
         while (s.Contains(" "))
         {
             s = s.Replace(" ", "");
         }
         if ((s.Length % 2) != 0)
         {
             return;
         }
         byte[] data = ToBuff(s);
         data = Helper.Decrypt("CD&ML", data);
         MemoryStream m = new MemoryStream();
         m.Write(data, 1, data.Length - 1);
         data = Helper.Decompress(m.ToArray());
         StringBuilder sb = new StringBuilder();
         foreach (byte b in data)
         {
             sb.Append(b.ToString("X2"));
         }
         richTextBox2.Text = sb.ToString();
     }
     catch { richTextBox2.Text = "ERROR"; }
 }
예제 #2
0
        public QPacket(byte[] data)
        {
            MemoryStream m = new MemoryStream(data);

            m_oSourceVPort      = new VPort(Helper.ReadU8(m));
            m_oDestinationVPort = new VPort(Helper.ReadU8(m));
            m_byPacketTypeFlags = Helper.ReadU8(m);
            type  = (PACKETTYPE)(m_byPacketTypeFlags & 0x7);
            flags = new List <PACKETFLAG>();
            ExtractFlags();
            m_bySessionID = Helper.ReadU8(m);
            m_uiSignature = Helper.ReadU32(m);
            uiSeqId       = Helper.ReadU16(m);
            if (type == PACKETTYPE.SYN || type == PACKETTYPE.CONNECT)
            {
                m_uiConnectionSignature = Helper.ReadU32(m);
            }
            if (type == PACKETTYPE.DATA)
            {
                m_byPartNumber = Helper.ReadU8(m);
            }
            if (flags.Contains(PACKETFLAG.FLAG_HAS_SIZE))
            {
                payloadSize = Helper.ReadU16(m);
            }
            MemoryStream pl = new MemoryStream();

            for (int i = (int)m.Position; i < m.Length - 1; i++)
            {
                pl.WriteByte(Helper.ReadU8(m));
            }
            payload     = pl.ToArray();
            payloadSize = (ushort)payload.Length;
            if (payload != null && payload.Length > 0)
            {
                payload         = Helper.Decrypt(Global.keyDATA, payload);
                usesCompression = payload[0] != 0;
                if (usesCompression)
                {
                    MemoryStream m2 = new MemoryStream();
                    m2.Write(payload, 1, payload.Length - 1);
                    payload = Helper.Decompress(m2.ToArray());
                }
                else
                {
                    MemoryStream m2 = new MemoryStream();
                    m2.Write(payload, 1, payload.Length - 1);
                    payload = m2.ToArray();
                }
                payloadSize = (ushort)payload.Length;
            }
            checkSum = Helper.ReadU8(m);
        }
예제 #3
0
        private static byte[] MakeConnectPayload(ClientInfo client, QPacket p)
        {
            MemoryStream m    = new MemoryStream(p.payload);
            uint         size = Helper.ReadU32(m);

            byte[] buff = new byte[size];
            m.Read(buff, 0, (int)size);
            size = Helper.ReadU32(m) - 16;
            buff = new byte[size];
            m.Read(buff, 0, (int)size);
            buff = Helper.Decrypt(client.sessionKey, buff);
            m    = new MemoryStream(buff);
            Helper.ReadU32(m);
            Helper.ReadU32(m);
            uint responseCode = Helper.ReadU32(m);

            Log.WriteLine("Got response code 0x" + responseCode.ToString("X8"));
            m = new MemoryStream();
            Helper.WriteU32(m, 4);
            Helper.WriteU32(m, responseCode + 1);
            return(m.ToArray());
        }
예제 #4
0
        public static void ProcessCONNECT(QPacket p)
        {
            ClientInfo client = GetClientByIDrecv(p.m_uiSignature);

            if (client == null)
            {
                Log.WriteLine("[UDP] Cand find client for id : 0x" + p.m_uiSignature.ToString("X8"));
                return;
            }
            client.IDsend = p.m_uiConnectionSignature;
            QPacket reply = new QPacket();

            if (p.payload != null && p.payload.Length > 1)
            {
                using (var mem = new MemoryStream(p.payload))
                {
                    var ticketLen = Helper.ReadU32(mem);
                    var ticket    = new byte[ticketLen];
                    for (int i = 0; i < ticketLen; i++)
                    {
                        ticket[i] = Helper.ReadU8(mem);
                    }
                    var requestDataLen = Helper.ReadU32(mem);
                    var requestData    = new byte[requestDataLen];
                    for (int i = 0; i < requestDataLen; i++)
                    {
                        requestData[i] = Helper.ReadU8(mem);
                    }
                    var           sessionKey           = new byte[] { 0x9C, 0xB0, 0x1D, 0x7A, 0x2C, 0x5A, 0x6C, 0x5B, 0xED, 0x12, 0x68, 0x45, 0x69, 0xAE, 0x09, 0x0D };
                    var           decryptedRequestData = Helper.Decrypt(sessionKey, requestData);
                    StringBuilder sb = new StringBuilder();
                    foreach (byte b in decryptedRequestData)
                    {
                        sb.Append(b.ToString("X2"));
                    }
                    uint rcv;
                    using (var d = new MemoryStream(decryptedRequestData))
                    {
                        var uPid = Helper.ReadU32(d);
                        var cid  = Helper.ReadU32(d);
                        rcv = Helper.ReadU32(d);
                    }
                    using (var r = new MemoryStream())
                    {
                        reply.m_oSourceVPort      = p.m_oDestinationVPort;
                        reply.m_oDestinationVPort = p.m_oSourceVPort;
                        reply.flags = new List <QPacket.PACKETFLAG>()
                        {
                            QPacket.PACKETFLAG.FLAG_ACK, QPacket.PACKETFLAG.FLAG_HAS_SIZE
                        };
                        reply.type                    = QPacket.PACKETTYPE.CONNECT;
                        reply.m_bySessionID           = p.m_bySessionID;
                        reply.m_uiSignature           = client.IDsend;
                        reply.uiSeqId                 = p.uiSeqId;
                        reply.m_uiConnectionSignature = client.IDrecv;
                        Helper.WriteU32(r, 4);
                        Helper.WriteU32(r, rcv + 1);
                        reply.payload = r.ToArray();
                    }
                }
            }
            else
            {
                reply.m_oSourceVPort      = p.m_oDestinationVPort;
                reply.m_oDestinationVPort = p.m_oSourceVPort;
                reply.flags = new List <QPacket.PACKETFLAG>()
                {
                    QPacket.PACKETFLAG.FLAG_ACK
                };
                reply.type                    = QPacket.PACKETTYPE.CONNECT;
                reply.m_bySessionID           = p.m_bySessionID;
                reply.m_uiSignature           = client.IDsend;
                reply.uiSeqId                 = p.uiSeqId;
                reply.m_uiConnectionSignature = client.IDrecv;
                reply.payload                 = new byte[0];
            }
            Send(reply, client);
        }