Exemple #1
0
        public static Packet[] ReadAllPackets(byte[] data)
        {
            List <Packet> packets = new List <Packet>();

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    try
                    {
                        while (br.BaseStream.Position != br.BaseStream.Length)
                        {
                            Packet temp = new Packet();
                            temp.Size    = br.ReadInt16();
                            temp.pub_key = br.ReadByte();

                            byte[] content      = br.ReadBytes(temp.Size);
                            byte   pub_keyindex = XCRYPT.GetPubKeyIndex(temp.pub_key);
                            content   = XCRYPT.Decrypt(content, pub_keyindex, XCRYPT.ZoneServerPrivKey);
                            temp.body = content;
                            packets.Add(temp);
                        }
                        return(packets.ToArray());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
            return(packets.ToArray());
        }
Exemple #2
0
        public static void ZSMakePacketAndSend(Socket s, byte[] content)
        {
            short ContentLenght = (short)content.Length;
            byte  RandomPubKey  = XCRYPT.AddRandPubKey();


            using (MemoryStream stream = new MemoryStream())
            {
                int len = 0;
                using (BinaryWriter bw = new BinaryWriter(stream, Encoding.UTF8))
                {
                    bw.Write((short)ContentLenght);
                    bw.Write((byte)RandomPubKey);
                    bw.Write(XCRYPT.Encrypt(content, XCRYPT.GetPubKeyIndex(RandomPubKey), XCRYPT.ZoneServerPrivKey));
                    len = (int)bw.BaseStream.Length;
                }
                byte[] buffer = stream.GetBuffer();
                Array.Resize(ref buffer, len);
                ZoneServer.Conn.ZSend(s, buffer);
            }
        }
Exemple #3
0
        public ReadPacket(byte[] data, byte key)
        {
            try
            {
                buffer = data;
                using (MemoryStream ms = new MemoryStream(buffer))
                {
                    using (BinaryReader br = new BinaryReader(ms, Encoding.UTF8))
                    {
                        short PacketLen = br.ReadInt16();
                        byte  pubkey    = br.ReadByte();
                        Head.len    = PacketLen;
                        Head.pubkey = pubkey;

                        byte[] content = br.ReadBytes(PacketLen);

                        using (MemoryStream ms2 = new MemoryStream())
                        {
                            using (BinaryWriter bw = new BinaryWriter(ms2))
                            {
                                byte PubKeyIndex = XCRYPT.GetPubKeyIndex(pubkey);
                                bw.Write(XCRYPT.Decrypt(content, PubKeyIndex, key));
                            }
                            ms2.Flush();
                            body = ms2.GetBuffer();
                            Array.Resize(ref body, content.Length);
                        }
                    }
                }
                Initialized = true;
            }
            catch
            {
                Initialized = false;
                return;
            }
        }