예제 #1
0
        /// <summary>
        /// Injects the Reloaded bootstrapper into an active process.
        /// </summary>
        /// <exception cref="ArgumentException">DLL Injection failed, likely due to bad DLL or application.</exception>
        public void Inject()
        {
            long handle = _injector.Inject(GetBootstrapperPath(_process));

            if (handle == 0)
            {
                throw new ArgumentException(Errors.DllInjectionFailed());
            }

            // Wait until mod loader loads.
            // If debugging, ignore timeout.
            bool WhileCondition()
            {
                if (CheckRemoteDebuggerPresent(_process.Handle, out var isDebuggerPresent))
                {
                    return(isDebuggerPresent);
                }

                return(false);
            }

            ActionWrappers.TryGetValueWhile(() =>
            {
                // Exit if application crashes while loading Reloaded..
                if (_process.HasExited)
                {
                    return(0);
                }

                return(Client.GetPort((int)_process.Id));
            }, WhileCondition, _xamlModLoaderSetupTimeout.Get(), _xamlModLoaderSetupSleepTime.Get());
        }
예제 #2
0
 private void ApplicationLaunched(object sender, EventArrivedEventArgs e)
 {
     ActionWrappers.TryCatch(() =>
     {
         var processId = Convert.ToInt32(e.NewEvent.Properties[WmiProcessidName].Value);
         var process   = Process.GetProcessById(processId);
         RaiseOnNewProcess(process);
     });
 }
예제 #3
0
 public static void PreloadAddresses()
 {
     // Dummy. Static constructor only needed.
     if (!initialized)
     {
         ActionWrappers.TryCatch(() => { x64LoadLibraryAddress = Getx64LoadLibraryAddress(); });
         ActionWrappers.TryCatch(() => { x86LoadLibraryAddress = Getx86LoadLibraryAddress(); });
         initialized = true;
     }
 }
예제 #4
0
        private void BuildInitialProcesses(CancellationToken token = default)
        {
            var allProcesses = Process.GetProcesses();

            _processes = new HashSet <Process>(allProcesses.Length);

            foreach (var process in allProcesses)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                ActionWrappers.TryCatchDiscard(() =>
                {
                    var processPath = Path.GetFullPath(process.GetExecutablePath());

                    if (string.Equals(processPath, _applicationPath, StringComparison.OrdinalIgnoreCase))
                    {
                        _processes.Add(process);
                    }
                });
            }
        }
예제 #5
0
 private void OnAvailableXamlFilesUpdated(object sender, FileSystemEventArgs e)
 {
     ActionWrappers.ExecuteWithApplicationDispatcher(PopulateXamlFiles);
 }