コード例 #1
0
        private bool AssemblyAllowed(Assembly ass)
        {
#if !UNITY_WEBPLAYER
            string assemblyName = ass.GetName().Name;
#else
            string fullname     = ass.FullName;
            string assemblyName = fullname.Substring(0, fullname.IndexOf(", ", StringComparison.Ordinal));
#endif

            int hash = GetAssemblyHash(ass);

            bool result = false;
            for (int i = 0; i < allowedAssemblies.Length; i++)
            {
                AllowedAssembly allowedAssembly = allowedAssemblies[i];

                if (allowedAssembly.name == assemblyName)
                {
                    if (Array.IndexOf(allowedAssembly.hashes, hash) != -1)
                    {
                        result = true;
                        break;
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        private void LoadAndParseAllowedAssemblies()
        {
            TextAsset textAsset = (TextAsset)Resources.Load("fndid", typeof(TextAsset));

            if (textAsset == null)
            {
                signaturesAreNotGenuine = true;
            }
            else
            {
                string[] separator = new string[1]
                {
                    ":"
                };
                MemoryStream memoryStream = new MemoryStream(textAsset.bytes);
                BinaryReader binaryReader = new BinaryReader(memoryStream);
                int          num          = binaryReader.ReadInt32();
                allowedAssemblies = new AllowedAssembly[num];
                for (int i = 0; i < num; i++)
                {
                    string value = binaryReader.ReadString();
                    value = ObscuredString.EncryptDecrypt(value, "Elina");
                    string[] array = value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                    int      num2  = array.Length;
                    if (num2 <= 1)
                    {
                        signaturesAreNotGenuine = true;
                        binaryReader.Close();
                        memoryStream.Close();
                        return;
                    }
                    string name   = array[0];
                    int[]  array2 = new int[num2 - 1];
                    for (int j = 1; j < num2; j++)
                    {
                        array2[j - 1] = int.Parse(array[j]);
                    }
                    allowedAssemblies[i] = new AllowedAssembly(name, array2);
                }
                binaryReader.Close();
                memoryStream.Close();
                Resources.UnloadAsset(textAsset);
                hexTable = new string[256];
                for (int k = 0; k < 256; k++)
                {
                    hexTable[k] = k.ToString("x2");
                }
            }
        }
コード例 #3
0
        private bool AssemblyAllowed(Assembly ass)
        {
            string name         = ass.GetName().Name;
            int    assemblyHash = GetAssemblyHash(ass);
            bool   result       = false;

            for (int i = 0; i < allowedAssemblies.Length; i++)
            {
                AllowedAssembly allowedAssembly = allowedAssemblies[i];
                if (allowedAssembly.name == name && Array.IndexOf(allowedAssembly.hashes, assemblyHash) != -1)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        private void LoadAndParseAllowedAssemblies()
        {
#if ACTK_DEBUG_NORMAL
            Debug.Log(ACTkConstants.LogPrefix + "Starting LoadAndParseAllowedAssemblies()", this);
            Stopwatch sw = Stopwatch.StartNew();
#endif
            var assembliesSignatures = (TextAsset)Resources.Load("fndid", typeof(TextAsset));
            if (assembliesSignatures == null)
            {
                signaturesAreNotGenuine = true;
                return;
            }

#if ACTK_DEBUG_NORMAL
            sw.Stop();
            Debug.Log(ACTkConstants.LogPrefix + "Creating separator array and opening MemoryStream", this);
            sw.Start();
#endif

            string[] separator = { ":" };

            var ms = new MemoryStream(assembliesSignatures.bytes);
            var br = new BinaryReader(ms);

            var count = br.ReadInt32();

#if ACTK_DEBUG_NORMAL
            sw.Stop();
            Debug.Log(ACTkConstants.LogPrefix + "Allowed assemblies count from MS: " + count, this);
            sw.Start();
#endif

            allowedAssemblies = new AllowedAssembly[count];

            for (var i = 0; i < count; i++)
            {
                var line = br.ReadString();
#if ACTK_DEBUG_PARANOID
                sw.Stop();
                Debug.Log(ACTkConstants.LogPrefix + "Line: " + line, this);
                sw.Start();
#endif
                line = ObscuredString.EncryptDecrypt(line, "Elina");
#if ACTK_DEBUG_PARANOID
                sw.Stop();
                Debug.Log(ACTkConstants.LogPrefix + "Line decrypted : " + line, this);
                sw.Start();
#endif
                var strArr       = line.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                var stringsCount = strArr.Length;
#if ACTK_DEBUG_PARANOID
                sw.Stop();
                Debug.Log(ACTkConstants.LogPrefix + "stringsCount : " + stringsCount, this);
                sw.Start();
#endif
                if (stringsCount > 1)
                {
                    var assemblyName = strArr[0];

                    var hashes = new int[stringsCount - 1];
                    for (var j = 1; j < stringsCount; j++)
                    {
                        hashes[j - 1] = int.Parse(strArr[j]);
                    }

                    allowedAssemblies[i] = new AllowedAssembly(assemblyName, hashes);
                }
                else
                {
                    signaturesAreNotGenuine = true;
                    br.Close();
                    ms.Close();
#if ACTK_DEBUG_NORMAL
                    sw.Stop();
#endif
                    return;
                }
            }
            br.Close();
            ms.Close();
            Resources.UnloadAsset(assembliesSignatures);

#if ACTK_DEBUG_NORMAL
            sw.Stop();
            Debug.Log(ACTkConstants.LogPrefix + "Allowed Assemblies parsing duration: " + sw.ElapsedMilliseconds + " ms.", this);
#endif

            hexTable = new string[256];
            for (var i = 0; i < 256; i++)
            {
                hexTable[i] = i.ToString("x2");
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
0
		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;
		}
コード例 #8
0
		internal static void InjectionAssembliesScan(bool forced)
		{
			if (!IsInjectionDetectorTargetCompatible() && !forced)
			{
				InjectionDetectorTargetCompatibleCheck();
				return;
			}

#if (DEBUG || DEBUG_VERBOSE || DEBUG_PARANIOD)
			Stopwatch sw = Stopwatch.StartNew();
	#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Injection Detector Assemblies Scan\n");
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Paths:\n" +

			          "Assets: " + ActEditorGlobalStuff.ASSETS_PATH + "\n" +
			          "Assemblies: " + ActEditorGlobalStuff.ASSEMBLIES_PATH + "\n" +
			          "Injection Detector Data: " + ActEditorGlobalStuff.INJECTION_DATA_PATH);
			sw.Start();
	#endif
#endif

#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Looking for all assemblies in current project...");
			sw.Start();
#endif
			allLibraries.Clear();
			allowedAssemblies.Clear();

			allLibraries.AddRange(ActEditorGlobalStuff.FindLibrariesAt(ActEditorGlobalStuff.assetsPath));
			allLibraries.AddRange(ActEditorGlobalStuff.FindLibrariesAt(ActEditorGlobalStuff.assembliesPath));
#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Total libraries found: " + allLibraries.Count);
			sw.Start();
#endif
			const string editorSubdir = "/editor/";
			string assembliesPathLowerCase = ActEditorGlobalStuff.ASSEMBLIES_PATH_RELATIVE.ToLower();
			foreach (string libraryPath in allLibraries)
			{
				string libraryPathLowerCase = libraryPath.ToLower();
#if (DEBUG_PARANIOD)
				sw.Stop();
				Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Checking library at the path: " + libraryPathLowerCase);
				sw.Start();
#endif
				if (libraryPathLowerCase.Contains(editorSubdir)) continue;
				if (libraryPathLowerCase.Contains("-editor.dll") && libraryPathLowerCase.Contains(assembliesPathLowerCase)) continue;

				try
				{
					AssemblyName assName = AssemblyName.GetAssemblyName(libraryPath);
					string name = assName.Name;
					int hash = ActEditorGlobalStuff.GetAssemblyHash(assName);

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

					if (allowed != null)
					{
						allowed.AddHash(hash);
					}
					else
					{
						allowed = new AllowedAssembly(name, new[] {hash});
						allowedAssemblies.Add(allowed);
					}
				}
				catch
				{
					// not a valid IL assembly, skipping
				}
			}

#if (DEBUG || DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			string trace = ActEditorGlobalStuff.LOG_PREFIX + "Found assemblies (" + allowedAssemblies.Count + "):\n";

			foreach (AllowedAssembly allowedAssembly in allowedAssemblies)
			{
				trace += "  Name: " + allowedAssembly.name + "\n";
				trace = allowedAssembly.hashes.Aggregate(trace, (current, hash) => current + ("    Hash: " + hash + "\n"));
			}

			Debug.Log(trace);
			sw.Start();
#endif
			if (!Directory.Exists(ActEditorGlobalStuff.resourcesPath))
			{
#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
				sw.Stop();
				Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Creating resources folder: " + ActEditorGlobalStuff.RESOURCES_PATH);
				sw.Start();
#endif
				Directory.CreateDirectory(ActEditorGlobalStuff.resourcesPath);
			}

			ActEditorGlobalStuff.RemoveReadOnlyAttribute(ActEditorGlobalStuff.injectionDataPath);
			BinaryWriter bw = new BinaryWriter(new FileStream(ActEditorGlobalStuff.injectionDataPath, FileMode.Create, FileAccess.Write, FileShare.Read));
			int allowedAssembliesCount = allowedAssemblies.Count;

			int totalWhitelistedAssemblies = 0;

#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Processing default whitelist");
			sw.Start();
#endif

			string defaultWhitelistPath = ActEditorGlobalStuff.ResolveInjectionDefaultWhitelistPath();
			if (File.Exists(defaultWhitelistPath))
			{
				BinaryReader br = new BinaryReader(new FileStream(defaultWhitelistPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
				int assembliesCount = br.ReadInt32();
				totalWhitelistedAssemblies = assembliesCount + allowedAssembliesCount;

				bw.Write(totalWhitelistedAssemblies);

				for (int i = 0; i < assembliesCount; i++)
				{
					bw.Write(br.ReadString());
				}
				br.Close();
			}
			else
			{
#if (DEBUG || DEBUG_VERBOSE || DEBUG_PARANIOD)
				sw.Stop();
#endif
				bw.Close();
				Debug.LogError(ActEditorGlobalStuff.LOG_PREFIX + "Can't find " + ActEditorGlobalStuff.INJECTION_DEFAULT_WHITELIST_FILE + " file!\nPlease, report to " + ActEditorGlobalStuff.REPORT_EMAIL);
				return;
			}

#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Processing user whitelist");
			sw.Start();
#endif

			string userWhitelistPath = ActEditorGlobalStuff.ResolveInjectionUserWhitelistPath();
			if (File.Exists(userWhitelistPath))
			{
				BinaryReader br = new BinaryReader(new FileStream(userWhitelistPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
				int assembliesCount = br.ReadInt32();

				bw.Seek(0, SeekOrigin.Begin);
				bw.Write(totalWhitelistedAssemblies + assembliesCount);
				bw.Seek(0, SeekOrigin.End);
				for (int i = 0; i < assembliesCount; i++)
				{
					bw.Write(br.ReadString());
				}
				br.Close();
			}

#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Processing project assemblies");
			sw.Start();
#endif

			for (int i = 0; i < allowedAssembliesCount; i++)
			{
				AllowedAssembly assembly = allowedAssemblies[i];
				string name = assembly.name;
				string hashes = "";

				for (int j = 0; j < assembly.hashes.Length; j++)
				{
					hashes += assembly.hashes[j];
					if (j < assembly.hashes.Length - 1)
					{
						hashes += ActEditorGlobalStuff.INJECTION_DATA_SEPARATOR;
					}
				}

				string line = ObscuredString.EncryptDecrypt(name + ActEditorGlobalStuff.INJECTION_DATA_SEPARATOR + hashes, "Elina");
				
#if (DEBUG_VERBOSE || DEBUG_PARANIOD)
				Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Writing assembly:\n" + name + ActEditorGlobalStuff.INJECTION_DATA_SEPARATOR + hashes);
#endif
				bw.Write(line);
			}

			bw.Close();			 
#if (DEBUG || DEBUG_VERBOSE || DEBUG_PARANIOD)
			sw.Stop();
			Debug.Log(ActEditorGlobalStuff.LOG_PREFIX + "Assemblies scan duration: " + sw.ElapsedMilliseconds + " ms.");
#endif

			if (allowedAssembliesCount == 0)
			{
				Debug.LogError(ActEditorGlobalStuff.LOG_PREFIX + "Can't find any assemblies!\nPlease, report to " + ActEditorGlobalStuff.REPORT_EMAIL);
			}

			AssetDatabase.Refresh();
			//EditorApplication.UnlockReloadAssemblies();
		}