private WhitelisingResult TryWhitelistAssemblyName(AssemblyName assName, bool singleFile)
        {
            WhitelisingResult result = WhitelisingResult.Exists;

            string name = assName.Name;
            int    hash = ActEditorGlobalStuff.GetAssemblyHash(assName);

            AllowedAssembly allowed = whiteList.FirstOrDefault(allowedAssembly => allowedAssembly.name == name);

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

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

            return(result);
        }
        private bool TryWhitelistAssemblies(string[] libraries, bool singleFile)
        {
            int added   = 0;
            int updated = 0;

            int count = libraries.Length;

            for (int i = 0; i < count; i++)
            {
                string libraryPath = libraries[i];
                try
                {
                    AssemblyName      assName            = AssemblyName.GetAssemblyName(libraryPath);
                    WhitelisingResult whitelistingResult = TryWhitelistAssemblyName(assName, singleFile);
                    if (whitelistingResult == WhitelisingResult.Added)
                    {
                        added++;
                    }
                    else if (whitelistingResult == WhitelisingResult.Updated)
                    {
                        updated++;
                    }
                }
                catch
                {
                    if (singleFile)
                    {
                        ShowNotification(new GUIContent("Selected file is not a valid .NET assembly!"));
                    }
                }
            }

            if (!singleFile)
            {
                ShowNotification(new GUIContent("Assemblies added: " + added + ", updated: " + updated));
            }

            return(added > 0 || updated > 0);
        }
        private void OnGUI()
        {
            if (whiteList == null)
            {
                whiteList = new List <AllowedAssembly>();
                LoadAndParseWhiteList();
            }

            GUIStyle tmpStyle = new GUIStyle(EditorStyles.largeLabel);

            tmpStyle.alignment = TextAnchor.MiddleCenter;
            tmpStyle.fontStyle = FontStyle.Bold;
            GUILayout.Label("User-defined Whitelist of Assemblies trusted by Injection Detector", tmpStyle);

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

            int count = whiteList.Count;

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

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

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Save"))
                {
                    try
                    {
                        AssemblyName      assName = new AssemblyName(manualAssemblyWhitelistingName);
                        WhitelisingResult res     = TryWhitelistAssemblyName(assName, true);
                        if (res != WhitelisingResult.Exists)
                        {
                            whitelistUpdated = true;
                        }
                        manualAssemblyWhitelisting     = false;
                        manualAssemblyWhitelistingName = INITIAL_CUSTOM_NAME;
                    }
                    catch (FileLoadException error)
                    {
                        ShowNotification(new GUIContent(error.Message));
                    }

                    GUI.FocusControl("");
                }

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

            EditorGUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (GUILayout.Button("Add Assembly"))
            {
                string 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"))
            {
                string selectedFolder = EditorUtility.OpenFolderPanel("Choose a folder with Assemblies", "", "");
                if (!String.IsNullOrEmpty(selectedFolder))
                {
                    string[] libraries = ActEditorGlobalStuff.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.EndHorizontal();

            GUILayout.Space(20);

            if (whitelistUpdated)
            {
                WriteWhiteList();
            }
        }