Exemple #1
0
            internal void Decrypt()
            {
                if (!Obscured)
                {
                    return;
                }
                if (!IsEditableObscuredValue())
                {
                    return;
                }

                bool success = true;

                switch (obscuredType)
                {
                case ObscuredPrefs.DataType.Int:
                    prefType = PrefsType.Int;
                    break;

                case ObscuredPrefs.DataType.String:
                    prefType = PrefsType.String;
                    break;

                case ObscuredPrefs.DataType.Float:
                    prefType = PrefsType.Float;
                    break;

                case ObscuredPrefs.DataType.UInt:
                case ObscuredPrefs.DataType.Double:
                case ObscuredPrefs.DataType.Long:
                case ObscuredPrefs.DataType.Bool:
                case ObscuredPrefs.DataType.ByteArray:
                case ObscuredPrefs.DataType.Vector2:
                case ObscuredPrefs.DataType.Vector3:
                case ObscuredPrefs.DataType.Quaternion:
                case ObscuredPrefs.DataType.Color:
                case ObscuredPrefs.DataType.Rect:
                    instance.ShowNotification(new GUIContent("Type " + obscuredType + " isn't supported"));
                    success = false;
                    break;

                case ObscuredPrefs.DataType.Unknown:
                    instance.ShowNotification(new GUIContent("Can't decrypt " + key));
                    success = false;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (success)
                {
                    Obscured     = false;
                    obscuredType = ObscuredPrefs.DataType.Unknown;
                    dirtyValue   = dirtyKey = true;
                }
            }
Exemple #2
0
            internal PrefsRecord(string newKey, string value, bool encrypted)
            {
                key         = savedKey = newKey;
                stringValue = value;

                prefType = PrefsType.String;

                if (encrypted)
                {
                    obscuredType = ObscuredPrefs.DataType.String;
                    Obscured     = true;
                }
            }
Exemple #3
0
            internal PrefsRecord(string newKey, float value, bool encrypted)
            {
                key        = savedKey = newKey;
                floatValue = value;

                if (encrypted)
                {
                    prefType     = PrefsType.String;
                    obscuredType = ObscuredPrefs.DataType.Float;
                    Obscured     = true;
                }
                else
                {
                    prefType = PrefsType.Float;
                }
            }
        private static string EncryptData(string key, byte[] cleanBytes, ObscuredPrefs.DataType type)
        {
            int num = cleanBytes.Length;

            byte[] src  = ObscuredPrefs.EncryptDecryptBytes(cleanBytes, num, key + ObscuredPrefs.cryptoKey);
            uint   num2 = xxHash.CalculateHash(cleanBytes, num, 0u);

            byte[] src2 = new byte[]
            {
                (byte)(num2 & 255u),
                (byte)(num2 >> 8 & 255u),
                (byte)(num2 >> 16 & 255u),
                (byte)(num2 >> 24 & 255u)
            };
            byte[] array = null;
            int    num3;

            if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None)
            {
                num3 = num + 11;
                uint num4 = ObscuredPrefs.DeviceIdHash;
                array = new byte[]
                {
                    (byte)(num4 & 255u),
                    (byte)(num4 >> 8 & 255u),
                    (byte)(num4 >> 16 & 255u),
                    (byte)(num4 >> 24 & 255u)
                };
            }
            else
            {
                num3 = num + 7;
            }
            byte[] array2 = new byte[num3];
            Buffer.BlockCopy(src, 0, array2, 0, num);
            if (array != null)
            {
                Buffer.BlockCopy(array, 0, array2, num, 4);
            }
            array2[num3 - 7] = (byte)type;
            array2[num3 - 6] = 2;
            array2[num3 - 5] = (byte)ObscuredPrefs.lockToDevice;
            Buffer.BlockCopy(src2, 0, array2, num3 - 4, 4);
            return(Convert.ToBase64String(array2));
        }
Exemple #5
0
            internal PrefsRecord(string originalKey)
            {
                key = savedKey = originalKey;

                ReadValue();

                // only string prefs may be obscured
                if (prefType == PrefsType.String)
                {
                    Obscured = IsValueObscured(stringValue);

                    if (Obscured)
                    {
                        key = DecryptKey(key);

                        if (obscuredType == ObscuredPrefs.DataType.String)
                        {
                            stringValue = ObscuredPrefs.DecryptStringValue(key, stringValue, DEFAULT_STRING);
                            if (stringValue == DEFAULT_STRING)
                            {
                                stringValue = CANT_DECRYPT;
                            }
                        }
                        else if (obscuredType == ObscuredPrefs.DataType.Int)
                        {
                            intValue = ObscuredPrefs.DecryptIntValue(key, stringValue, DEFAULT_INT);
                            if (intValue == DEFAULT_INT)
                            {
                                obscuredType = ObscuredPrefs.DataType.String;
                                stringValue  = CANT_DECRYPT;
                            }
                        }
                        else if (obscuredType == ObscuredPrefs.DataType.Float)
                        {
                            floatValue = ObscuredPrefs.DecryptFloatValue(key, stringValue, DEFAULT_FLOAT);
                            if (floatValue == DEFAULT_FLOAT)
                            {
                                obscuredType = ObscuredPrefs.DataType.String;
                                stringValue  = CANT_DECRYPT;
                            }
                        }
                    }
                }
            }
            internal PrefsRecord(string originalKey)
            {
                key = savedKey = originalKey;

                ReadValue();

                // only string prefs may be obscured
                if (prefType == PrefsType.String)
                {
                    Obscured = IsValueObscured(stringValue);

                    if (Obscured)
                    {
                        key = DecryptKey(key);

                        if (obscuredType == ObscuredPrefs.DataType.String)
                        {
                            stringValue = ObscuredPrefs.DecryptStringValue(key, stringValue, DefaultString);
                            if (stringValue == DefaultString)
                            {
                                stringValue = CantDecrypt;
                            }
                        }
                        else if (obscuredType == ObscuredPrefs.DataType.Int)
                        {
                            intValue = ObscuredPrefs.DecryptIntValue(key, stringValue, DefaultInt);
                            if (intValue == DefaultInt)
                            {
                                obscuredType = ObscuredPrefs.DataType.String;
                                stringValue  = CantDecrypt;
                            }
                        }
                        else if (obscuredType == ObscuredPrefs.DataType.Float)
                        {
                            floatValue = ObscuredPrefs.DecryptFloatValue(key, stringValue, DefaultFloat);
                            if (Math.Abs(floatValue - DefaultFloat) < 0.00001f)
                            {
                                obscuredType = ObscuredPrefs.DataType.String;
                                stringValue  = CantDecrypt;
                            }
                        }
                    }
                }
            }
