private static extern int NtQueryInformationProcess( IntPtr processHandle, int processInformationClass, ref NativeProcessUtils processInformation, int processInformationLength, out int returnLength );
/// <summary> /// Gets the parent process of a specified process. /// </summary> /// <param name="handle">The process handle.</param> /// <returns>An instance of the Process class.</returns> public static int GetParentPID(IntPtr handle) { NativeProcessUtils pbi = new NativeProcessUtils(); int returnLength; int status = NtQueryInformationProcess(handle, 0, ref pbi, Marshal.SizeOf(pbi), out returnLength); if (status != 0) { return(-1); } return(pbi.InheritedFromUniqueProcessId.ToInt32()); }
private async Task TimeoutWatcher(int timeout) {// workhorse for our timer delegates Stopwatch sw = Stopwatch.StartNew(); double lastTime = sw.ElapsedMilliseconds, elapsedTimer = 0; while (!TimeoutCancelled && elapsedTimer < timeout * 1000) { await Task.Delay(Interval); elapsedTimer += sw.ElapsedMilliseconds - lastTime; lastTime = sw.ElapsedMilliseconds; bool _isRunning = IsRunning(); if (HasAcquired && _isRunning) { sw.Restart(); return; // bail while process is healthy } else if (!HasAcquired && _isRunning) { OnProcessAcquired(this, new ProcessEventArgs { TargetProcess = TargetLauncher.ProcWrapper.Proc, ProcessName = NativeProcessUtils.GetProcessModuleName(TargetLauncher.ProcWrapper.Proc.Id), ProcessType = TargetLauncher.ProcWrapper.ProcessType, Elapsed = elapsedTimer, AvoidPID = TargetLauncher.ProcWrapper.Proc.Id }); return; } else if (HasAcquired && !_isRunning) { OnProcessSoftExit(this, new ProcessEventArgs { TargetProcess = TargetLauncher.ProcWrapper.Proc, ProcessName = TargetLauncher.ProcWrapper.ProcessName ?? TargetLauncher.MonitorName, Timeout = timeout }); } } // timed out (check for fresh running - wait till next iteration) if (!TimeoutCancelled && !IsRunning()) { OnProcessHardExit(this, new ProcessEventArgs { TargetProcess = TargetLauncher.ProcWrapper.Proc, ProcessName = TargetLauncher.ProcWrapper.ProcessName ?? TargetLauncher.MonitorName, Elapsed = elapsedTimer, Timeout = timeout }); } }
public static int DetectWindowType(Process proc) { int result = -1; if (proc != null) { var _hWnd = GetHWND(proc); string haystack = NativeProcessUtils.GetProcessModuleName(proc.Id); if (_hWnd != IntPtr.Zero) { // excluded windows if (ProcessUtils.OrdinalContains("EasyAntiCheat_launcher", haystack)) { return(-1); } // initially try to resolve by looking up className and windowTitle if (MatchWindowDetails("Epic Games Launcher", "UnrealWindow", _hWnd)) { result = 4; // Epic Games Launcher [Type 4] } else if (MatchWindowDetails("Uplay", "uplay_main", _hWnd)) { result = 3; // Uplay [Type 3] } else if (MatchWindowDetails("Origin", "Qt5QWindowIcon", _hWnd)) { result = 2; // Origin [Type 2] } else if (MatchWindowDetails("Blizzard Battle.net", "Qt5QWindowOwnDCIcon", _hWnd)) { result = 1; // Blizzard Battle.net [Type 1] } else if (WindowHasDetails(_hWnd) || IsWindow(_hWnd)) { result = 0; // catch all other obvious windows } if (result > -1) { return(result); } } // fallback to detection by module name if (ProcessUtils.OrdinalContains("EpicGamesLauncher", haystack)) { result = 4; } else if (ProcessUtils.OrdinalContains("upc", haystack)) { result = 3; } else if (ProcessUtils.OrdinalContains("Origin", haystack)) { result = 2; } else if (ProcessUtils.OrdinalContains("Battle.net", haystack)) { result = 1; } } return(result); }