Skip to content

Commit 3f834c5

Browse files
committed
Added compatibility for .net 2.0
1 parent e827eb1 commit 3f834c5

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

ConPtyShell.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ private static void TryParseRowsColsFromSocket(Socket shellSocket, ref uint rows
178178
}
179179

180180
private static void CreatePipes(ref IntPtr InputPipeRead, ref IntPtr InputPipeWrite, ref IntPtr OutputPipeRead, ref IntPtr OutputPipeWrite){
181-
int securityAttributeSize = Marshal.SizeOf<SECURITY_ATTRIBUTES>();
182-
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES { nLength = securityAttributeSize, bInheritHandle=1, lpSecurityDescriptor=IntPtr.Zero };
181+
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
182+
pSec.nLength = Marshal.SizeOf(pSec);
183+
pSec.bInheritHandle=1;
184+
pSec.lpSecurityDescriptor=IntPtr.Zero;
183185
if(!CreatePipe(out InputPipeRead, out InputPipeWrite, ref pSec, BUFFER_SIZE_PIPE))
184186
throw new InvalidOperationException("Could not create the InputPipe");
185187
if(!CreatePipe(out OutputPipeRead, out OutputPipeWrite, ref pSec, BUFFER_SIZE_PIPE))
@@ -212,7 +214,10 @@ private static void EnableVirtualTerminalSequenceProcessing()
212214
private static int CreatePseudoConsoleWithPipes(ref IntPtr handlePseudoConsole, ref IntPtr ConPtyInputPipeRead, ref IntPtr ConPtyOutputPipeWrite, uint rows, uint cols){
213215
int result = -1;
214216
EnableVirtualTerminalSequenceProcessing();
215-
result = CreatePseudoConsole(new COORD { X = (short)cols, Y = (short)rows }, ConPtyInputPipeRead, ConPtyOutputPipeWrite, 0, out handlePseudoConsole);
217+
COORD consoleCoord = new COORD();
218+
consoleCoord.X=(short)cols;
219+
consoleCoord.Y=(short)rows;
220+
result = CreatePseudoConsole(consoleCoord, ConPtyInputPipeRead, ConPtyOutputPipeWrite, 0, out handlePseudoConsole);
216221
return result;
217222
}
218223

@@ -225,7 +230,7 @@ private static STARTUPINFOEX ConfigureProcessThread(IntPtr handlePseudoConsole,
225230
throw new InvalidOperationException("Could not calculate the number of bytes for the attribute list. " + Marshal.GetLastWin32Error());
226231
}
227232
STARTUPINFOEX startupInfo = new STARTUPINFOEX();
228-
startupInfo.StartupInfo.cb = Marshal.SizeOf<STARTUPINFOEX>();
233+
startupInfo.StartupInfo.cb = Marshal.SizeOf(startupInfo);
229234
startupInfo.lpAttributeList = Marshal.AllocHGlobal(lpSize);
230235
success = InitializeProcThreadAttributeList(startupInfo.lpAttributeList, 1, 0, ref lpSize);
231236
if (!success)
@@ -243,9 +248,11 @@ private static STARTUPINFOEX ConfigureProcessThread(IntPtr handlePseudoConsole,
243248
private static PROCESS_INFORMATION RunProcess(ref STARTUPINFOEX sInfoEx, string commandLine)
244249
{
245250
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
246-
int securityAttributeSize = Marshal.SizeOf<SECURITY_ATTRIBUTES>();
247-
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES { nLength = securityAttributeSize };
248-
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES { nLength = securityAttributeSize };
251+
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
252+
int securityAttributeSize = Marshal.SizeOf(pSec);
253+
pSec.nLength = securityAttributeSize;
254+
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
255+
tSec.nLength = securityAttributeSize;
249256
bool success = CreateProcess(null, commandLine, ref pSec, ref tSec, false, EXTENDED_STARTUPINFO_PRESENT, IntPtr.Zero, null, ref sInfoEx, out pInfo);
250257
if (!success)
251258
{

compile_command.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe -target:exe -optimize -out:ConPtyShell.exe ConPtyShell.cs
1+
.NET 4.0
2+
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe -target:exe -optimize -out:ConPtyShell.exe ConPtyShell.cs
3+
4+
.NET 2.0
5+
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\csc.exe -target:exe -optimize -out:ConPtyShell.exe ConPtyShell.cs

0 commit comments

Comments
 (0)