Ejemplo n.º 1
0
 private void toolStripButton2_Click(object sender, EventArgs e)
 {
     try
     {
         string s = richTextBox2.Text.Trim();
         while (s.Contains(" "))
         {
             s = s.Replace(" ", "");
         }
         if ((s.Length % 2) != 0)
         {
             return;
         }
         byte[] data       = ToBuff(s);
         uint   sizeBefore = (uint)data.Length;
         byte[] buff       = Helper.Compress(data);
         byte   count      = (byte)(sizeBefore / buff.Length);
         if ((sizeBefore % buff.Length) != 0)
         {
             count++;
         }
         MemoryStream m = new MemoryStream();
         m.WriteByte(count);
         m.Write(buff, 0, buff.Length);
         data = Helper.Encrypt("CD&ML", m.ToArray());
         StringBuilder sb = new StringBuilder();
         foreach (byte b in data)
         {
             sb.Append(b.ToString("X2"));
         }
         richTextBox1.Text = sb.ToString();
     }
     catch { richTextBox1.Text = "ERROR"; }
 }
Ejemplo n.º 2
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)
            {
                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();
                    tmpPayload = Helper.Encrypt(Global.keyDATA, tmpPayload);
                }
                else
                {
                    MemoryStream m2 = new MemoryStream();
                    m2.WriteByte(0);
                    m2.Write(tmpPayload, 0, tmpPayload.Length);
                    tmpPayload = m2.ToArray();
                    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()));
        }