Beispiel #1
0
        public byte[] toBuffer()
        {
            MemoryStream m = new MemoryStream();

            Helper.WriteU8(m, m_oSourceVPort.toByte());
            Helper.WriteU8(m, m_oDestinationVPort.toByte());
            byte typeFlag = (byte)type;

            foreach (PACKETFLAG flag in flags)
            {
                typeFlag |= (byte)((byte)flag << 3);
            }
            Helper.WriteU8(m, typeFlag);
            Helper.WriteU8(m, m_bySessionID);
            Helper.WriteU32(m, m_uiSignature);
            Helper.WriteU16(m, uiSeqId);
            if (type == PACKETTYPE.SYN || type == PACKETTYPE.CONNECT)
            {
                Helper.WriteU32(m, m_uiConnectionSignature);
            }
            if (type == PACKETTYPE.DATA)
            {
                Helper.WriteU8(m, m_byPartNumber);
            }
            byte[] tmpPayload = payload;
            if (tmpPayload != null && tmpPayload.Length > 0 && type != PACKETTYPE.SYN && m_oSourceVPort.type != STREAMTYPE.NAT)
            {
                if (usesCompression)
                {
                    uint   sizeBefore = (uint)tmpPayload.Length;
                    byte[] buff       = Helper.Compress(tmpPayload);
                    byte   count      = (byte)(sizeBefore / buff.Length);
                    if ((sizeBefore % buff.Length) != 0)
                    {
                        count++;
                    }
                    MemoryStream m2 = new MemoryStream();
                    m2.WriteByte(count);
                    m2.Write(buff, 0, buff.Length);
                    tmpPayload = m2.ToArray();
                }
                else
                {
                    MemoryStream m2 = new MemoryStream();
                    m2.WriteByte(0);
                    m2.Write(tmpPayload, 0, tmpPayload.Length);
                    tmpPayload = m2.ToArray();
                }
                if (m_oSourceVPort.type == STREAMTYPE.OldRVSec)
                {
                    tmpPayload = Helper.Encrypt(Global.keyDATA, tmpPayload);
                }
            }
            if (flags.Contains(PACKETFLAG.FLAG_HAS_SIZE))
            {
                Helper.WriteU16(m, (ushort)tmpPayload.Length);
            }
            m.Write(tmpPayload, 0, tmpPayload.Length);
            return(AddCheckSum(m.ToArray()));
        }