Esempio n. 1
0
        public void Dispose()
        {
            if (bw != null)
            {
                bw.ProgressChanged -= _registeredProgressCallback;
                bw.CancelAsync();
                bw = null;
            }

            if (_unloadOnExit)
            {
                // Unload the DLL from any still running instance
                HashSet <uint> pids = FindProcesses(_exitArguments);
                foreach (uint pid in _pidModuleHandleMap.Keys)
                {
                    if (pids.Contains(pid))
                    {
                        if (DllInjector.UnloadDll(pid, _pidModuleHandleMap[pid]))
                        {
                            Logger.InfoFormat("Unloaded module from pid {0}", pid);
                        }
                        else
                        {
                            Logger.InfoFormat("Failed to unload module from pid {0}", pid);
                        }
                    }
                }
            }
            else
            {
                Logger.Info("Exiting without unloading DLL (as per configuration)");
            }
        }
Esempio n. 2
0
 private bool Is64Bit(int pid)
 {
     try {
         var p = System.Diagnostics.Process.GetProcessById(pid);
         return(DllInjector.Is64BitProcess(p));
     }
     catch (ArgumentException) {
         return(false);
     }
 }
Esempio n. 3
0
 private HashSet <uint> FindProcesses(RunArguments args)
 {
     if (!string.IsNullOrEmpty(args.WindowName))
     {
         return(DllInjector.FindProcessForWindow(args.WindowName));
     }
     else
     {
         throw new NotSupportedException("Class name provided instead of window name, not yet implemented.");
     }
 }
Esempio n. 4
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;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
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
                            {
                                Logger.Warn("Grim Dawn is running as 32bit, sometime in the future 32bit support in IA will be removed.");
                                DllInjector.NewInject(pid, dll32Bit);
                                // Inject32Bit("Grim Dawn.exe", dll32Bit);


                                if (!InjectionVerifier.VerifyInjection(pid, dll32Bit))
                                {
                                    worker.ReportProgress(INJECTION_ERROR, null);
                                }
                            }
                        }
                    }
                }
            }
        }