Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="PatchEncryptionKey"/> based on the provided
        /// <see cref="vector"/>.
        /// </summary>
        /// <param name="vector">The vector to base the key from.</param>
        /// <returns>A new initalized patch encryption key.</returns>
        public static PatchEncryptionKey Create(uint vector)
        {
            PatchEncryptionKey key = new PatchEncryptionKey();

            InitializeKey(key, vector);

            return(key);
        }
        public PatchServerCryptoProvider(PatchEncryptionKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            Key = key;
        }
 //TODO: Gett fixed pointer to span may be unsafe, we need pinnable reference probably.
 public unsafe void CRYPT_PC_CryptData(PatchEncryptionKey key, Span <byte> data, int offset, int count)
 {
     for (uint x = (uint)offset; x < count; x += 4)
     {
         fixed(void *p = &data[(int)x])
         {
             *(uint *)p = (*(uint *)p) ^ key.CRYPT_PC_GetNextKey();
         }
     }
 }
Exemplo n.º 4
0
        private static void InitializeKey(PatchEncryptionKey key, uint val)
        {
            uint index, tmp;

            tmp          = 1;
            key.Keys[55] = val;

            for (int i1 = 0x15; i1 <= 0x46E; i1 += 0x15)
            {
                index           = (uint)(i1 % 55);
                val            -= tmp;
                key.Keys[index] = tmp;
                tmp             = val;
                val             = (uint)key.Keys[index];
            }

            for (int i = 0; i < 4; i++)
            {
                key.CRYPT_PC_MixKeys();
            }

            key.Position = 56;
        }