/// <summary> /// Allocates a console instance to the running process /// </summary> internal static void CreateLoggerInstance() { NativeImport.AllocConsole(); var outFile = NativeImport.CreateFile("CONOUT$", NativeImport.ConsolePropertyModifiers.GENERIC_WRITE | NativeImport.ConsolePropertyModifiers.GENERIC_READ, NativeImport.ConsolePropertyModifiers.FILE_SHARE_WRITE, 0, NativeImport.ConsolePropertyModifiers.OPEN_EXISTING, /*FILE_ATTRIBUTE_NORMAL*/ 0, 0); var safeHandle = new SafeFileHandle(outFile, true); NativeImport.SetStdHandle(-11, outFile); FileStream fs = new FileStream(safeHandle, FileAccess.Write); StreamWriter writer = new StreamWriter(fs) { AutoFlush = true }; Console.SetOut(writer); if (NativeImport.GetConsoleMode(outFile, out var cMode)) { NativeImport.SetConsoleMode(outFile, cMode | 0x0200); } Console.Title = $"Log Window - {Assembly.GetExecutingAssembly().GetName().Name}"; }
public static void SuspendProcess() { var process = Process.GetCurrentProcess(); foreach (ProcessThread pT in process.Threads) { IntPtr pOpenThread = NativeImport.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); if (pOpenThread == IntPtr.Zero) { continue; } NativeImport.SuspendThread(pOpenThread); NativeImport.CloseHandle(pOpenThread); } }
public static void ResumeProcess() { var process = Process.GetCurrentProcess(); foreach (ProcessThread pT in process.Threads) { IntPtr pOpenThread = NativeImport.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); if (pOpenThread == IntPtr.Zero) { continue; } var suspendCount = 0; do { suspendCount = NativeImport.ResumeThread(pOpenThread); } while (suspendCount > 0); NativeImport.CloseHandle(pOpenThread); } }