Exemple #7
0
            private bool IsValueObscured(string value)
            {
                bool validBase64String = (value.Length % 4 == 0) && Regex.IsMatch(value, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None);

                if (!validBase64String)
                {
                    return(false);
                }

                ObscuredPrefs.DataType dataType = ObscuredPrefs.GetRawValueType(value);
                if (!Enum.IsDefined(typeof(ObscuredPrefs.DataType), dataType) || dataType == ObscuredPrefs.DataType.Unknown)
                {
                    return(false);
                }

                obscuredType = dataType;

                return(true);
            }
Exemple #8
0
        private static string EncryptData(string key, byte[] cleanBytes, ObscuredPrefs.DataType type)
        {
            int length1 = cleanBytes.Length;

            byte[] numArray1 = ObscuredPrefs.EncryptDecryptBytes(cleanBytes, length1, key + ObscuredPrefs.encryptionKey);
            uint   hash      = xxHash.CalculateHash(cleanBytes, length1, 0U);

            byte[] numArray2 = new byte[4] {
                (byte)(hash & (uint)byte.MaxValue), (byte)(hash >> 8 & (uint)byte.MaxValue), (byte)(hash >> 16 & (uint)byte.MaxValue), (byte)(hash >> 24 & (uint)byte.MaxValue)
            };
            byte[] numArray3 = (byte[])null;
            int    length2;

            if (ObscuredPrefs.lockToDevice != ObscuredPrefs.DeviceLockLevel.None)
            {
                length2 = length1 + 11;
                uint deviceIdHash = ObscuredPrefs.DeviceIdHash;
                numArray3 = new byte[4]
                {
                    (byte)(deviceIdHash & (uint)byte.MaxValue),
                    (byte)(deviceIdHash >> 8 & (uint)byte.MaxValue),
                    (byte)(deviceIdHash >> 16 & (uint)byte.MaxValue),
                    (byte)(deviceIdHash >> 24 & (uint)byte.MaxValue)
                };
            }
            else
            {
                length2 = length1 + 7;
            }
            byte[] inArray = new byte[length2];
            Buffer.BlockCopy((Array)numArray1, 0, (Array)inArray, 0, length1);
            if (numArray3 != null)
            {
                Buffer.BlockCopy((Array)numArray3, 0, (Array)inArray, length1, 4);
            }
            inArray[length2 - 7] = (byte)type;
            inArray[length2 - 6] = (byte)2;
            inArray[length2 - 5] = (byte)ObscuredPrefs.lockToDevice;
            Buffer.BlockCopy((Array)numArray2, 0, (Array)inArray, length2 - 4, 4);
            return(Convert.ToBase64String(inArray));
        }
Exemple #9
0
            internal void Encrypt()
            {
                if (Obscured)
                {
                    return;
                }

                bool success = true;

                switch (prefType)
                {
                case PrefsType.Unknown:
                    success = false;
                    Debug.LogError(ActEditorGlobalStuff.LOG_PREFIX + "Can't encrypt pref of unknown type!");
                    break;

                case PrefsType.String:
                    obscuredType = ObscuredPrefs.DataType.String;
                    break;

                case PrefsType.Int:
                    obscuredType = ObscuredPrefs.DataType.Int;
                    break;

                case PrefsType.Float:
                    obscuredType = ObscuredPrefs.DataType.Float;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                if (success)
                {
                    prefType   = PrefsType.String;
                    Obscured   = true;
                    dirtyValue = dirtyKey = true;
                }
            }
        internal static ObscuredPrefs.DataType GetRawValueType(string value)
        {
            ObscuredPrefs.DataType dataType = ObscuredPrefs.DataType.Unknown;
            byte[] array;
            try
            {
                array = Convert.FromBase64String(value);
            }
            catch (Exception)
            {
                ObscuredPrefs.DataType result = dataType;
                return(result);
            }
            if (array.Length < 7)
            {
                return(dataType);
            }
            int num = array.Length;

            dataType = (ObscuredPrefs.DataType)array[num - 7];
            return(dataType);
        }