Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="progressChanged">Callback for errors and notifications</param>
        /// <param name="unloadOnExit">Whetever this DLL should get unloaded on exit</param>
        /// <param name="windowName">Name of the window you wish to inject to</param>
        /// <param name="className">Name of the class you wish to inject to (IFF window name is empty/null)</param>
        /// <param name="dll">Name of the DLL you wish to inject</param>
        public InjectionHelper(BackgroundWorker bw, ProgressChangedEventHandler progressChanged, bool unloadOnExit, string windowName, string className, string dll)
        {
            if (string.IsNullOrEmpty(windowName) && string.IsNullOrEmpty(className))
            {
                throw new ArgumentException("Either window or class name must be specified");
            }
            else if (string.IsNullOrEmpty(dll))
            {
                throw new ArgumentException("DLL name must be specified");
            }

            this._registeredProgressCallback = progressChanged;
            this._unloadOnExit            = unloadOnExit;
            bw.DoWork                    += new DoWorkEventHandler(bw_DoWork);
            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress      = true;
            bw.ProgressChanged           += progressChanged;
            //bw.ProgressChanged += bw_ProgressChanged;

            _exitArguments = new RunArguments {
                WindowName = windowName,
                ClassName  = className,
                DllName    = dll
            };
            bw.RunWorkerAsync(_exitArguments);
        }
