internal void LockObscuredPrefsToDevice(ObscuredPrefs.DeviceLockLevel level)
 {
     // you can lock saves to the device (so they can't be read on another device)
     // there are few different levels of strictness, please see API docs for
     // lockToDevice property for additional details
     // set to None be default (does not lock to device)
     ObscuredPrefs.lockToDevice = level;
 }
Exemple #2
0
        private void DrawObscuredPrefsPage()
        {
            GUILayout.Label("ACTk has secure layer for the PlayerPrefs: <color=\"#75C4EB\">ObscuredPrefs</color>. " +
                            "It protects data from view, detects any cheating attempts, " +
                            "optionally locks data to the current device and supports additional data types.");
            GUILayout.Space(5);
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Label("<b>Supported types:</b>\n" + GetAllObscuredPrefsDataTypes(), GUILayout.MinWidth(130));
                using (new GUILayout.VerticalScope(GUI.skin.box))
                {
                    GUILayout.Label("Below you can try to cheat both regular PlayerPrefs and secure ObscuredPrefs:");
                    using (new GUILayout.VerticalScope())
                    {
                        GUILayout.Label("<color=\"" + RedColor + "\"><b>PlayerPrefs:</b></color>\neasy to cheat, only 3 supported types", centeredStyle);
                        GUILayout.Space(5);
                        if (string.IsNullOrEmpty(obscuredPrefsExamples.regularPrefs))
                        {
                            obscuredPrefsExamples.LoadRegularPrefs();
                        }
                        using (new GUILayout.HorizontalScope())
                        {
                            GUILayout.Label(obscuredPrefsExamples.regularPrefs, GUILayout.Width(270));
                            using (new GUILayout.VerticalScope())
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    if (GUILayout.Button("Save"))
                                    {
                                        obscuredPrefsExamples.SaveRegularPrefs();
                                    }
                                    if (GUILayout.Button("Load"))
                                    {
                                        obscuredPrefsExamples.LoadRegularPrefs();
                                    }
                                }
                                if (GUILayout.Button("Delete"))
                                {
                                    obscuredPrefsExamples.DeleteRegularPrefs();
                                }
                            }
                        }
                    }
                    GUILayout.Space(5);
                    using (new GUILayout.VerticalScope())
                    {
                        GUILayout.Label("<color=\"" + GreenColor + "\"><b>ObscuredPrefs:</b></color>\nsecure, lot of additional types and extra options", centeredStyle);
                        GUILayout.Space(5);
                        if (string.IsNullOrEmpty(obscuredPrefsExamples.obscuredPrefs))
                        {
                            obscuredPrefsExamples.LoadObscuredPrefs();
                        }

                        using (new GUILayout.HorizontalScope())
                        {
                            GUILayout.Label(obscuredPrefsExamples.obscuredPrefs, GUILayout.Width(270));
                            using (new GUILayout.VerticalScope())
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    if (GUILayout.Button("Save"))
                                    {
                                        obscuredPrefsExamples.SaveObscuredPrefs();
                                    }
                                    if (GUILayout.Button("Load"))
                                    {
                                        obscuredPrefsExamples.LoadObscuredPrefs();
                                    }
                                }
                                if (GUILayout.Button("Delete"))
                                {
                                    obscuredPrefsExamples.DeleteObscuredPrefs();
                                }

                                using (new GUILayout.HorizontalScope())
                                {
                                    GUILayout.Label("LockToDevice level");
                                }

                                savesLock = (ObscuredPrefs.DeviceLockLevel)GUILayout.SelectionGrid((int)savesLock, Enum.GetNames(typeof(ObscuredPrefs.DeviceLockLevel)), 3);
                                obscuredPrefsExamples.LockObscuredPrefsToDevice(savesLock);

                                GUILayout.Space(5);
                                using (new GUILayout.HorizontalScope())
                                {
                                    obscuredPrefsExamples.PreservePlayerPrefs = GUILayout.Toggle(obscuredPrefsExamples.PreservePlayerPrefs, "preservePlayerPrefs");
                                }
                                using (new GUILayout.HorizontalScope())
                                {
                                    obscuredPrefsExamples.EmergencyMode = GUILayout.Toggle(obscuredPrefsExamples.EmergencyMode, "emergencyMode");
                                }
                                using (new GUILayout.HorizontalScope())
                                {
                                    obscuredPrefsExamples.ReadForeignSaves = GUILayout.Toggle(obscuredPrefsExamples.ReadForeignSaves, "readForeignSaves");
                                }
                                GUILayout.Space(5);
                                GUILayout.Label("<color=\"" + (obscuredPrefsExamples.savesAlterationDetected ? RedColor : GreenColor) + "\">Saves modification detected: " + obscuredPrefsExamples.savesAlterationDetected + "</color>");
                                GUILayout.Label("<color=\"" + (obscuredPrefsExamples.foreignSavesDetected ? RedColor : GreenColor) + "\">Foreign saves detected: " + obscuredPrefsExamples.foreignSavesDetected + "</color>");
                            }
                        }
                    }
                    GUILayout.Space(5);
                }
            }
        }
        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);
        }
Exemple #4
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);
        }