コード例 #1
0
        internal static byte[] DecryptData(string key, string encryptedInput)
        {
            byte[] array;
            try
            {
                array = Convert.FromBase64String(encryptedInput);
            }
            catch (Exception)
            {
                ObscuredPrefs.SavesTampered();
                byte[] result = null;
                return(result);
            }
            if (array.Length <= 0)
            {
                ObscuredPrefs.SavesTampered();
                return(null);
            }
            int  num = array.Length;
            byte b   = array[num - 6];

            if (b != 2)
            {
                ObscuredPrefs.SavesTampered();
                return(null);
            }
            ObscuredPrefs.DeviceLockLevel deviceLockLevel = (ObscuredPrefs.DeviceLockLevel)array[num - 5];
            byte[] array2 = new byte[4];
            Buffer.BlockCopy(array, num - 4, array2, 0, 4);
            uint num2 = (uint)((int)array2[0] | (int)array2[1] << 8 | (int)array2[2] << 16 | (int)array2[3] << 24);
            uint num3 = 0u;
            int  num4;

            if (deviceLockLevel != ObscuredPrefs.DeviceLockLevel.None)
            {
                num4 = num - 11;
                if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None)
                {
                    byte[] array3 = new byte[4];
                    Buffer.BlockCopy(array, num4, array3, 0, 4);
                    num3 = (uint)((int)array3[0] | (int)array3[1] << 8 | (int)array3[2] << 16 | (int)array3[3] << 24);
                }
            }
            else
            {
                num4 = num - 7;
            }
            byte[] array4 = new byte[num4];
            Buffer.BlockCopy(array, 0, array4, 0, num4);
            byte[] array5 = ObscuredPrefs.EncryptDecryptBytes(array4, num4, key + ObscuredPrefs.cryptoKey);
            uint   num5   = xxHash.CalculateHash(array5, num4, 0u);

            if (num5 != num2)
            {
                ObscuredPrefs.SavesTampered();
                return(null);
            }
            if (ObscuredPrefs.lockToDevice == ObscuredPrefs.DeviceLockLevel.Strict && num3 == 0u && !ObscuredPrefs.emergencyMode && !ObscuredPrefs.readForeignSaves)
            {
                return(null);
            }
            if (num3 != 0u && !ObscuredPrefs.emergencyMode)
            {
                uint num6 = ObscuredPrefs.DeviceIdHash;
                if (num3 != num6)
                {
                    ObscuredPrefs.PossibleForeignSavesDetected();
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        return(null);
                    }
                }
            }
            return(array5);
        }
コード例 #2
0
        private static byte[] DecryptData(string key, string encryptedInput)
        {
            byte[] numArray1;
            try
            {
                numArray1 = Convert.FromBase64String(encryptedInput);
            }
            catch (Exception ex)
            {
                ObscuredPrefs.SavesTampered();
                return((byte[])null);
            }
            if (numArray1.Length <= 0)
            {
                ObscuredPrefs.SavesTampered();
                return((byte[])null);
            }
            int length1 = numArray1.Length;

            if ((int)numArray1[length1 - 6] != 2)
            {
                ObscuredPrefs.SavesTampered();
                return((byte[])null);
            }
            ObscuredPrefs.DeviceLockLevel deviceLockLevel = (ObscuredPrefs.DeviceLockLevel)numArray1[length1 - 5];
            byte[] numArray2 = new byte[4];
            Buffer.BlockCopy((Array)numArray1, length1 - 4, (Array)numArray2, 0, 4);
            uint num1 = (uint)((int)numArray2[0] | (int)numArray2[1] << 8 | (int)numArray2[2] << 16 | (int)numArray2[3] << 24);
            uint num2 = 0;
            int  length2;

            if (deviceLockLevel != ObscuredPrefs.DeviceLockLevel.None)
            {
                length2 = length1 - 11;
                if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None)
                {
                    byte[] numArray3 = new byte[4];
                    Buffer.BlockCopy((Array)numArray1, length2, (Array)numArray3, 0, 4);
                    num2 = (uint)((int)numArray3[0] | (int)numArray3[1] << 8 | (int)numArray3[2] << 16 | (int)numArray3[3] << 24);
                }
            }
            else
            {
                length2 = length1 - 7;
            }
            byte[] bytes = new byte[length2];
            Buffer.BlockCopy((Array)numArray1, 0, (Array)bytes, 0, length2);
            byte[] buf = ObscuredPrefs.EncryptDecryptBytes(bytes, length2, key + ObscuredPrefs.encryptionKey);
            if ((int)xxHash.CalculateHash(buf, length2, 0U) != (int)num1)
            {
                ObscuredPrefs.SavesTampered();
                return((byte[])null);
            }
            if (ObscuredPrefs.lockToDevice == ObscuredPrefs.DeviceLockLevel.Strict && (int)num2 == 0 && (!ObscuredPrefs.emergencyMode && !ObscuredPrefs.readForeignSaves))
            {
                return((byte[])null);
            }
            if ((int)num2 != 0 && !ObscuredPrefs.emergencyMode)
            {
                uint deviceIdHash = ObscuredPrefs.DeviceIdHash;
                if ((int)num2 != (int)deviceIdHash)
                {
                    ObscuredPrefs.PossibleForeignSavesDetected();
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        return((byte[])null);
                    }
                }
            }
            return(buf);
        }
