Esempio n. 1
0
 private static void Main(string[] args)
 {
     WardenManager.Initialize(new WardenOptions
     {
         DeepKill        = true,
         CleanOnExit     = true,
         ReadFileHeaders = false
     });
     HostFactory.Run(x =>                                                     //1
     {
         x.Service <UlteriusAgent>(s =>                                       //2
         {
             s.ConstructUsing(name => new UlteriusAgent());                   //3
             s.WhenStarted(tc => tc.Start());                                 //4
             s.WhenStopped(tc => tc.Stop());
             s.WhenSessionChanged((se, e, id) => { se.HandleEvent(e, id); }); //5
         });
         x.OnException(ex =>
         {
             //TODO Logging
         });
         x.RunAsLocalSystem(); //6
         x.EnableSessionChanged();
         x.EnableServiceRecovery(r => { r.RestartService(1); });
         x.SetDescription("The server that powers Ulterius"); //7
         x.SetDisplayName("Ulterius Server");                 //8
         x.SetServiceName("UlteriusServer");                  //9
         x.StartAutomaticallyDelayed();
     });
 }
Esempio n. 2
0
        static void Main(string[] ars)
        {
            WardenManager.Logger = new WardenLogger();
            WardenManager.OnUntrackedProcessAdded += WardenManagerOnOnUntrackedProcessAdded;
            WardenManager.Initialize(new WardenOptions
            {
                CleanOnExit = true,
                DeepKill = true,
                PollingInterval = TimeSpan.FromSeconds(1)
            });

            Console.WriteLine("Start notepad");
           /* var wardenTest = WardenProcess.StartUwp(new WardenStartInfo
            {
                PackageFamilyName = "Microsoft.MinecraftUWP_8wekyb3d8bbwe",
                ApplicationId = "App"
            });*/

           var cancel = new CancellationTokenSource();
           cancel.CancelAfter(TimeSpan.FromSeconds(10));
           var wardenTest = WardenProcess.StartUriDeferred(new WardenStartInfo
           {
               FileName = "steam://run/107410",
               TargetFileName = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Arma 3\\arma3launcher.exe"
           }, delegate(bool b)
           {
               Console.WriteLine($"Alive! {b}");
           });

            if (wardenTest != null)
            {
              

                Console.WriteLine($"Hello {wardenTest.Id}");
                wardenTest.OnStateChange += delegate (object sender, StateEventArgs args)
                {
                    Console.WriteLine($"---\nName: {wardenTest.Name}\nId: {wardenTest.Id}\nstate changed to {args.State}\n---");
                    if (!wardenTest.IsTreeActive())
                    {
                        Console.WriteLine("We're gone!");
                        Environment.Exit(0);
                    }
                };

                wardenTest.OnProcessAdded += delegate(object sender, ProcessAddedEventArgs args)
                {
                  Console.WriteLine($"Added process {args.ProcessPath} to {args.ParentId}");
                };

                wardenTest.OnChildStateChange += delegate(object sender, StateEventArgs args)
                {
                    var childInfo = wardenTest.FindChildById(args.Id);
                    if (childInfo != null)
                    {
                        Console.WriteLine($"---\nName: {childInfo.Name}\nId: {childInfo.Id}\nParentId:{childInfo.ParentId}\nstated changed to {args.State}\n---");
                    }
                };
            }
            Console.ReadKey(true);
        }
