Esempio n. 1
0
        public static void Send(string source, QPacket p, IPEndPoint ep, UdpClient listener)
        {
            byte[]        data = p.toBuffer();
            StringBuilder sb   = new StringBuilder();

            foreach (byte b in data)
            {
                sb.Append(b.ToString("X2") + " ");
            }
            Log.WriteLine(5, "[" + source + "] send : " + p.ToStringShort());
            Log.WriteLine(10, "[" + source + "] send : " + sb.ToString());
            Log.WriteLine(10, "[" + source + "] send : " + p.ToStringDetailed());
            listener.Send(data, data.Length, ep);
            Log.LogPacket(true, data);
        }
Esempio n. 2
0
        public static void Send(UdpClient udp, QPacket p, ClientInfo client)
        {
            byte[]        data = p.toBuffer();
            StringBuilder sb   = new StringBuilder();

            foreach (byte b in data)
            {
                sb.Append(b.ToString("X2") + " ");
            }
            WriteLog(5, "send : " + p.ToStringShort());
            WriteLog(10, "send : " + sb.ToString());
            WriteLog(10, "send : " + p.ToStringDetailed());
            udp.Send(data, data.Length, client.ep);
            Log.LogPacket(true, data);
        }
Esempio n. 3
0
        private static void SendACK(UdpClient udp, QPacket p, ClientInfo client)
        {
            QPacket np = new QPacket(p.toBuffer());

            np.flags = new List <QPacket.PACKETFLAG>()
            {
                QPacket.PACKETFLAG.FLAG_ACK
            };
            np.m_oSourceVPort      = p.m_oDestinationVPort;
            np.m_oDestinationVPort = p.m_oSourceVPort;
            np.m_uiSignature       = client.IDsend;
            np.payload             = new byte[0];
            np.payloadSize         = 0;
            WriteLog(10, "send ACK packet");
            Send(udp, np, client);
        }
Esempio n. 4
0
        private static void SendResponsePacket(UdpClient udp, QPacket p, RMCP rmc, ClientInfo client, RMCPResponse reply, bool useCompression, uint error)
        {
            MemoryStream m = new MemoryStream();

            if ((ushort)rmc.proto < 0x7F)
            {
                Helper.WriteU8(m, (byte)rmc.proto);
            }
            else
            {
                Helper.WriteU8(m, 0x7F);
                Helper.WriteU16(m, (ushort)rmc.proto);
            }
            byte[] buff;
            if (error == 0)
            {
                Helper.WriteU8(m, 0x1);
                Helper.WriteU32(m, rmc.callID);
                Helper.WriteU32(m, rmc.methodID | 0x8000);
                buff = reply.ToBuffer();
                m.Write(buff, 0, buff.Length);
            }
            else
            {
                Helper.WriteU8(m, 0);
                Helper.WriteU32(m, error);
                Helper.WriteU32(m, rmc.callID);
            }
            buff = m.ToArray();
            m    = new MemoryStream();
            Helper.WriteU32(m, (uint)buff.Length);
            m.Write(buff, 0, buff.Length);
            QPacket np = new QPacket(p.toBuffer());

            np.flags = new List <QPacket.PACKETFLAG>()
            {
                QPacket.PACKETFLAG.FLAG_NEED_ACK
            };
            np.m_oSourceVPort      = p.m_oDestinationVPort;
            np.m_oDestinationVPort = p.m_oSourceVPort;
            np.m_uiSignature       = client.IDsend;
            MakeAndSend(client, np, m.ToArray());
        }
Esempio n. 5
0
        public static string MakeDetailedPacketLog(byte[] data, bool isSinglePacket = false)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                QPacket qp = new QPacket(data);
                sb.AppendLine("##########################################################");
                sb.AppendLine(qp.ToStringDetailed());
                if (qp.type == QPacket.PACKETTYPE.DATA && qp.m_byPartNumber == 0)
                {
                    switch (qp.m_oSourceVPort.type)
                    {
                    case QPacket.STREAMTYPE.OldRVSec:
                        if (qp.flags.Contains(QPacket.PACKETFLAG.FLAG_ACK))
                        {
                            break;
                        }
                        sb.AppendLine("Trying to process RMC packet...");
                        try
                        {
                            MemoryStream m = new MemoryStream(qp.payload);
                            RMCP         p = new RMCP(qp);
                            m.Seek(p._afterProtocolOffset + 4, 0);
                            if (!p.isRequest)
                            {
                                m.ReadByte();
                            }
                            p.methodID = Helper.ReadU32(m);
                            sb.AppendLine("\tRMC Request  : " + p.isRequest);
                            sb.AppendLine("\tRMC Protocol : " + p.proto);
                            sb.AppendLine("\tRMC Method   : " + p.methodID.ToString("X"));
                            if (p.proto == RMCP.PROTOCOL.GlobalNotificationEventProtocol && p.methodID == 1)
                            {
                                sb.AppendLine("\t\tNotification :");
                                sb.AppendLine("\t\t\tSource".PadRight(20) + ": 0x" + Helper.ReadU32(m).ToString("X8"));
                                uint type = Helper.ReadU32(m);
                                sb.AppendLine("\t\t\tType".PadRight(20) + ": " + (type / 1000));
                                sb.AppendLine("\t\t\tSubType".PadRight(20) + ": " + (type % 1000));
                                sb.AppendLine("\t\t\tParam 1".PadRight(20) + ": 0x" + Helper.ReadU32(m).ToString("X8"));
                                sb.AppendLine("\t\t\tParam 2".PadRight(20) + ": 0x" + Helper.ReadU32(m).ToString("X8"));
                                sb.AppendLine("\t\t\tParam String".PadRight(20) + ": " + Helper.ReadString(m));
                                sb.AppendLine("\t\t\tParam 3".PadRight(20) + ": 0x" + Helper.ReadU32(m).ToString("X8"));
                            }
                            sb.AppendLine();
                        }
                        catch
                        {
                            sb.AppendLine("Error processing RMC packet");
                            sb.AppendLine();
                        }
                        break;

                    case QPacket.STREAMTYPE.DO:
                        if (qp.flags.Contains(QPacket.PACKETFLAG.FLAG_ACK))
                        {
                            break;
                        }
                        sb.AppendLine("Trying to unpack DO messages...");
                        try
                        {
                            MemoryStream m    = new MemoryStream(qp.payload);
                            uint         size = Helper.ReadU32(m);
                            byte[]       buff = new byte[size];
                            m.Read(buff, 0, (int)size);
                            DO.UnpackMessage(buff, 1, sb);
                            sb.AppendLine();
                        }
                        catch
                        {
                            sb.AppendLine("Error processing DO messages");
                            sb.AppendLine();
                        }
                        break;
                    }
                }
                int size2 = qp.toBuffer().Length;
                if (size2 == data.Length || isSinglePacket)
                {
                    break;
                }
                MemoryStream m2 = new MemoryStream(data);
                m2.Seek(size2, 0);
                size2 = (int)(m2.Length - m2.Position);
                if (size2 <= 8)
                {
                    break;
                }
                data = new byte[size2];
                m2.Write(data, 0, size2);
            }
            return(sb.ToString());
        }