├── MiniTerm
├── App.config
├── PseudoConsole.cs
├── Properties
│ └── AssemblyInfo.cs
├── MiniTerm.csproj
├── Program.cs
├── Terminal.cs
├── Process.cs
└── NativeApi.cs
├── README.md
├── LICENSE
├── MiniTerm.sln
├── .gitattributes
└── .gitignore
/MiniTerm/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/MiniTerm/PseudoConsole.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32.SafeHandles;
2 | using System;
3 | using static MiniTerm.NativeApi;
4 |
5 | namespace MiniTerm
6 | {
7 | ///
8 | /// Utility functions around the new Pseudo Console APIs
9 | ///
10 | static class PseudoConsole
11 | {
12 | internal static IntPtr CreatePseudoConsole(SafeFileHandle inputReadSide, SafeFileHandle outputWriteSide)
13 | {
14 | var createResult = NativeApi.CreatePseudoConsole(new COORD { X = 100, Y = 100 }, inputReadSide, outputWriteSide, 0, out IntPtr hPC);
15 | if(createResult != 0)
16 | {
17 | throw new InvalidOperationException("Could not create psuedo console. Error Code " + createResult);
18 | }
19 | return hPC;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MiniTerm
2 |
3 | Experimental terminal using the new PTY APIs from Microsoft. Written in C#, and heavily based on the native code examples.
4 |
5 | **EDIT: All development has been moved to [my fork of microsoft/console](https://github.com/waf/console/tree/add-csharp-conpty-sample). It will soon result in a PR to that repo.**
6 |
7 | ## Status
8 |
9 | Buggy proof-of-concept. Demonstrates the basic API calls required.
10 |
11 | ## Resources
12 |
13 | - [Introductory blog post from Microsoft](https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/)
14 | - [MSDN Documentation](https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session)
15 |
16 | ## System Requirements
17 |
18 | See the Introductory blog post from Microsoft for the full setup instructions. This project has been tested with:
19 |
20 | - OS: Windows 10 Pro Build 17744
21 | - SDK: Windows_InsiderPreview_SDK_en-us_17749
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Will Fuqua
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MiniTerm.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2035
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniTerm", "MiniTerm\MiniTerm.csproj", "{121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {EFB13BDE-C952-4311-9FE7-35EFDAC8F021}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/MiniTerm/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MiniPty")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MiniPty")]
13 | [assembly: AssemblyCopyright("Copyright © 2018")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("121d4818-bd57-433b-8ad5-c4e1ace7e7c0")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/MiniTerm/MiniTerm.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {121D4818-BD57-433B-8AD5-C4E1ACE7E7C0}
8 | Exe
9 | MiniPty
10 | MiniPty
11 | v4.7.2
12 | 512
13 | true
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/MiniTerm/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32.SafeHandles;
2 | using System;
3 | using System.Threading.Tasks;
4 | using static MiniTerm.NativeApi;
5 |
6 | namespace MiniTerm
7 | {
8 | ///
9 | /// C# version of:
10 | /// https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/
11 | /// https://docs.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session
12 | ///
13 | /// System Requirements:
14 | /// As of September 2018, requires Windows 10 with the "Windows Insider Program" installed for Redstone 5.
15 | /// Also requires the Windows Insider Preview SDK: https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK
16 | ///
17 | static class Program
18 | {
19 | static void Main(string[] args)
20 | {
21 | try
22 | {
23 | // newer versions of the windows console support interpreting virtual terminal sequences, we just have to opt-in
24 | Terminal.EnableVirtualTerminalSequenceProcessing();
25 |
26 | RunTerminal();
27 | }
28 | catch (InvalidOperationException e)
29 | {
30 | Console.Error.WriteLine(e.Message);
31 | throw;
32 | }
33 | }
34 |
35 | private static void RunTerminal()
36 | {
37 | if (!CreatePipe(out SafeFileHandle inputReadSide, out SafeFileHandle inputWriteSide, IntPtr.Zero, 0))
38 | {
39 | throw new InvalidOperationException("failed to create input pipe");
40 | }
41 | if (!CreatePipe(out SafeFileHandle outputReadSide, out SafeFileHandle outputWriteSide, IntPtr.Zero, 0))
42 | {
43 | throw new InvalidOperationException("failed to create output pipe");
44 | }
45 |
46 | // set up a background task to copy all pseudo console output to stdout
47 | Task.Run(() => Terminal.CopyPipeToOutput(outputReadSide));
48 |
49 | IntPtr hPC = PseudoConsole.CreatePseudoConsole(inputReadSide, outputWriteSide);
50 | var process = Process.Start(hPC, "cmd.exe", (IntPtr)PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE);
51 |
52 | // prompt for stdin input and send the result to the pipe.
53 | // blocks until the user types "exit"
54 | Terminal.CopyInputToPipe(inputWriteSide);
55 |
56 | Process.CleanUp(process);
57 | ClosePseudoConsole(hPC);
58 | inputReadSide.Dispose();
59 | inputWriteSide.Dispose();
60 | outputReadSide.Dispose();
61 | outputWriteSide.Dispose();
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/MiniTerm/Terminal.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32.SafeHandles;
2 | using System;
3 | using System.IO;
4 | using static MiniTerm.NativeApi;
5 |
6 | namespace MiniTerm
7 | {
8 | ///
9 | /// The UI of the terminal. It's just a normal console window, but we're managing the input/output.
10 | /// In a "real" project this could be some other UI.
11 | ///
12 | static class Terminal
13 | {
14 | public static void EnableVirtualTerminalSequenceProcessing()
15 | {
16 | var iStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
17 | if (!GetConsoleMode(iStdOut, out uint outConsoleMode))
18 | {
19 | throw new InvalidOperationException("Could not get console mode");
20 | }
21 |
22 | outConsoleMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN;
23 | if (!SetConsoleMode(iStdOut, outConsoleMode))
24 | {
25 | throw new InvalidOperationException("Could not enable virtual terminal processing");
26 | }
27 | }
28 |
29 | public static void CopyInputToPipe(SafeFileHandle inputWriteSide)
30 | {
31 | using (var writer = new StreamWriter(new FileStream(inputWriteSide, FileAccess.Write)))
32 | {
33 | writer.AutoFlush = true;
34 | writer.WriteLine(@"cd \");
35 |
36 | while (true)
37 | {
38 | string input = Console.ReadLine();
39 | if (input == "exit")
40 | {
41 | break;
42 | }
43 |
44 | writer.WriteLine(input);
45 | }
46 | }
47 | }
48 |
49 | public static void CopyPipeToOutput(SafeFileHandle outputReadSide)
50 | {
51 | var consoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
52 | const int bufferSize = 512;
53 | byte[] buffer = new byte[bufferSize];
54 |
55 | bool read;
56 | uint lpNumberOfBytesRead;
57 | do
58 | {
59 | read = ReadFile(outputReadSide, buffer, bufferSize, out lpNumberOfBytesRead, IntPtr.Zero);
60 | WriteFile(consoleOut, buffer, lpNumberOfBytesRead, out uint lpNumberOfBytesWritten, IntPtr.Zero);
61 | } while (read && lpNumberOfBytesRead > 0);
62 |
63 | consoleOut.Dispose();
64 | // the above could be replaced by something like the following, where terminalOutput is from Console.OpenStandardOutput()
65 | // but the original C++ version said:
66 | // > Note: Write to the Console using WriteFile(hConsole...), not printf()/puts() to
67 | // > prevent partially-read VT sequences from corrupting output
68 | //using (var pseudoConsoleOutput = new FileStream(outputReadSide, FileAccess.Read))
69 | //{
70 | // pseudoConsoleOutput.CopyTo(terminalOutput);
71 | //}
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/MiniTerm/Process.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using static MiniTerm.NativeApi;
4 |
5 | namespace MiniTerm
6 | {
7 | ///
8 | /// Support for starting and configuring processes.
9 | ///
10 | ///
11 | /// Possible to replace with managed code? The key is being able to provide the PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE attribute
12 | ///
13 | static class Process
14 | {
15 | ///
16 | /// Start and configure a process. The return value should be send to
17 | ///
18 | ///
19 | ///
20 | ///
21 | ///
22 | internal static (STARTUPINFOEX, PROCESS_INFORMATION) Start(IntPtr hPC, string command, IntPtr attributes)
23 | {
24 | var startupInfo = ConfigureProcessThread(hPC, attributes);
25 | var processInfo = RunProcess(ref startupInfo, "cmd.exe");
26 | return (startupInfo, processInfo);
27 | }
28 |
29 | private static STARTUPINFOEX ConfigureProcessThread(IntPtr hPC, IntPtr attributes)
30 | {
31 | var startupInfo = new STARTUPINFOEX();
32 | startupInfo.StartupInfo.cb = Marshal.SizeOf(startupInfo);
33 | var lpSize = IntPtr.Zero;
34 | startupInfo.lpAttributeList = Marshal.AllocHGlobal(lpSize);
35 |
36 | var success = InitializeProcThreadAttributeList(IntPtr.Zero, 1, 0, ref lpSize);
37 | if (success || lpSize == IntPtr.Zero)
38 | {
39 | throw new InvalidOperationException("Could not calculate the number of bytes for the attribute list. " + Marshal.GetLastWin32Error());
40 | }
41 |
42 | success = InitializeProcThreadAttributeList(startupInfo.lpAttributeList, 1, 0, ref lpSize);
43 | if (!success)
44 | {
45 | throw new InvalidOperationException("Could not set up attribute list. " + Marshal.GetLastWin32Error());
46 | }
47 |
48 | success = UpdateProcThreadAttribute(
49 | startupInfo.lpAttributeList,
50 | 0,
51 | attributes,
52 | hPC,
53 | (IntPtr)IntPtr.Size,
54 | IntPtr.Zero,
55 | IntPtr.Zero);
56 | if (!success)
57 | {
58 | throw new InvalidOperationException("Could not set pseudoconsole thread attribute. " + Marshal.GetLastWin32Error());
59 | }
60 |
61 | return startupInfo;
62 | }
63 |
64 | private static PROCESS_INFORMATION RunProcess(ref STARTUPINFOEX sInfoEx, string commandLine)
65 | {
66 | PROCESS_INFORMATION pInfo;
67 | var pSec = new SECURITY_ATTRIBUTES();
68 | pSec.nLength = Marshal.SizeOf(pSec);
69 | var tSec = new SECURITY_ATTRIBUTES();
70 | tSec.nLength = Marshal.SizeOf(tSec);
71 | var result = CreateProcess(null, commandLine, ref pSec, ref tSec, false, EXTENDED_STARTUPINFO_PRESENT, IntPtr.Zero, null, ref sInfoEx, out pInfo);
72 | if (!result)
73 | {
74 | throw new InvalidOperationException("Could not create process. " + Marshal.GetLastWin32Error());
75 | }
76 |
77 | return pInfo;
78 | }
79 |
80 | public static void CleanUp((STARTUPINFOEX, PROCESS_INFORMATION) process)
81 | {
82 | var (startupInfo, processInfo) = process;
83 |
84 | // Free the attribute list
85 | if (startupInfo.lpAttributeList != IntPtr.Zero)
86 | {
87 | DeleteProcThreadAttributeList(startupInfo.lpAttributeList);
88 | Marshal.FreeHGlobal(startupInfo.lpAttributeList);
89 | }
90 |
91 | // Close process and thread handles
92 | if (processInfo.hProcess != IntPtr.Zero)
93 | {
94 | CloseHandle(processInfo.hProcess);
95 | }
96 | if (processInfo.hThread != IntPtr.Zero)
97 | {
98 | CloseHandle(processInfo.hThread);
99 | }
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/MiniTerm/NativeApi.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Win32.SafeHandles;
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace MiniTerm
6 | {
7 | static class NativeApi
8 | {
9 | internal const uint PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE = 0x00020016;
10 | internal const uint EXTENDED_STARTUPINFO_PRESENT = 0x00080000;
11 |
12 | internal const int STD_OUTPUT_HANDLE = -11;
13 | internal const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
14 | internal const uint DISABLE_NEWLINE_AUTO_RETURN = 0x0008;
15 |
16 | [StructLayout(LayoutKind.Sequential)]
17 | internal struct COORD
18 | {
19 | internal short X;
20 | internal short Y;
21 | }
22 |
23 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
24 | internal struct STARTUPINFOEX
25 | {
26 | internal STARTUPINFO StartupInfo;
27 | internal IntPtr lpAttributeList;
28 | }
29 |
30 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
31 | internal struct STARTUPINFO
32 | {
33 | internal Int32 cb;
34 | internal string lpReserved;
35 | internal string lpDesktop;
36 | internal string lpTitle;
37 | internal Int32 dwX;
38 | internal Int32 dwY;
39 | internal Int32 dwXSize;
40 | internal Int32 dwYSize;
41 | internal Int32 dwXCountChars;
42 | internal Int32 dwYCountChars;
43 | internal Int32 dwFillAttribute;
44 | internal Int32 dwFlags;
45 | internal Int16 wShowWindow;
46 | internal Int16 cbReserved2;
47 | internal IntPtr lpReserved2;
48 | internal IntPtr hStdInput;
49 | internal IntPtr hStdOutput;
50 | internal IntPtr hStdError;
51 | }
52 |
53 | [StructLayout(LayoutKind.Sequential)]
54 | internal struct PROCESS_INFORMATION
55 | {
56 | internal IntPtr hProcess;
57 | internal IntPtr hThread;
58 | internal int dwProcessId;
59 | internal int dwThreadId;
60 | }
61 |
62 | [StructLayout(LayoutKind.Sequential)]
63 | internal struct SECURITY_ATTRIBUTES
64 | {
65 | internal int nLength;
66 | internal IntPtr lpSecurityDescriptor;
67 | internal int bInheritHandle;
68 | }
69 |
70 | [DllImport("kernel32.dll", SetLastError = true)]
71 | internal static extern SafeFileHandle GetStdHandle(int nStdHandle);
72 |
73 | [DllImport("kernel32.dll", SetLastError = true)]
74 | internal static extern bool SetConsoleMode(SafeFileHandle hConsoleHandle, uint mode);
75 |
76 | [DllImport("kernel32.dll", SetLastError = true)]
77 | internal static extern bool GetConsoleMode(SafeFileHandle handle, out uint mode);
78 |
79 | [DllImport("kernel32.dll", SetLastError = true)]
80 | internal static extern int CreatePseudoConsole(COORD size, SafeFileHandle hInput, SafeFileHandle hOutput, uint dwFlags, out IntPtr phPC);
81 |
82 | [DllImport("kernel32.dll", SetLastError = true)]
83 | internal static extern int CreatePseudoConsole(COORD size, IntPtr hInput, IntPtr hOutput, uint dwFlags, out IntPtr phPC);
84 |
85 | [DllImport("kernel32.dll", SetLastError = true)]
86 | internal static extern int ResizePseudoConsole(IntPtr hPC, COORD size);
87 |
88 | [DllImport("kernel32.dll", SetLastError = true)]
89 | internal static extern int ClosePseudoConsole(IntPtr hPC);
90 |
91 | [DllImport("kernel32.dll", SetLastError = true)]
92 | [return: MarshalAs(UnmanagedType.Bool)]
93 | internal static extern bool InitializeProcThreadAttributeList(
94 | IntPtr lpAttributeList, int dwAttributeCount, int dwFlags, ref IntPtr lpSize);
95 |
96 | [DllImport("kernel32.dll", SetLastError = true)]
97 | [return: MarshalAs(UnmanagedType.Bool)]
98 | internal static extern bool UpdateProcThreadAttribute(
99 | IntPtr lpAttributeList, uint dwFlags, IntPtr Attribute, IntPtr lpValue,
100 | IntPtr cbSize, IntPtr lpPreviousValue, IntPtr lpReturnSize);
101 |
102 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
103 | internal static extern bool CreatePipe(ref IntPtr hReadPipe, ref IntPtr hWritePipe, IntPtr lpPipeAttributes, int nSize);
104 |
105 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
106 | internal static extern bool CreatePipe(out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, IntPtr lpPipeAttributes, int nSize);
107 |
108 | [DllImport("kernel32.dll", SetLastError = true)]
109 | internal static extern bool ReadFile(IntPtr hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr lpOverlapped);
110 | [DllImport("kernel32.dll", SetLastError = true)]
111 | internal static extern bool ReadFile(SafeFileHandle hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, IntPtr lpOverlapped);
112 |
113 | [DllImport("kernel32.dll")]
114 | [return: MarshalAs(UnmanagedType.Bool)]
115 | internal static extern bool WriteFile(SafeFileHandle hFile, byte[] lpBuffer,
116 | uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten,
117 | IntPtr lpOverlapped);
118 |
119 | [DllImport("kernel32.dll")]
120 | [return: MarshalAs(UnmanagedType.Bool)]
121 | internal static extern bool CreateProcess(
122 | string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes,
123 | ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags,
124 | IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFOEX lpStartupInfo,
125 | out PROCESS_INFORMATION lpProcessInformation);
126 |
127 | [DllImport("kernel32.dll", SetLastError = true)]
128 | [return: MarshalAs(UnmanagedType.Bool)]
129 | internal static extern bool DeleteProcThreadAttributeList(IntPtr lpAttributeList);
130 |
131 | [DllImport("kernel32.dll", SetLastError = true)]
132 | internal static extern bool CloseHandle(IntPtr hObject);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------