Esempio n. 3
0
        private static async Task Start()
        {
            WardenManager.Initialize();
            Console.Write("Enter the process ID: ");
            var processId = int.Parse(Console.ReadLine());
            var test      = WardenProcess.GetProcessFromId(processId);

            test.OnProcessAdded += delegate(object sender, ProcessAddedEventArgs args)
            {
                if (args.ParentId == test.Id)
                {
                    Console.WriteLine($"Added child {args.Name}({args.Id}) to root process {test.Name}({test.Id})");
                }
                else
                {
                    var parentInfo = test.FindChildById(args.ParentId);
                    if (parentInfo != null)
                    {
                        Console.WriteLine($"Added child process {args.Name}({args.Id}) to child {parentInfo.Name}({parentInfo.Id})");
                    }
                }
            };
            test.OnStateChange += delegate(object sender, StateEventArgs args)
            {
                Console.WriteLine($"---\nName: {test.Name}\nId: {test.Id}\nstate changed to {args.State}\n---");
            };
            test.OnChildStateChange += delegate(object sender, StateEventArgs args)
            {
                var childInfo = test.FindChildById(args.Id);
                if (childInfo != null)
                {
                    Console.WriteLine($"---\nName: {childInfo.Name}\nId: {childInfo.Id}\nParentId:{childInfo.ParentId}\nstated changed to {args.State}\n---");
                }
            };
            Console.WriteLine($"Hooked into {test.Name}({test.Id})");
            Console.Read();
            Console.WriteLine("Start notepad");
            var wardenTest = await WardenProcess.Start("notepad.exe", string.Empty, ProcessTypes.Win32);

            if (wardenTest != null)
            {
                wardenTest.OnStateChange += delegate(object sender, StateEventArgs args)
                {
                    Console.WriteLine($"---\nName: {wardenTest.Name}\nId: {wardenTest.Id}\nstate changed to {args.State}\n---");
                };
            }
            Console.ReadKey(true);
        }
Esempio n. 4
0
        public async void WardenGetsTestProcessInformation()
        {
            WardenManager.Initialize();
            var testProcess = await WardenProcess.Start("TestProcess.exe", string.Empty, ProcessTypes.Win32);

            var children = testProcess.Children.ToArray();

            testProcess.OnChildStateChange += TestProcessOnOnChildStateChange;
            await Task.Delay(5000);

            Assert.NotEmpty(testProcess.Children);
            testProcess.Kill();
            await Task.Delay(2000);

            Assert.True(testProcess.State == ProcessState.Dead);
        }
Esempio n. 5
0
        private static async Task Start()
        {
            WardenManager.Initialize(new WardenOptions
            {
                CleanOnExit     = true,
                DeepKill        = true,
                ReadFileHeaders = true
            });
            Console.Write("Enter the process ID: ");
            var processId = int.Parse(Console.ReadLine());
            var test      = WardenProcess.GetProcessFromId(processId);

            if (test != null)
            {
                test.OnProcessAdded += delegate(object sender, ProcessAddedEventArgs args)
                {
                    if (args.ParentId == test.Id)
                    {
                        Console.WriteLine($"Added child {args.Name}({args.Id}) to root process {test.Name}({test.Id})");
                    }
                    else
                    {
                        var parentInfo = test.FindChildById(args.ParentId);
                        if (parentInfo != null)
                        {
                            Console.WriteLine($"Added child process {args.Name}({args.Id}) to child {parentInfo.Name}({parentInfo.Id})");
                        }
                    }
                };
                test.OnStateChange += delegate(object sender, StateEventArgs args)
                {
                    Console.WriteLine($"---\nName: {test.Name}\nId: {test.Id}\nstate changed to {args.State}\n---");
                };
                test.OnChildStateChange += delegate(object sender, StateEventArgs args)
                {
                    var childInfo = test.FindChildById(args.Id);
                    if (childInfo != null)
                    {
                        Console.WriteLine($"---\nName: {childInfo.Name}\nId: {childInfo.Id}\nParentId:{childInfo.ParentId}\nstated changed to {args.State}\n---");
                    }
                };
                Console.WriteLine($"Hooked into {test.Name}({test.Id})");
                Console.Read();
                Console.WriteLine(JsonConvert.SerializeObject(test, Formatting.Indented));
                test.Kill();
            }



            Console.WriteLine("Start notepad");
            var wardenTest = await WardenProcess.Start("notepad", string.Empty, null);

            if (wardenTest != null)
            {
                wardenTest.OnStateChange += delegate(object sender, StateEventArgs args)
                {
                    Console.WriteLine($"---\nName: {wardenTest.Name}\nId: {wardenTest.Id}\nstate changed to {args.State}\n---");
                };
            }
            Console.ReadKey(true);
        }
Esempio n. 6
0
 public TestWardenOnTestProcess()
 {
     WardenManager.Initialize(true);
     _currentProcess = WardenProcess.GetProcessFromId(Process.GetCurrentProcess().Id);
 }