private static void LoadAndParseWhitelist()
        {
            whitelistPath = ACTkEditorGlobalStuff.ResolveInjectionUserWhitelistPath();
            if (string.IsNullOrEmpty(whitelistPath) || !File.Exists(whitelistPath))
            {
                return;
            }

            string[] separator = { ACTkEditorGlobalStuff.InjectionDataSeparator };

            var fs = new FileStream(whitelistPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            var br = new BinaryReader(fs);

            var count = br.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var line = br.ReadString();
                line = ObscuredString.EncryptDecrypt(line, "Elina");
                var strArr       = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                var stringsCount = strArr.Length;
                if (stringsCount > 1)
                {
                    var assemblyName = strArr[0];

                    var hashes = new int[stringsCount - 1];
                    for (var j = 1; j < stringsCount; j++)
                    {
                        var parseResult = 0;
                        var success     = int.TryParse(strArr[j], out parseResult);
                        if (success)
                        {
                            hashes[j - 1] = parseResult;
                        }
                        else
                        {
                            Debug.LogError("Could not parse value: " + strArr[j] + ", line:\n" + line);
                        }
                    }

                    whitelist.Add(new AllowedAssembly(assemblyName, hashes));
                }
                else
                {
                    Debug.LogWarning("Error parsing whitelist file line! Please report to " + ACTkEditorGlobalStuff.ReportEmail);
                }
            }

            br.Close();
            fs.Close();
        }
        private static void WriteWhitelist()
        {
            if (whitelist.Count > 0)
            {
                var fileExisted = File.Exists(whitelistPath);
                ACTkEditorGlobalStuff.RemoveReadOnlyAttribute(whitelistPath);
                var fs = new FileStream(whitelistPath, FileMode.Create, FileAccess.Write, FileShare.Read);
                var br = new BinaryWriter(fs);

                br.Write(whitelist.Count);

                foreach (var assembly in whitelist)
                {
                    var assemblyName = assembly.name;
                    var hashes       = "";

                    for (var j = 0; j < assembly.hashes.Length; j++)
                    {
                        hashes += assembly.hashes[j];
                        if (j < assembly.hashes.Length - 1)
                        {
                            hashes += ACTkEditorGlobalStuff.InjectionDataSeparator;
                        }
                    }

                    var line = ObscuredString.EncryptDecrypt(assemblyName + ACTkEditorGlobalStuff.InjectionDataSeparator + hashes, "Elina");
                    br.Write(line);
                }
                br.Close();
                fs.Close();

                if (!fileExisted)
                {
                    AssetDatabase.Refresh();
                }
            }
            else
            {
                ACTkEditorGlobalStuff.RemoveReadOnlyAttribute(whitelistPath);

                FileUtil.DeleteFileOrDirectory(whitelistPath);
                FileUtil.DeleteFileOrDirectory(whitelistPath + ".meta");

                AssetDatabase.Refresh();
            }

            ACTkPostprocessor.InjectionAssembliesScan();
        }
        public override void OnInspectorGUI()
        {
            if (self == null)
            {
                return;
            }

            serializedObject.Update();

            EditorGUIUtility.labelWidth = 140;
            EditorGUILayout.Space();
            DrawHeader("Base settings");

            EditorGUILayout.PropertyField(autoStart);
            detectionEventHasListener.boolValue = ACTkEditorGlobalStuff.CheckUnityEventHasActivePersistentListener(detectionEvent);

            CheckAdditionalEventsForListeners();

            if (autoStart.boolValue && !detectionEventHasListener.boolValue && !AdditionalEventsHasListeners())
            {
                EditorGUILayout.LabelField(new GUIContent("You need to add at least one active item to the Events in order to use Auto Start feature!"), ACTkEditorGUI.BoldLabel);
            }
            else if (!autoStart.boolValue)
            {
                EditorGUILayout.LabelField(new GUIContent("Don't forget to start detection!", "You should start detector from code using ObscuredCheatingDetector.StartDetection() method. See readme for details."), ACTkEditorGUI.BoldLabel);
                EditorGUILayout.Separator();
            }
            EditorGUILayout.PropertyField(autoDispose);
            EditorGUILayout.PropertyField(keepAlive);

            EditorGUILayout.Separator();

            if (DrawUniqueDetectorProperties())
            {
                EditorGUILayout.Separator();
            }

            //DrawHeader("Events");

            EditorGUILayout.PropertyField(detectionEvent);
            DrawAdditionalEvents();
            serializedObject.ApplyModifiedProperties();

            EditorGUIUtility.labelWidth = 0;
        }
        private WhitelistingResult TryWhitelistAssemblyName(AssemblyName assName, bool singleFile)
        {
            var result = WhitelistingResult.Exists;

            var assNameString = assName.Name;
            var hash          = ACTkEditorGlobalStuff.GetAssemblyHash(assName);

            var allowed = whitelist.FirstOrDefault(allowedAssembly => allowedAssembly.name == assNameString);

            if (allowed != null)
            {
                if (allowed.AddHash(hash))
                {
                    if (singleFile)
                    {
                        ShowNotification(new GUIContent("New hash added!"));
                    }
                    result = WhitelistingResult.Updated;
                }
                else
                {
                    if (singleFile)
                    {
                        ShowNotification(new GUIContent("Assembly already exists!"));
                    }
                }
            }
            else
            {
                allowed = new AllowedAssembly(assNameString, new[] { hash });
                whitelist.Add(allowed);

                if (singleFile)
                {
                    ShowNotification(new GUIContent("Assembly added!"));
                }
                result = WhitelistingResult.Added;
            }

            return(result);
        }
        private void OnGUI()
        {
            if (whitelist == null)
            {
                whitelist = new List <AllowedAssembly>();
                LoadAndParseWhitelist();
            }

            var tmpStyle = new GUIStyle(EditorStyles.largeLabel)
            {
                alignment = TextAnchor.MiddleCenter,
                fontStyle = FontStyle.Bold
            };

            GUILayout.Label("User-defined Whitelist of Assemblies trusted by Injection Detector", tmpStyle);

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            var whitelistUpdated = false;

            var count = whitelist.Count;

            if (count > 0)
            {
                for (var i = 0; i < count; i++)
                {
                    var assembly = whitelist[i];
                    using (ACTkEditorGUI.Horizontal())
                    {
                        GUILayout.Label(assembly.ToString());
                        if (GUILayout.Button(new GUIContent("-", "Remove Assembly from Whitelist"), GUILayout.Width(30)))
                        {
                            whitelist.Remove(assembly);
                            whitelistUpdated = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                tmpStyle = new GUIStyle(EditorStyles.largeLabel)
                {
                    alignment = TextAnchor.MiddleCenter
                };
                GUILayout.Label("- no Assemblies added so far (use buttons below to add) -", tmpStyle);
            }

            if (manualAssemblyWhitelisting)
            {
                manualAssemblyWhitelistingName = EditorGUILayout.TextField(manualAssemblyWhitelistingName);

                using (ACTkEditorGUI.Horizontal())
                {
                    if (GUILayout.Button("Save"))
                    {
                        try
                        {
                            if (manualAssemblyWhitelistingName.StartsWith("Cause:"))
                            {
                                throw new Exception("Please remove Cause: from the assembly name!");
                            }

                            var assName = new AssemblyName(manualAssemblyWhitelistingName.Trim());

                            var res = TryWhitelistAssemblyName(assName, true);
                            if (res != WhitelistingResult.Exists)
                            {
                                whitelistUpdated = true;
                            }
                            manualAssemblyWhitelisting     = false;
                            manualAssemblyWhitelistingName = InitialCustomName;
                        }
                        catch (Exception error)
                        {
                            ShowNotification(new GUIContent(error.Message));
                        }

                        GUI.FocusControl("");
                    }

                    if (GUILayout.Button("Cancel"))
                    {
                        manualAssemblyWhitelisting     = false;
                        manualAssemblyWhitelistingName = InitialCustomName;
                        GUI.FocusControl("");
                    }
                }
            }

            EditorGUILayout.EndScrollView();

            using (ACTkEditorGUI.Horizontal())
            {
                GUILayout.Space(20);
                if (GUILayout.Button("Add Assembly"))
                {
                    var assemblyPath = EditorUtility.OpenFilePanel("Choose an Assembly to add", "", "dll");
                    if (!string.IsNullOrEmpty(assemblyPath))
                    {
                        whitelistUpdated |= TryWhitelistAssemblies(new[] { assemblyPath }, true);
                    }
                }

                if (GUILayout.Button("Add Assemblies from folder"))
                {
                    var selectedFolder = EditorUtility.OpenFolderPanel("Choose a folder with Assemblies", "", "");
                    if (!string.IsNullOrEmpty(selectedFolder))
                    {
                        var libraries = ACTkEditorGlobalStuff.FindLibrariesAt(selectedFolder);
                        whitelistUpdated |= TryWhitelistAssemblies(libraries);
                    }
                }

                if (!manualAssemblyWhitelisting)
                {
                    if (GUILayout.Button("Add Assembly manually"))
                    {
                        manualAssemblyWhitelisting = true;
                    }
                }

                if (count > 0)
                {
                    if (GUILayout.Button("Clear"))
                    {
                        if (EditorUtility.DisplayDialog("Please confirm",
                                                        "Are you sure you wish to completely clear your Injection Detector whitelist?", "Yes", "No"))
                        {
                            whitelist.Clear();
                            whitelistUpdated = true;
                        }
                    }
                }
                GUILayout.Space(20);
            }

            GUILayout.Space(20);

            if (whitelistUpdated)
            {
                WriteWhitelist();
            }
        }
Beispiel #6
0
        private void OnGUI()
        {
            using (ACTkEditorGUI.Vertical(ACTkEditorGUI.PanelWithBackground))
            {
                ACTkEditorGUI.DrawHeader("Injection Detector settings (global)");
                //GUILayout.Label("Injection Detector settings (global)", ACTkEditorGUI.LargeBoldLabel);

                var enableInjectionDetector = EditorPrefs.GetBool(ACTkEditorGlobalStuff.PrefsInjectionEnabled);

                EditorGUI.BeginChangeCheck();
                enableInjectionDetector = GUILayout.Toggle(enableInjectionDetector, "Enable Injection Detector");
                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool(ACTkEditorGlobalStuff.PrefsInjectionEnabled, enableInjectionDetector);
                    if (enableInjectionDetector && !ACTkPostprocessor.IsInjectionDetectorTargetCompatible())
                    {
                        Debug.LogWarning(ACTkEditorGlobalStuff.LogPrefix + "Injection Detector is not available on selected platform (" +
                                         EditorUserBuildSettings.activeBuildTarget + ")");
                    }

                    if (!enableInjectionDetector)
                    {
                        ACTkEditorGlobalStuff.CleanInjectionDetectorData();
                    }
                    else if (!File.Exists(ACTkEditorGlobalStuff.injectionDataPath))
                    {
                        ACTkPostprocessor.InjectionAssembliesScan();
                    }
                }

                EditorGUILayout.Space();

                if (GUILayout.Button("Edit Whitelist"))
                {
                    ACTkAssembliesWhitelist.ShowWindow();
                }

                GUILayout.Space(3);
            }

            EditorGUILayout.Space();

            using (ACTkEditorGUI.Vertical(ACTkEditorGUI.PanelWithBackground))
            {
                ACTkEditorGUI.DrawHeader("WallHack Detector settings (per-project)");
                GUILayout.Label("Wireframe module uses specific shader under the hood. Thus such shader should be included into the build to exist at runtime. To make sure it's get included, you may add it to the Always Included Shaders list using buttons below. You don't need to include it if you're not going to use Wireframe module.",
                                EditorStyles.wordWrappedLabel);

                ReadGraphicsAsset();

                if (graphicsSettingsAsset != null && includedShaders != null)
                {
                    // outputs whole included shaders list, use for debug
                    //EditorGUILayout.PropertyField(includedShaders, true);

                    var shaderIndex = GetWallhackDetectorShaderIndex();

                    EditorGUI.BeginChangeCheck();

                    if (shaderIndex != -1)
                    {
                        GUILayout.Label("Shader <b>is at</b> the Always Included Shaders list, you're good to go!", ACTkEditorGUI.RichLabel);
                        if (GUILayout.Button("Remove shader"))
                        {
                            includedShaders.DeleteArrayElementAtIndex(shaderIndex);
                            includedShaders.DeleteArrayElementAtIndex(shaderIndex);
                        }
                        EditorGUILayout.Space();
                    }
                    else
                    {
                        GUILayout.Label("Shader <b>is not</b> at the Always Included Shaders list.", ACTkEditorGUI.RichLabel);
                        using (ACTkEditorGUI.Horizontal())
                        {
                            if (GUILayout.Button("Include automatically", GUILayout.Width(minSize.x / 2f)))
                            {
                                var shader = Shader.Find(WireframeShaderName);
                                if (shader != null)
                                {
                                    includedShaders.InsertArrayElementAtIndex(includedShaders.arraySize);
                                    var newItem = includedShaders.GetArrayElementAtIndex(includedShaders.arraySize - 1);
                                    newItem.objectReferenceValue = shader;
                                }
                                else
                                {
                                    Debug.LogError("Can't find " + WireframeShaderName + " shader! Please report this to the  " +
                                                   ACTkEditorGlobalStuff.ReportEmail + " including your Unity version number.");
                                }
                            }

                            if (GUILayout.Button("Include manually (see readme.pdf)"))
                            {
#if UNITY_2018_3_OR_NEWER
                                SettingsService.OpenProjectSettings("Project/Graphics");
#else
                                EditorApplication.ExecuteMenuItem("Edit/Project Settings/Graphics");
#endif
                            }
                        }
                        GUILayout.Space(3);
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        graphicsSettingsAsset.ApplyModifiedProperties();
                    }
                }
                else
                {
                    GUILayout.Label("Can't automatically control " + WireframeShaderName +
                                    " shader existence at the Always Included Shaders list. Please, manage this manually in Graphics Settings.");
                    if (GUILayout.Button("Open Graphics Settings"))
                    {
                        EditorApplication.ExecuteMenuItem("Edit/Project Settings/Graphics");
                    }
                }
            }

            EditorGUILayout.Space();

            using (ACTkEditorGUI.Vertical(ACTkEditorGUI.PanelWithBackground))
            {
                ACTkEditorGUI.DrawHeader("Conditional Compilation Symbols (per-project)");
                GUILayout.Label("Here you may switch conditional compilation symbols used in ACTk.\n" +
                                "Check Readme for more details on each symbol.", EditorStyles.wordWrappedLabel);
                EditorGUILayout.Space();
                if (symbolsData == null)
                {
                    symbolsData = GetSymbolsData();
                }

                /*if (GUILayout.Button("Reset"))
                 * {
                 *      var groups = (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup));
                 *      foreach (BuildTargetGroup buildTargetGroup in groups)
                 *      {
                 *              PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, string.Empty);
                 *      }
                 * }*/

                using (ACTkEditorGUI.Horizontal())
                {
                    using (ACTkEditorGUI.Vertical())
                    {
                        GUILayout.Label("Debug Symbols", ACTkEditorGUI.LargeBoldLabel);
                        ACTkEditorGUI.Separator();

                        DrawSymbol(ref symbolsData.injectionDebug, ACTkEditorGlobalStuff.ConditionalSymbols.InjectionDebug, "Switches the Injection Detector debug.");
                        DrawSymbol(ref symbolsData.injectionDebugVerbose, ACTkEditorGlobalStuff.ConditionalSymbols.InjectionDebugVerbose, "Switches the Injection Detector verbose debug level.");
                        DrawSymbol(ref symbolsData.injectionDebugParanoid, ACTkEditorGlobalStuff.ConditionalSymbols.InjectionDebugParanoid, "Switches the Injection Detector paranoid debug level.");
                        DrawSymbol(ref symbolsData.wallhackDebug, ACTkEditorGlobalStuff.ConditionalSymbols.WallhackDebug, "Switches the WallHack Detector debug - you'll see the WallHack objects in scene and get extra information in console.");
                        DrawSymbol(ref symbolsData.detectionBacklogs, ACTkEditorGlobalStuff.ConditionalSymbols.DetectionBacklogs, "Enables additional logs in some detectors to make it easier to debug false positives.");
                    }

                    using (ACTkEditorGUI.Vertical())
                    {
                        GUILayout.Label("Compatibility Symbols", ACTkEditorGUI.LargeBoldLabel);
                        ACTkEditorGUI.Separator();

                        DrawSymbol(ref symbolsData.exposeThirdPartyIntegrationSymbol, ACTkEditorGlobalStuff.ConditionalSymbols.ThirdPartyIntegration, "Enable to let other third-party code in project know you have ACTk added.");
                        DrawSymbol(ref symbolsData.excludeObfuscation, ACTkEditorGlobalStuff.ConditionalSymbols.ExcludeObfuscation, "Enable if you use Unity-unaware obfuscators which support ObfuscationAttribute to help avoid names corruption.");
                        DrawSymbol(ref symbolsData.preventReadPhoneState, ACTkEditorGlobalStuff.ConditionalSymbols.PreventReadPhoneState, "Disables ObscuredPrefs Lock To Device functionality.");
                        DrawSymbol(ref symbolsData.preventInternetPermission, ACTkEditorGlobalStuff.ConditionalSymbols.PreventInternetPermission, "Disables TimeCheatingDetector functionality.");
                        DrawSymbol(ref symbolsData.obscuredAutoMigration, ACTkEditorGlobalStuff.ConditionalSymbols.ObscuredAutoMigration, "Enables automatic migration of ObscuredFloat and ObscuredDouble instances from the ACTk 1.5.2.0-1.5.8.0 to the 1.5.9.0+ format. Reduces these types performance a bit.");
                    }
                }

                GUILayout.Space(3);
            }
        }