예제 #1
0
        public void Save(PacketInfo packet)
        {
            if (!Exists("cfg/comments"))
            {
                CreateDirectory("cfg/comments");
            }

            var inc = packet.Destination == Client;
            var isl = (inc ? packet.Source : packet.Destination) == Login;
            var isw = (inc ? packet.Source : packet.Destination) == World;
            var isc = (inc ? packet.Source : packet.Destination) == Chat;
            var isa = (inc ? packet.Source : packet.Destination) == Auction;

            var file = $"cfg/comments/{packet.Opcode}.{(inc ? 'i' : 'o')}.{(isl ? 'l' : isw ? 'w' : isc ? 'c' : 'a')}.op";

            var w = new StreamWriter(file);

            if (inc)
            {
                w.Write(isl ? IncomingL[packet.Opcode] : isw ? IncomingW[packet.Opcode] : isc ? IncomingC[packet.Opcode] : IncomingA[packet.Opcode]);
            }
            else
            {
                w.Write(isl ? OutgoingL[packet.Opcode] : isw ? OutgoingW[packet.Opcode] : isc ? OutgoingC[packet.Opcode] : OutgoingA[packet.Opcode]);
            }

            w.Flush();
            w.Close();
            w.Dispose();
        }
예제 #2
0
        public FormColours()
        {
            InitializeComponent();

            Pairs = new Dictionary <Key, Val>(Colours.I.Pairs);
            var data = new PacketInfo[8];

            for (int i = 0; i < 8; i++)
            {
                data[i]             = new PacketInfo(new byte[] { });
                data[i].Time        = DateTime.Now;
                data[i].Length      = 42;
                data[i].Source      = (i < 4) ? Client : (Daemon)(i - 3);
                data[i].Destination = (i < 4) ? (Daemon)(i + 1) : Client;
                data[i].Opcode      = 1337;
            }

            olvPreview.SetObjects(data);

            SetComboColours(cpC2LFG, cpC2LBG, Client, Login);
            SetComboColours(cpC2WFG, cpC2WBG, Client, World);
            SetComboColours(cpC2CHFG, cpC2CHBG, Client, Chat);
            SetComboColours(cpC2AFG, cpC2ABG, Client, Auction);
            SetComboColours(cpL2CFG, cpL2CBG, Login, Client);
            SetComboColours(cpW2CFG, cpW2CBG, World, Client);
            SetComboColours(cpCH2CFG, cpCH2CBG, Chat, Client);
            SetComboColours(cpA2CFG, cpA2CBG, Auction, Client);
        }
예제 #3
0
파일: FormMain.cs 프로젝트: allocenx/Ostara
 void AddPacket(PacketInfo p)
 {
     if (!Ignores.I.Values.Contains(p.Opcode))
     {
         flvPackets.AddObject(p);
     }
 }
예제 #4
0
파일: FormMain.cs 프로젝트: allocenx/Ostara
        ResultCollection ParsePacketData(PacketInfo packet)
        {
            var filename = $"cfg\\structs\\{GetSchemaFilename(packet)}";

            if (!File.Exists(filename))
            {
                return(null);
            }

            ResultCollection r = null;

            try {
                r = Schema.FromFile(filename).Parse(packet.Data);
            } catch (Exception e) {
#if DEBUG
                Console.WriteLine(e.Message);
#else
                MessageBox.Show(e.Message);
#endif
            }

            return(r);
        }
예제 #5
0
        public static List <PacketInfo> Load(string file)
        {
            var result = new List <PacketInfo>();

            var f = File.OpenRead(file);
            var r = new BinaryReader(f, Encoding.ASCII);

            while (r.PeekChar() != -1)
            {
                var length = r.ReadInt32();
                var data   = r.ReadBytes(length);
                var p      = new PacketInfo(data);
                p.Opcode      = r.ReadUInt16();
                p.Time        = DateTime.FromFileTimeUtc(r.ReadInt64());
                p.Source      = (PacketInfo.Daemon)r.ReadByte();
                p.Destination = (PacketInfo.Daemon)r.ReadByte();

                result.Add(p);
            }

            r.Dispose();

            return(result);
        }
예제 #6
0
파일: FormMain.cs 프로젝트: allocenx/Ostara
        string GetSchemaFilename(PacketInfo packet)
        {
            PacketInfo.Daemon daemon;
            var opcode = packet.Opcode;

            if (packet.IsIncoming)
            {
                daemon = packet.Source;
            }
            else
            {
                daemon = packet.Destination;
            }

            var dchar =
                (daemon == PacketInfo.Daemon.Auction) ? 'a' :
                (daemon == PacketInfo.Daemon.Chat) ? 'c' :
                (daemon == PacketInfo.Daemon.Login) ? 'l' :
                'w';

            var ichar = (packet.IsIncoming) ? 'i' : 'o';

            return($"{opcode}.{ichar}.{dchar}.bee");
        }
