-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NotEnoughAV1Encodes | ||
{ | ||
class suspend | ||
{ | ||
[Flags] | ||
public enum ThreadAccess : int | ||
{ | ||
TERMINATE = (0x0001), | ||
SUSPEND_RESUME = (0x0002), | ||
GET_CONTEXT = (0x0008), | ||
SET_CONTEXT = (0x0010), | ||
SET_INFORMATION = (0x0020), | ||
QUERY_INFORMATION = (0x0040), | ||
SET_THREAD_TOKEN = (0x0080), | ||
IMPERSONATE = (0x0100), | ||
DIRECT_IMPERSONATION = (0x0200) | ||
} | ||
|
||
[DllImport("kernel32.dll")] | ||
static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId); | ||
[DllImport("kernel32.dll")] | ||
static extern uint SuspendThread(IntPtr hThread); | ||
[DllImport("kernel32.dll")] | ||
static extern int ResumeThread(IntPtr hThread); | ||
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] | ||
static extern bool CloseHandle(IntPtr handle); | ||
|
||
|
||
public static void SuspendProcess(int pid) | ||
{ | ||
var process = Process.GetProcessById(pid); // throws exception if process does not exist | ||
|
||
foreach (ProcessThread pT in process.Threads) | ||
{ | ||
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); | ||
|
||
if (pOpenThread == IntPtr.Zero) | ||
{ | ||
continue; | ||
} | ||
|
||
SuspendThread(pOpenThread); | ||
|
||
CloseHandle(pOpenThread); | ||
} | ||
} | ||
|
||
public static void ResumeProcess(int pid) | ||
{ | ||
var process = Process.GetProcessById(pid); | ||
|
||
if (process.ProcessName == string.Empty) | ||
return; | ||
|
||
foreach (ProcessThread pT in process.Threads) | ||
{ | ||
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); | ||
|
||
if (pOpenThread == IntPtr.Zero) | ||
{ | ||
continue; | ||
} | ||
|
||
var suspendCount = 0; | ||
do | ||
{ | ||
suspendCount = ResumeThread(pOpenThread); | ||
} while (suspendCount > 0); | ||
|
||
CloseHandle(pOpenThread); | ||
} | ||
} | ||
} | ||
} |