Exemplo n.º 1
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var process = ViewModel.ApplicationViewModel.SelectedProcess;

            if (!process.HasExited)
            {
                var injector = new ApplicationInjector(ViewModel.ApplicationViewModel.SelectedProcess);
                injector.Inject();

                // Exit page.
                ViewModel.ApplicationViewModel.ChangeApplicationPage(Enum.ApplicationSubPage.ReloadedProcess);
            }
        }
Exemplo n.º 2
0
 /* Implementation */
 private void ProcessWatcherOnOnNewProcess(Process newProcess)
 {
     try
     {
         string fullPath = newProcess.GetExecutablePath();
         var    config   = _configService.Items.FirstOrDefault(x => string.Equals(ApplicationConfig.GetAbsoluteAppLocation(x), fullPath, StringComparison.OrdinalIgnoreCase));
         if (config != null && config.Config.AutoInject)
         {
             var appInjector = new ApplicationInjector(newProcess);
             appInjector.Inject();
         }
     }
     catch (Exception)
     {
         // Ignored
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// Starts the application, injecting Reloaded into it.
    /// </summary>
    public void Start()
    {
        // Start up the process
        Native.STARTUPINFO         startupInfo         = new Native.STARTUPINFO();
        Native.SECURITY_ATTRIBUTES lpProcessAttributes = new Native.SECURITY_ATTRIBUTES();
        Native.SECURITY_ATTRIBUTES lpThreadAttributes  = new Native.SECURITY_ATTRIBUTES();
        Native.PROCESS_INFORMATION processInformation  = new Native.PROCESS_INFORMATION();

        if (_arguments == null)
        {
            _arguments = "";
        }

        bool success = Native.CreateProcessW(null, $"\"{_location}\" {_arguments}", ref lpProcessAttributes,
                                             ref lpThreadAttributes, false, Native.ProcessCreationFlags.CREATE_SUSPENDED,
                                             IntPtr.Zero, Path.GetDirectoryName(_location) !, ref startupInfo, ref processInformation);

        if (!success)
        {
            string windowsErrorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
            throw new ArgumentException($"{Resources.ErrorFailedToStartProcess.Get()} {windowsErrorMessage}");
        }

        // DLL Injection
        var process  = Process.GetProcessById((int)processInformation.dwProcessId);
        var injector = new ApplicationInjector(process);

        try
        {
            injector.Inject();
        }
        catch (Exception)
        {
            Native.ResumeThread(processInformation.hThread);
            throw;
        }

        Native.ResumeThread(processInformation.hThread);
    }