Example #2
0
        private static void Main(string[] args)
        {
            RunArguments = new RunArguments();
            RunArguments.ProcessCliArguments(args);

            if (!Environment.UserInteractive)
            {
                if (selfInstaller == null)
                {
                    selfInstaller = new Service();
                }

                var servicesToRun = new ServiceBase[]
                {
                    selfInstaller
                };
                ServiceBase.Run(servicesToRun);
            }
            else
            {
                // running as console app
                Start(args);
                Stop();
                Console.WriteLine("Finished.");
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var options = new RunArguments();

            string invokedVerb        = null;
            object invokerVerbOptions = null;

            var parser = new Parser(settings =>
            {
                settings.HelpWriter             = null;
                settings.IgnoreUnknownArguments = false;
                settings.MutuallyExclusive      = true;
            });

            parser.ParseArgumentsStrict(args, options, (verCommand, verbOptions) =>
            {
                invokedVerb        = verCommand;
                invokerVerbOptions = verbOptions;
            }, () => invokerVerbOptions = null);

            if (string.IsNullOrEmpty(invokedVerb))
            {
                Environment.Exit(Parser.DefaultExitCodeFail);
            }

            using (var scope = BuildIoC())
            {
                BeginNeuSim(scope.Resolve <CommandsContext>(), invokedVerb, invokerVerbOptions);
            }
        }
Example #4
0
        /// <summary>
        /// Pulls and runs an image as a named container.
        /// If a container by this name already exists, it will be stopped and removed
        /// </summary>
        /// <param name="imageName"></param>
        /// <param name="containerName"></param>
        /// <returns></returns>
        public string RunOrReplace(string imageName, string containerName)
        {
            var arguments = new RunArguments
            {
                Name = containerName,
            };

            return(RunOrReplace(imageName, null, arguments));
        }
Example #5
0
 private HashSet <uint> FindProcesses(RunArguments args)
 {
     if (!string.IsNullOrEmpty(args.WindowName))
     {
         return(EvilsoftCommons.DllInjector.DllInjector.FindProcessForWindow(args.WindowName));
     }
     else
     {
         throw new NotSupportedException("Class name provided instead of window name, not yet implemented.");
     }
 }
Example #6
0
        /// <summary>
        /// Runs the specified image in a new container
        /// </summary>
        /// <param name="imageName"></param>
        /// <param name="args"></param>
        /// <param name="tag"></param>
        /// <returns>Newly created container ID</returns>
        public string RunImage(string imageName, string tag, RunArguments args, string command = null)
        {
            var tagArg = tag != null ? $":{tag}" : "";

            using (var process = GetDockerProcess($"run {args.ToArgString()} {imageName}{tagArg} {command}"))
            {
                process.Start();
                process.WaitForExit();
                process.ThrowForError();

                // remove trailing \n
                return(process.StandardOutput.ReadToEnd().TrimEnd());
            }
        }
Example #7
0
        private void Process(BackgroundWorker worker, RunArguments arguments)
        {
            System.Threading.Thread.Sleep(1200);

            HashSet <uint> pids = FindProcesses(arguments);


            if (pids.Count == 0 && _previouslyInjected.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND_ON_STARTUP, null);
            }
            else if (pids.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND, null);
            }



            string dll32Bit = Path.Combine(Directory.GetCurrentDirectory(), arguments.DllName.Replace(".dll", "_x86.dll"));
            string dll64Bit = Path.Combine(Directory.GetCurrentDirectory(), arguments.DllName.Replace(".dll", "_x64.dll"));

            if (!File.Exists(dll32Bit))
            {
                Logger.FatalFormat("Could not find {1} at \"{0}\"", dll32Bit, arguments.DllName);
            }
            else if (!File.Exists(dll64Bit))
            {
                Logger.FatalFormat("Could not find {1} at \"{0}\"", dll64Bit, arguments.DllName);
            }
            else
            {
                foreach (uint pid in pids)
                {
                    if (!_previouslyInjected.Contains(pid))
                    {
                        if (Is64Bit((int)pid))
                        {
                            if (InjectionVerifier.VerifyInjection(pid, dll64Bit))
                            {
                                Logger.Info($"DLL already injected into target process, skipping injection into {pid}");
                                _dontLog.Add(pid);
                                _previouslyInjected.Add(pid);
                            }
                            else
                            {
                                Inject64Bit("Grim Dawn.exe", dll64Bit);

                                if (!InjectionVerifier.VerifyInjection(pid, dll64Bit))
                                {
                                    worker.ReportProgress(INJECTION_ERROR, null);
                                }
                            }
                        }
                        else
                        {
                            if (InjectionVerifier.VerifyInjection(pid, dll32Bit))
                            {
                                Logger.Info($"DLL already injected into target process, skipping injection into {pid}");
                                _dontLog.Add(pid);
                                _previouslyInjected.Add(pid);
                            }
                            else
                            {
                                //DllInjector.NewInject(pid, dll32Bit);
                                Inject32Bit("Grim Dawn.exe", dll32Bit);


                                if (!InjectionVerifier.VerifyInjection(pid, dll32Bit))
                                {
                                    worker.ReportProgress(INJECTION_ERROR, null);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        private void process(BackgroundWorker worker, RunArguments arguments)
        {
            System.Threading.Thread.Sleep(1200);

            HashSet <uint> pids = FindProcesses(arguments);


            if (pids.Count == 0 && _previouslyInjected.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND_ON_STARTUP, null);
            }
            else if (pids.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND, null);
            }

            string dll = Path.Combine(Directory.GetCurrentDirectory(), arguments.DllName);

            if (!File.Exists(dll))
            {
                Logger.FatalFormat("Could not find {1} at \"{0}\"", dll, arguments.DllName);
            }
            else
            {
                foreach (uint pid in pids)
                {
                    if (!_previouslyInjected.Contains(pid))
                    {
                        //DllInjector.adjustDebugPriv(pid);
                        IntPtr remoteModuleHandle = DllInjector.NewInject(pid, dll);
                        if (remoteModuleHandle == IntPtr.Zero)
                        {
                            if (!_dontLog.Contains(pid))
                            {
                                Logger.WarnFormat("Could not inject dll into process {0}, if this is a recurring issue, try running as administrator.", pid);
                                worker.ReportProgress(INJECTION_ERROR, "Could not inject dll into process " + pid);
                            }
                        }
                        else
                        {
                            if (!_dontLog.Contains(pid))
                            {
                                Logger.Info("Injected dll into process " + pid);
                            }

                            if (!InjectionVerifier.VerifyInjection(pid, arguments.DllName))
                            {
                                if (!_dontLog.Contains(pid))
                                {
                                    Logger.Warn("InjectionVerifier reports injection failed.");
                                    ExceptionReporter.ReportIssue("InjectionVerifier reports injection failed into PID " + pid);
                                    worker.ReportProgress(INJECTION_ERROR, string.Format("InjectionVerifier reports injection failed into PID {0}, try running as administrator.", pid));
                                }


                                _dontLog.Add(pid);
                            }
                            else
                            {
                                Logger.Info("InjectionVerifier reports injection succeeded.");
                                _previouslyInjected.Add(pid);
                                _pidModuleHandleMap[pid] = remoteModuleHandle;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="worker"></param>
        /// <param name="arguments"></param>
        private void Process(BackgroundWorker worker, RunArguments arguments)
        {
            Thread.Sleep(1200);

            HashSet <uint> pids = FindProcesses(arguments);

            if (pids.Count == 0 && _previouslyInjected.Count == 0)
            {
                worker.ReportProgress(NoProcessFoundOnStartup, null);
            }
            else if (pids.Count == 0)
            {
                worker.ReportProgress(NoProcessFound, null);
            }

            string dll = Path.Combine(Directory.GetCurrentDirectory(), arguments.DllName);

            if (!File.Exists(dll))
            {
                Logger.Fatal($"Could not find {arguments.DllName} at \"{dll}\"");
                return;
            }

            foreach (uint pid in pids)
            {
                if (_previouslyInjected.Contains(pid))
                {
                    continue;
                }

                IntPtr remoteModuleHandle = DllInjector.NewInject(pid, dll);
                if (remoteModuleHandle == IntPtr.Zero)
                {
                    if (!_dontLog.Contains(pid))
                    {
                        Logger.Warn($"Could not inject dll into process {pid}, if this is a recurring issue, try running as administrator.");
                        worker.ReportProgress(InjectionError, $"Could not inject dll into process {pid}");
                    }

                    continue;
                }

                if (!_dontLog.Contains(pid))
                {
                    Logger.Info("Injected dll into process " + pid);
                }

                if (!InjectionVerifier.VerifyInjection(pid, arguments.DllName))
                {
                    if (!_dontLog.Contains(pid))
                    {
                        Logger.Warn("InjectionVerifier reports injection failed.");
                        worker.ReportProgress(InjectionError, $"InjectionVerifier reports injection failed into PID {pid}, try running as administrator.");
                    }

                    _dontLog.Add(pid);

                    continue;
                }

                Logger.Info("InjectionVerifier reports injection succeeded.");
                _previouslyInjected.Add(pid);
                _pidModuleHandleMap[pid] = remoteModuleHandle;
            }
        }
Example #10
0
        private void Process(BackgroundWorker worker, RunArguments arguments)
        {
            System.Threading.Thread.Sleep(1200);

            HashSet <uint> pids = FindProcesses(arguments);


            if (pids.Count == 0 && _previouslyInjected.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND_ON_STARTUP, null);
            }
            else if (pids.Count == 0)
            {
                worker.ReportProgress(NO_PROCESS_FOUND, null);
            }



            string dll64Bit = Path.Combine(Directory.GetCurrentDirectory(), arguments.DllName.Replace(".dll", "_x64.dll"));

            if (!File.Exists(dll64Bit))
            {
                Logger.FatalFormat("Could not find {1} at \"{0}\"", dll64Bit, arguments.DllName);
            }
            else
            {
                foreach (uint pid in pids)
                {
                    if (!_previouslyInjected.Contains(pid))
                    {
                        if (Is64Bit((int)pid, worker))
                        {
                            if (InjectionVerifier.VerifyInjection(pid, dll64Bit))
                            {
                                Logger.Info($"DLL already injected into target process, skipping injection into {pid}");
                                _dontLog.Add(pid);
                                _previouslyInjected.Add(pid);
                            }
                            else
                            {
                                Inject64Bit("Grim Dawn.exe", dll64Bit, _injectionMethods.GetInjectionMethod());

                                if (!InjectionVerifier.VerifyInjection(pid, dll64Bit))
                                {
                                    Logger.Error($"Error injecting DLL into Grim Dawn. Injection method {_injectionMethods.GetInjectionMethod()}, switching to injetion method {_injectionMethods.GetNextInjectionMethod()}");
                                    _injectionMethods.SwitchInjectionMethod();


                                    worker.ReportProgress(INJECTION_ERROR, null);
                                }
                            }
                        }
                        else
                        {
                            Logger.Fatal("This version of Item Assistant does not support 32bit Grim Dawn");
                            worker.ReportProgress(INJECTION_ERROR_32BIT, null);
                        }
                    }
                    else
                    {
                        worker.ReportProgress(STILL_RUNNING, null);
                    }
                }
            }
        }
Example #11
0
 public string RunOrReplace(string imageName, string tag, RunArguments args, string command = null)
 {
     StopAndRemoveContainer(args.Name);
     PullImage(imageName, tag);
     return(RunImage(imageName, tag, args, command));
 }
Example #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="imageName"></param>
 /// <param name="args"></param>
 /// <returns>Newly created container ID</returns>
 public string RunImage(string imageName, RunArguments args)
 {
     return(RunImage(imageName, null, args));
 }