コード例 #3
0
        private static string DeprecatedDecryptValue(string value)
        {
            string[] array = value.Split(new char[]
            {
                ':'
            });
            if (array.Length < 2)
            {
                ObscuredPrefs.SavesTampered();
                return(string.Empty);
            }
            string text = array[0];
            string a    = array[1];

            byte[] array2;
            try
            {
                array2 = Convert.FromBase64String(text);
            }
            catch
            {
                ObscuredPrefs.SavesTampered();
                return(string.Empty);
            }
            string @string = Encoding.UTF8.GetString(array2, 0, array2.Length);
            string result  = ObscuredString.EncryptDecrypt(@string, ObscuredPrefs.cryptoKey);

            if (array.Length == 3)
            {
                if (a != ObscuredPrefs.DeprecatedCalculateChecksum(text + ObscuredPrefs.DeprecatedDeviceId))
                {
                    ObscuredPrefs.SavesTampered();
                }
            }
            else if (array.Length == 2)
            {
                if (a != ObscuredPrefs.DeprecatedCalculateChecksum(text))
                {
                    ObscuredPrefs.SavesTampered();
                }
            }
            else
            {
                ObscuredPrefs.SavesTampered();
            }
            if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None && !ObscuredPrefs.emergencyMode)
            {
                if (array.Length >= 3)
                {
                    string a2 = array[2];
                    if (a2 != ObscuredPrefs.DeprecatedDeviceId)
                    {
                        if (!ObscuredPrefs.readForeignSaves)
                        {
                            result = string.Empty;
                        }
                        ObscuredPrefs.PossibleForeignSavesDetected();
                    }
                }
                else if (ObscuredPrefs.lockToDevice == ObscuredPrefs.DeviceLockLevel.Strict)
                {
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        result = string.Empty;
                    }
                    ObscuredPrefs.PossibleForeignSavesDetected();
                }
                else if (a != ObscuredPrefs.DeprecatedCalculateChecksum(text))
                {
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        result = string.Empty;
                    }
                    ObscuredPrefs.PossibleForeignSavesDetected();
                }
            }
            return(result);
        }
コード例 #4
0
        private static string DeprecatedDecryptValue(string value)
        {
            string[] strArray = value.Split(':');
            if (strArray.Length < 2)
            {
                ObscuredPrefs.SavesTampered();
                return(string.Empty);
            }
            string str1 = strArray[0];
            string str2 = strArray[1];

            byte[] bytes;
            try
            {
                bytes = Convert.FromBase64String(str1);
            }
            catch
            {
                ObscuredPrefs.SavesTampered();
                return(string.Empty);
            }
            string str3 = ObscuredString.EncryptDecrypt(Encoding.UTF8.GetString(bytes, 0, bytes.Length), ObscuredPrefs.encryptionKey);

            if (strArray.Length == 3)
            {
                if (str2 != ObscuredPrefs.DeprecatedCalculateChecksum(str1 + ObscuredPrefs.DeprecatedDeviceId))
                {
                    ObscuredPrefs.SavesTampered();
                }
            }
            else if (strArray.Length == 2)
            {
                if (str2 != ObscuredPrefs.DeprecatedCalculateChecksum(str1))
                {
                    ObscuredPrefs.SavesTampered();
                }
            }
            else
            {
                ObscuredPrefs.SavesTampered();
            }
            if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None && !ObscuredPrefs.emergencyMode)
            {
                if (strArray.Length >= 3)
                {
                    if (strArray[2] != ObscuredPrefs.DeprecatedDeviceId)
                    {
                        if (!ObscuredPrefs.readForeignSaves)
                        {
                            str3 = string.Empty;
                        }
                        ObscuredPrefs.PossibleForeignSavesDetected();
                    }
                }
                else if (ObscuredPrefs.lockToDevice == ObscuredPrefs.DeviceLockLevel.Strict)
                {
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        str3 = string.Empty;
                    }
                    ObscuredPrefs.PossibleForeignSavesDetected();
                }
                else if (str2 != ObscuredPrefs.DeprecatedCalculateChecksum(str1))
                {
                    if (!ObscuredPrefs.readForeignSaves)
                    {
                        str3 = string.Empty;
                    }
                    ObscuredPrefs.PossibleForeignSavesDetected();
                }
            }
            return(str3);
        }