Exemple #1
0
        static void Main(string[] args)
        {
            FileUnblocker fub = new FileUnblocker();

            string[] list = Directory.EnumerateFiles("./", "*.*", SearchOption.AllDirectories).ToArray();
            foreach (string s in list)
            {
                Console.WriteLine($"Filename - {s} :: Unblocked -> {fub.Unblock(s)}");
            }
        }
Exemple #2
0
        public static Process StartPowerPoint(string pptPath)
        {
            var success = FileUnblocker.Unblock(pptPath);

            if (!success)
            {
                throw new InvalidOperationException($"The specified file is blocked and can not be unblocked. {pptPath}");
            }

            if (powerPointPath == null)
            {
                powerPointPath = FindExtensionExe(Path.GetExtension(pptPath));
            }

            var processName       = Path.GetFileNameWithoutExtension(powerPointPath);
            var existingProcesses = Process.GetProcessesByName(processName);

            foreach (var item in existingProcesses)
            {
                var cmd = GetCommandLine(item);
                if (cmd?.Contains("/s", StringComparison.InvariantCultureIgnoreCase) == true)
                {
                    item.Kill();
                }
            }

            ProcessStartInfo psi = new ProcessStartInfo(powerPointPath);

            psi.ArgumentList.Add("/S");
            psi.ArgumentList.Add(pptPath);
            psi.UseShellExecute = true;
            using var process   = Process.Start(psi);
            process.WaitForInputIdle();
            Process powerPointProcess;
            int     maxTries = 50;

            do
            {
                maxTries--;
                if (!process.HasExited)
                {
                    Thread.Sleep(10);
                }
                powerPointProcess = WindowEnumerationHelper.GetProcesses(processName).FirstOrDefault(x => GetCommandLine(x)?.Contains(pptPath) == true);
                if (powerPointProcess == null)
                {
                    Thread.Sleep(10);
                }
            } while (powerPointProcess == null && maxTries > 0);

            return(powerPointProcess);
        }
Exemple #3
0
        /// <summary>
        /// Removes Zone Information from dynamic link libraries downloaded from the internet such
        /// that certain users of Microsoft Windows would not be denied loading of our own arbitrary code.
        /// </summary>
        /// <remarks>
        /// Only affects files downloaded via very specific certain outdated programs such as
        /// Internet Explorer
        /// </remarks>
        public static void UnblockDlls()
        {
            // Print Info Message about Unlocking DLLs
            LoaderConsole.PrintFormattedMessage("Removing Zone Identifiers from Files (DLL Unlocking)", LoaderConsole.PrintInfoMessage);

            // Search all DLLs under loader directories.
            // Normally I'd restrict this to mod directories, but the loader's own libraries might also be worth checking.
            string[] dllFiles = Directory.GetFiles(LoaderPaths.GetModLoaderDirectory(), "*.dll", SearchOption.AllDirectories);

            // Unblock new file.
            foreach (string dllFile in dllFiles)
            {
                FileUnblocker.Unblock(dllFile);
            }
        }
        public static void loadPlugins()
        {
            string           settings     = File.ReadAllText(Environment.CurrentDirectory + "/settings.json");
            HookSettings     hookSettings = JsonConvert.DeserializeObject <HookSettings>(settings);
            BackgroundWorker pluginWorker = new BackgroundWorker();

            pluginWorker.DoWork += (object sender, DoWorkEventArgs e) =>
            {
                string        currentDir = Environment.CurrentDirectory;
                DirectoryInfo pluginDir  = new DirectoryInfo(currentDir + "\\Plugins");
                if (!pluginDir.Exists)
                {
                    pluginDir.Create();
                }
                foreach (FileInfo file in pluginDir.GetFiles())
                {
                    if (!file.Name.Contains(".dll"))
                    {
                        Logger.Log("Skipping " + file.Name + " as it isnt a .dll");
                        continue;
                    }
                    if (!hookSettings.enabledPlugins.Contains(file.Name))
                    {
                        Logger.Log("Skipping " + file.Name + " as it isnt enabled.");
                        continue;
                    }
                    BackgroundWorker pluginLoadWorker = new BackgroundWorker();
                    pluginLoadWorker.DoWork += (object obj, DoWorkEventArgs dw) =>
                    {
                        try
                        {
                            Logger.Log("Unblocking " + file.Name);
                            FileUnblocker.Unblock(file.FullName);
                            Logger.Log("Attempting to load " + file.Name);
                            Assembly pluginAsm  = Assembly.LoadFrom(file.FullName);
                            Type     pluginType = typeof(NkPlugin);
                            foreach (Type t in pluginAsm.GetTypes())
                            {
                                //Logger.Log("Found class " + t.Name);
                                if (pluginType.IsAssignableFrom(t))
                                {
                                    Logger.Log("Found " + t.Name + " to be assignable");
                                    NkPlugin plugin = (NkPlugin)Activator.CreateInstance(t);
                                    plugin.NkLoad();
                                    Logger.Log("Loaded " + t.Name + " via NkPlugin load function");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Log("Exception while loading plugin!");
                            Logger.Log("-------------------------------");
                            Logger.Log("Message: " + ex.Message);
                            Logger.Log("Stacktrace:\n" + ex.StackTrace);
                            Logger.Log("-------------------------------");
                        }
                    };
                    pluginLoadWorker.RunWorkerAsync();
                }
                Console.Title = "NKHook5-Console";
            };
            pluginWorker.RunWorkerAsync();
        }