Exemple #1
0
        private void ExecuteScriptLinux(APlugin plugin, string file, string args)
        {
            using var dllimport = new DllImportLaunchCmdUnix();
            var result = "";

            if (plugin.AdministratorRights)
            {
                result = dllimport.UseLaunchCommand(
                    $"sudo -u {plugin.AdministratorUsername} -s {file} -c {args} 2> /dev/null");
            }
            else
            {
                result = dllimport.UseLaunchCommand($"{file} {args} 2> /dev/null");
            }

            // if it's not a valid json
            try
            {
                JObject.Parse(result);
            }
            catch (JsonReaderException)
            {
                Log.Instance?.Error($"{plugin.Infos.Name}: result not in a json format: {result}");
                return;
            }

            plugin.RaiseOnExecutionFinished(result);
        }
Exemple #2
0
        /// <summary>
        ///     run a code from a shared object fille
        /// </summary>
        /// <param name="plugin">plugin to be executed</param>
        public void RunFromSO(APlugin plugin)
        {
            // .so works only on linux
            if (OSAttribute.IsLinux)
            {
                QueueLength++;

                ThreadPool.QueueUserWorkItem(obj =>
                {
                    try
                    {
                        using var dllimport = new DllImportEntryPoint();
                        var result          = dllimport.UseRunEntryPointSharedObject(plugin.Infos.FilePath);

                        plugin.RaiseOnExecutionFinished(result);
                    }
                    catch (Exception e)
                    {
                        Log.Instance?.Error($"{plugin.Infos.FileName} encountered a problem: {e.Message}");
                    }
                    finally
                    {
                        Consume();
                    }
                });
            }
        }
Exemple #3
0
        private void RunClassicDLL(APlugin plugin)
        {
            using var dllimport = new DllImportEntryPoint();

            var result = dllimport.UseRunEntryPointSharedObject(plugin.Infos.FilePath);

            plugin.RaiseOnExecutionFinished(result);
        }
Exemple #4
0
        private void TryRunAssemblyDLL(APlugin plugin)
        {
            var assembly = Assembly.LoadFrom(plugin.Infos.FilePath);
            var type     = assembly.GetTypes().FirstOrDefault();

            var entryPointMethod = type?.GetMethod(MethodEntryPointName);

            if (entryPointMethod != null)
            {
                dynamic instance = Activator.CreateInstance(type);
                var     result   = entryPointMethod.Invoke(instance, null);

                plugin.RaiseOnExecutionFinished(result);
            }
            else
            {
                Log.Instance?.Error($"Method '{MethodEntryPointName}' from DLL {plugin.Infos.FileName} not found.");
            }
        }
Exemple #5
0
        private void ExecuteScriptWindows(APlugin plugin, string file, string args)
        {
            var verb     = "";
            var username = "";

            // if the plugin is a powershell scripts, it needs some tweeks to execute it
            if (plugin.Infos.FileExtension.Equals(".ps1"))
            {
                file = "Powershell.exe";
                args = $"-executionpolicy remotesigned -File {args}";
            }

            var start = new ProcessStartInfo
            {
                FileName               = file,
                Arguments              = args,
                Verb                   = verb,
                UserName               = username,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                RedirectStandardOutput = true,
                RedirectStandardError  = true
            };

            using var process      = Process.Start(start);
            using var readerOutput = process.StandardOutput;
            using var readerInput  = process.StandardError;

            var err = readerInput.ReadToEnd();

            if (!string.IsNullOrEmpty(err))
            {
                Log.Instance?.Error($"Plugin encoutered an error: {err}");
                throw new ApplicationException(err);
            }

            plugin.RaiseOnExecutionFinished(readerOutput.ReadToEnd());
        }