Beispiel #1
0
        public static PacketParts ParsePacket(byte[] bytes)
        { //2014.09.15.
            /*if (CurrentUser.Keys[CurrentUser.KeyIndex] != null)
             *  bytes = Storage.Encrypt(bytes, CurrentUser.Keys[CurrentUser.KeyIndex]);
             * else
             *  bytes = Storage.Encrypt(bytes, "ihavenokeys");*/
            var ret = new PacketParts();

            ret.Response   = (bytes[0] == 0x01) ? true : false;
            ret.UpdateType = (UpdateType)bytes[1];
            int pos = 2; //2014.12.19.

            //ret.KeyVersion = BitConverter.ToInt32(bytes, 1 + 1);
            ret.KeyVersion = BitConverter.ToInt32(bytes, pos);
            pos           += sizeof(int);
            ret.Port       = BitConverter.ToInt32(bytes, pos);                //2014.12.19.
            pos           += sizeof(int);
            byte[] encryptedBytes = new byte[bytes.Length - pos];             //2014.12.22. - A hátralévő rész titkosított
            Array.Copy(bytes, pos, encryptedBytes, 0, encryptedBytes.Length); //2014.12.22.
            if (CurrentUser.Keys[CurrentUser.KeyIndex] != null)
            {
                bytes = Storage.Decrypt(encryptedBytes, true, CurrentUser.Keys[CurrentUser.KeyIndex]);
            }
            else
            {
                bytes = Storage.Decrypt(encryptedBytes, true, "ihavenokeys");
            }
            //ret.UserID = BitConverter.ToInt32(bytes, 1 + 1 + 4);
            pos        = 0; //2014.12.22. - Új tömb lett a visszafejtés után
            ret.UserID = BitConverter.ToInt32(bytes, pos);
            pos       += sizeof(int);
            //ret.Data = new byte[bytes.Length - 1 - 1 - 4 - 4];
            ret.Data = new byte[bytes.Length - pos];
            //Array.Copy(bytes, 2 + 4 + 4, ret.Data, 0, ret.Data.Length);
            Array.Copy(bytes, pos, ret.Data, 0, ret.Data.Length);
            return(ret);
        }
 /// <summary>
 /// Retrieves the size of the selected packet parts.
 /// </summary>
 /// <seealso href="GXPacketInsertHeader">InsertHeader</seealso>
 /// <seealso href="GXPacketInsertData">InsertData</seealso>
 /// <seealso href="GXPacketResetHeader">ResetHeader</seealso>
 /// <seealso href="GXPacketResetData">ResetData</seealso>
 public int GetSize(PacketParts parts)
 {
     int size = 0;
     if ((parts & PacketParts.Markers) != 0)
     {
         if (m_Bop != null)
         {
             size += GXConverter.GetBytes(m_Bop, false).Length;
         }
         if (m_Eop != null)
         {
             size += GXConverter.GetBytes(m_Eop, false).Length;
         }
         if (m_Checksum != null)
         {
             size += GXConverter.GetBytes(m_Checksum, false).Length;
         }
     }
     if ((parts & PacketParts.Data) != 0)
     {
         size += m_Data.Count;
     }
     return size;
 }