/// <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()); }
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); }); }
public static void PreloadAddresses() { // Dummy. Static constructor only needed. if (!initialized) { ActionWrappers.TryCatch(() => { x64LoadLibraryAddress = Getx64LoadLibraryAddress(); }); ActionWrappers.TryCatch(() => { x86LoadLibraryAddress = Getx86LoadLibraryAddress(); }); initialized = true; } }
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); } }); } }
private void OnAvailableXamlFilesUpdated(object sender, FileSystemEventArgs e) { ActionWrappers.ExecuteWithApplicationDispatcher(PopulateXamlFiles); }