예제 #7
0
파일: FormMain.cs 프로젝트: allocenx/Ostara
        void ProcessPacket(byte[] data, bool inc, PacketInfo.Daemon daemon, ushort port)
        {
            int s;

            byte[] tmp;

            if (inc)
            {
                switch (daemon)
                {
                case PacketInfo.Daemon.Login:
                    if (partil == null)
                    {
                        break;
                    }

                    s   = partil.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partil, 0, tmp, 0, partil.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partil.Length, data.Length);
                    data   = tmp;
                    partil = null;
                    break;

                case PacketInfo.Daemon.World:
                    if (partiw == null)
                    {
                        break;
                    }

                    s   = partiw.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partiw, 0, tmp, 0, partiw.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partiw.Length, data.Length);
                    data   = tmp;
                    partiw = null;
                    break;

                case PacketInfo.Daemon.Chat:
                    if (partic == null)
                    {
                        break;
                    }

                    s   = partic.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partic, 0, tmp, 0, partic.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partic.Length, data.Length);
                    data   = tmp;
                    partic = null;
                    break;

                case PacketInfo.Daemon.Auction:
                    if (partia == null)
                    {
                        break;
                    }

                    s   = partia.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partia, 0, tmp, 0, partia.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partia.Length, data.Length);
                    data   = tmp;
                    partia = null;
                    break;
                }
            }
            else
            {
                switch (daemon)
                {
                case PacketInfo.Daemon.Login:
                    if (partol == null)
                    {
                        break;
                    }

                    s   = partol.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partol, 0, tmp, 0, partol.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partol.Length, data.Length);
                    data   = tmp;
                    partol = null;
                    break;

                case PacketInfo.Daemon.World:
                    if (partow == null)
                    {
                        break;
                    }

                    s   = partow.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partow, 0, tmp, 0, partow.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partow.Length, data.Length);
                    data   = tmp;
                    partow = null;
                    break;

                case PacketInfo.Daemon.Chat:
                    if (partoc == null)
                    {
                        break;
                    }

                    s   = partoc.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partoc, 0, tmp, 0, partoc.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partoc.Length, data.Length);
                    data   = tmp;
                    partoc = null;
                    break;

                case PacketInfo.Daemon.Auction:
                    if (partoa == null)
                    {
                        break;
                    }

                    s   = partoa.Length + data.Length;
                    tmp = new byte[s];
                    Array.ConstrainedCopy(partoa, 0, tmp, 0, partoa.Length);
                    Array.ConstrainedCopy(data, 0, tmp, partoa.Length, data.Length);
                    data   = tmp;
                    partoa = null;
                    break;
                }
            }

            var size = (inc)
                                ? serverCrypt[port].GetPacketSize(data)
                                : clientCrypt[port].GetPacketSize(data);

            if (size > data.Length)
            {
#if DEBUG
                //Console.WriteLine("Found partial packet. Storing...");
#endif

                if (inc)
                {
                    if (daemon == PacketInfo.Daemon.Login)
                    {
                        partil = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partil, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.World)
                    {
                        partiw = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partiw, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.Chat)
                    {
                        partic = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partic, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.Auction)
                    {
                        partia = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partia, 0, data.Length);
                    }
                }
                else
                {
                    if (daemon == PacketInfo.Daemon.Login)
                    {
                        partol = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partol, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.World)
                    {
                        partow = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partow, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.Chat)
                    {
                        partoc = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partoc, 0, data.Length);
                    }
                    else if (daemon == PacketInfo.Daemon.Auction)
                    {
                        partoa = new byte[data.Length];
                        Array.ConstrainedCopy(data, 0, partoa, 0, data.Length);
                    }
                }

                return;
            }

            if (size < data.Length)
            {
                // Process the first subpacket
                var sub = new byte[size];
                Array.ConstrainedCopy(data, 0, sub, 0, size);
                ProcessPacket(sub, inc, daemon, port);

                // Process the rest of the data.  May contain further subpackets, or a partial packet.  We don't care
                sub = new byte[data.Length - size];
                Array.ConstrainedCopy(data, size, sub, 0, data.Length - size);
                ProcessPacket(sub, inc, daemon, port);

                return;
            }

            if (inc)
            {
                serverCrypt[port].Decrypt(data);
            }
            else
            {
                clientCrypt[port].Decrypt(data);
            }

            var ppkt = new PacketInfo(data, DateTime.Now, inc, daemon);

            if (inc && ((ppkt.Opcode == 101 && daemon == PacketInfo.Daemon.Login) ||
                        (ppkt.Opcode == 140 && daemon == PacketInfo.Daemon.World) ||
                        (ppkt.Opcode == 401 && daemon == PacketInfo.Daemon.Chat) ||
                        (ppkt.Opcode == 101 && daemon == PacketInfo.Daemon.Auction)))
            {
                unsafe
                {
                    fixed(byte *pp = data)
                    {
                        var key  = *(uint *)&pp[6];
                        var step = *(ushort *)&pp[16];

                        serverCrypt[port].ChangeKey(key, step);
                        clientCrypt[port].ChangeKey(key, step);
                    }
                }
            }

            if (!paused)
            {
                if (flvPackets.InvokeRequired)
                {
                    this.Invoke(new AddPacketDel(AddPacket), new object[] { ppkt });
                }
                else
                {
                    AddPacket(ppkt);
                }
            }
        }