Beispiel #1
0
		internal static void CheckWriteEdges(SafeFileHandle consoleHandle, uint codePage, Coordinates origin, BufferCell[,] contents, Rectangle contentsRegion, ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo, int firstLeftTrailingRow, int firstRightLeadingRow)
		{
			Rectangle rectangle = new Rectangle(0, 0, 1, contentsRegion.Bottom - contentsRegion.Top);
			if (origin.X != 0)
			{
				BufferCell[,] bufferCellArray = new BufferCell[rectangle.Bottom + 1, 2];
				ConsoleControl.ReadConsoleOutputCJK(consoleHandle, codePage, new Coordinates(origin.X - 1, origin.Y), rectangle, ref bufferCellArray);
				int top = contentsRegion.Top;
				int num = 0;
				while (top <= contentsRegion.Bottom)
				{
					if (!(bufferCellArray[top, 0].BufferCellType == BufferCellType.Leading ^ contents[top, contentsRegion.Left].BufferCellType == BufferCellType.Trailing))
					{
						top++;
						num++;
					}
					else
					{
						object[] left = new object[2];
						left[0] = top;
						left[1] = contentsRegion.Left;
						throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", left));
					}
				}
			}
			else
			{
				if (firstLeftTrailingRow >= 0)
				{
					object[] objArray = new object[2];
					objArray[0] = firstLeftTrailingRow;
					objArray[1] = contentsRegion.Left;
					throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", objArray));
				}
			}
			if (origin.X + contentsRegion.Right - contentsRegion.Left + 1 < bufferInfo.BufferSize.X)
			{
				BufferCell[,] bufferCellArray1 = new BufferCell[rectangle.Bottom + 1, 2];
				ConsoleControl.ReadConsoleOutputCJK(consoleHandle, codePage, new Coordinates(origin.X + contentsRegion.Right - contentsRegion.Left, origin.Y), rectangle, ref bufferCellArray1);
				int top1 = contentsRegion.Top;
				int num1 = 0;
				while (top1 <= contentsRegion.Bottom)
				{
					if (!(bufferCellArray1[top1, 0].BufferCellType == BufferCellType.Leading ^ contents[top1, contentsRegion.Right].BufferCellType == BufferCellType.Leading))
					{
						top1++;
						num1++;
					}
					else
					{
						object[] right = new object[2];
						right[0] = top1;
						right[1] = contentsRegion.Right;
						throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", right));
					}
				}
			}
			else
			{
				if (firstRightLeadingRow >= 0)
				{
					object[] right1 = new object[2];
					right1[0] = firstRightLeadingRow;
					right1[1] = contentsRegion.Right;
					throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]", right1));
				}
			}
		}
 KEY_EVENT_RECORDToKeyInfo(ConsoleControl.KEY_EVENT_RECORD keyEventRecord, out KeyInfo keyInfo)
 {
     keyInfo = new KeyInfo(
         keyEventRecord.VirtualKeyCode,
         keyEventRecord.UnicodeChar,
         (ControlKeyStates)keyEventRecord.ControlKeyState,
         keyEventRecord.KeyDown);
 }
Beispiel #3
0
        /// <summary>
        ///
        /// The break handler for the program.  Dispatches a break event to the current Executor.
        ///
        /// </summary>
        /// <param name="signal"></param>
        /// <returns></returns>
        private static bool MyBreakHandler(ConsoleControl.ConsoleBreakSignal signal)
        {
            switch (signal)
            {
                case ConsoleControl.ConsoleBreakSignal.CtrlBreak:
                    // Break into script debugger.
                    BreakIntoDebugger();
                    return true;

                // Run the break handler...
                case ConsoleControl.ConsoleBreakSignal.CtrlC:
                    SpinUpBreakHandlerThread(false);
                    return true;

                case ConsoleControl.ConsoleBreakSignal.Logoff:
                    // Just ignore the logoff signal. This signal is sent to console
                    // apps running as service anytime *any* user logs off which means
                    // that PowerShell couldn't be used in services/tasks if we didn't
                    // suppress this signal...
                    return true;

                case ConsoleControl.ConsoleBreakSignal.Close:
                case ConsoleControl.ConsoleBreakSignal.Shutdown:
                    SpinUpBreakHandlerThread(true);
                    return false;

                default:
                    // Log as much sqm data as possible before we exit.
                    SpinUpBreakHandlerThread(true);
                    return false;
            }
        }
Beispiel #4
0
		internal static void AddBreakHandler(ConsoleControl.BreakHandler handlerDelegate)
		{
			bool flag = ConsoleControl.NativeMethods.SetConsoleCtrlHandler(handlerDelegate, true);
			if (flag)
			{
				return;
			}
			else
			{
				int lastWin32Error = Marshal.GetLastWin32Error();
				HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "AddBreakHandler", ErrorCategory.ResourceUnavailable, ConsoleControlStrings.AddBreakHandlerExceptionMessage);
				throw hostException;
			}
		}
 GetBufferInfo(out ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo)
 {
     ConsoleHandle result = ConsoleControl.GetActiveScreenBufferHandle();
     bufferInfo = ConsoleControl.GetConsoleScreenBufferInfo(result);
     return result;
 }
Beispiel #6
0
 internal static bool WriteConsoleOutput(IntPtr consoleOutput, ConsoleControl.CHAR_INFO[] buffer, ConsoleControl.COORD bufferSize, ConsoleControl.COORD bufferCoord, ref ConsoleControl.SMALL_RECT writeRegion)
 {
     if (buffer == null) return true;
     var sb = new StringBuilder();
     foreach (var e in buffer)
     {
         sb.Append(Convert.ToChar(e.UnicodeChar));
     }
     Console.Write(sb.ToString());
     return true;
 }
Beispiel #7
0
		internal static void MimicKeyPress(ConsoleControl.INPUT[] inputs)
		{
			int num = ConsoleControl.NativeMethods.SendInput(inputs.Length, inputs, Marshal.SizeOf(typeof(ConsoleControl.INPUT)));
			if (num != 0)
			{
				return;
			}
			else
			{
				int lastWin32Error = Marshal.GetLastWin32Error();
				HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "SendKeyPressInput", ErrorCategory.ResourceUnavailable, ConsoleControlStrings.SendKeyPressInputExceptionTemplate);
				throw hostException;
			}
		}
Beispiel #8
0
			internal static bool ReadConsoleInput (IntPtr consoleInput, ConsoleControl.INPUT_RECORD[] buffer, int length, out int numberOfEventsRead)
			{
				numberOfEventsRead = 0;
				return true;
			}
Beispiel #9
0
			internal static bool ReadConsoleOutput(IntPtr consoleOutput, ConsoleControl.CHAR_INFO[] buffer, ConsoleControl.COORD bufferSize, ConsoleControl.COORD bufferCoord, ref ConsoleControl.SMALL_RECT readRegion)
			{
				return true;
			}
Beispiel #10
0
            /*
			[DllImport("GDI32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool GetTextMetrics(IntPtr hdc, out ConsoleControl.TEXTMETRIC tm);
            */

            internal static bool GetTextMetrics(IntPtr hdc, out ConsoleControl.TEXTMETRIC tm)
            {
                ConsoleControl.TEXTMETRIC rtm = new ConsoleControl.TEXTMETRIC();
                rtm.tmDefaultChar = Char.MinValue;
                tm = rtm;
                return true;
            }
Beispiel #11
0
			internal static bool ReadConsole (IntPtr consoleInput, StringBuilder buffer, int numberOfCharsToRead, out int numberOfCharsRead, ref ConsoleControl.CONSOLE_READCONSOLE_CONTROL controlData)
			{
				getCursor.Invoke (driverObj, null);
				rl_startx.SetValue (driverObj, cursorLeft.GetValue (driverObj));
				rl_starty.SetValue (driverObj, cursorTop.GetValue (driverObj));

				string line = editor.Edit (editor.Prompt, editor.Initial, new ConsoleHistory());
				editor.Initial = "";
				buffer.Append (line);
				if (!line.EndsWith ("\t", StringComparison.OrdinalIgnoreCase))
					buffer.Append ("\r\n");

				numberOfCharsRead = buffer.Length;

				return true;
			}
Beispiel #12
0
			internal static bool GetConsoleScreenBufferInfo(IntPtr consoleHandle, out ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO consoleScreenBufferInfo)
			{
				ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO c = new CONSOLE_SCREEN_BUFFER_INFO();
				c.BufferSize.X = (short)Console.BufferWidth;
				c.BufferSize.Y = (short)Console.BufferHeight;
				c.CursorPosition.X = (short)Console.CursorLeft;
				c.CursorPosition.Y = (short)Console.CursorTop;
				c.MaxWindowSize.X = (short)Console.LargestWindowWidth;
				c.MaxWindowSize.Y = (short)Console.LargestWindowHeight;
				consoleScreenBufferInfo = c;
				return true;
			}
Beispiel #13
0
			internal static bool GetConsoleCursorInfo (IntPtr consoleOutput, out ConsoleControl.CONSOLE_CURSOR_INFO consoleCursorInfo)
			{
				ConsoleControl.CONSOLE_CURSOR_INFO c = new ConsoleControl.CONSOLE_CURSOR_INFO();
				c.Size = Console.CursorSize;
				c.Visible = Console.CursorVisible;
				consoleCursorInfo = c;
				return true;
			}
Beispiel #14
0
			internal static bool FillConsoleOutputCharacter(IntPtr consoleOutput, char character, int length, ConsoleControl.COORD writeCoord, out int numberOfCharsWritten)
			{
				numberOfCharsWritten = length;
				return true;
			}
Beispiel #15
0
			internal static bool SetCurrentConsoleFontEx (IntPtr consoleOutput, bool bMaximumWindow, ref ConsoleControl.CONSOLE_FONT_INFO_EX consoleFontInfo)
			{
				return true;
			}
Beispiel #16
0
			internal static bool ScrollConsoleScreenBuffer(IntPtr consoleOutput, ref ConsoleControl.SMALL_RECT scrollRectangle, ref ConsoleControl.SMALL_RECT clipRectangle, ConsoleControl.COORD destinationOrigin, ref ConsoleControl.CHAR_INFO fill)
			{
				return true;
			}
Beispiel #17
0
			/*
			[DllImport("GDI32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool TranslateCharsetInfo(IntPtr src, out ConsoleControl.CHARSETINFO Cs, uint options);
			*/

			internal static bool TranslateCharsetInfo(IntPtr src, out ConsoleControl.CHARSETINFO Cs, uint options)
			{
				ConsoleControl.CHARSETINFO C = new ConsoleControl.CHARSETINFO();
				C.ciCharset = 255;
				Cs = C;
				return true;
			}
Beispiel #18
0
			internal static int SendInput (int inputNumbers, ConsoleControl.INPUT[] inputs, int sizeOfInput)
			{
				return 0;
			}
Beispiel #19
0
		private static int LengthInBufferCellsFE(char c, ref IntPtr hwnd, ref IntPtr hDC, ref bool istmInitialized, ref ConsoleControl.TEXTMETRIC tm)
		{
			bool textMetrics;
			int num = 0;
			if (32 > c || c > '~')
			{
				if (0x3041 > c || c > '\u3094')
				{
					if (0x30a1 > c || c > '\u30F6')
					{
						if (0x3105 > c || c > '\u312C')
						{
							if (0x3131 > c || c > '\u318E')
							{
								if (0xac00 > c || c > '\uD7A3')
								{
									if (0xff01 > c || c > '~')
									{
										if (0xff61 > c || c > '\uFF9F')
										{
											if ((0xffa0 > c || c > '\uFFBE') && (0xffc2 > c || c > '\uFFC7') && (0xffca > c || c > '\uFFCF') && (0xffd2 > c || c > '\uFFD7') && (0xffda > c || c > '\uFFDC'))
											{
												if (0xffe0 > c || c > '₩')
												{
													if (0x4e00 > c || c > '\u9FA5')
													{
														if (0xf900 > c || c > '\uFA2D')
														{
															if (hDC == (IntPtr)0)
															{
																hwnd = ConsoleControl.NativeMethods.GetConsoleWindow();
																if ((IntPtr)0 != hwnd)
																{
																	hDC = ConsoleControl.NativeMethods.GetDC(hwnd);
																	if ((IntPtr)0 == hDC)
																	{
																		int lastWin32Error = Marshal.GetLastWin32Error();
																		object[] objArray = new object[1];
																		objArray[0] = lastWin32Error;
																		ConsoleControl.tracer.TraceError("Win32 Error 0x{0:X} occurred when getting the Device Context of the console window.", objArray);
																		return 1;
																	}
																}
																else
																{
																	int lastWin32Error1 = Marshal.GetLastWin32Error();
																	object[] objArray1 = new object[1];
																	objArray1[0] = lastWin32Error1;
																	ConsoleControl.tracer.TraceError("Win32 Error 0x{0:X} occurred when getting the window handle to the console.", objArray1);
																	return 1;
																}
															}
															if (!istmInitialized)
															{
																textMetrics = ConsoleControl.NativeMethods.GetTextMetrics(hDC, out tm);
																if (textMetrics)
																{
																	istmInitialized = true;
																}
																else
																{
																	int num1 = Marshal.GetLastWin32Error();
																	object[] objArray2 = new object[1];
																	objArray2[0] = num1;
																	ConsoleControl.tracer.TraceError("Win32 Error 0x{0:X} occurred when getting the Text Metric of the console window's Device Context.", objArray2);
																	return 1;
																}
															}
															textMetrics = ConsoleControl.NativeMethods.GetCharWidth32(hDC, c, c, out num);
															if (textMetrics)
															{
																if (num < tm.tmMaxCharWidth)
																{
																	object[] objArray3 = new object[1];
																	objArray3[0] = (int)c;
																	ConsoleControl.tracer.WriteLine("failed to locate char {0}, return 1", objArray3);
																	return 1;
																}
																else
																{
																	return 2;
																}
															}
															else
															{
																int lastWin32Error2 = Marshal.GetLastWin32Error();
																object[] objArray4 = new object[1];
																objArray4[0] = lastWin32Error2;
																ConsoleControl.tracer.TraceError("Win32 Error 0x{0:X} occurred when getting the width of a char.", objArray4);
																return 1;
															}
														}
														else
														{
															return 2;
														}
													}
													else
													{
														return 2;
													}
												}
												else
												{
													return 2;
												}
											}
											else
											{
												return 1;
											}
										}
										else
										{
											return 1;
										}
									}
									else
									{
										return 2;
									}
								}
								else
								{
									return 2;
								}
							}
							else
							{
								return 2;
							}
						}
						else
						{
							return 2;
						}
					}
					else
					{
						return 2;
					}
				}
				else
				{
					return 2;
				}
			}
			else
			{
				return 1;
			}
		}
Beispiel #20
0
			internal static bool SetConsoleCtrlHandler (ConsoleControl.BreakHandler handlerRoutine, bool add)
			{
				return true;
			}
Beispiel #21
0
		internal static int ReadConsoleInput(SafeFileHandle consoleHandle, ref ConsoleControl.INPUT_RECORD[] buffer)
		{
			int num = 0;
			bool flag = ConsoleControl.NativeMethods.ReadConsoleInput(consoleHandle.DangerousGetHandle(), buffer, buffer.Length, out num);
			if (flag)
			{
				return num;
			}
			else
			{
				int lastWin32Error = Marshal.GetLastWin32Error();
				HostException hostException = ConsoleControl.CreateHostException(lastWin32Error, "ReadConsoleInput", ErrorCategory.ReadError, ConsoleControlStrings.ReadConsoleInputExceptionTemplate);
				throw hostException;
			}
		}
Beispiel #22
0
			/*
			[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleCursorInfo(IntPtr consoleOutput, ref ConsoleControl.CONSOLE_CURSOR_INFO consoleCursorInfo);

			[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleCursorPosition(IntPtr consoleOutput, ConsoleControl.COORD cursorPosition);
			*/

			internal static bool SetConsoleCursorInfo (IntPtr consoleOutput, ref ConsoleControl.CONSOLE_CURSOR_INFO consoleCursorInfo)
			{
				consoleCursorInfo.Size = Console.CursorSize;
				consoleCursorInfo.Visible = Console.CursorVisible;
				return true;
			}
        CheckCoordinateWithinBuffer(ref Coordinates c, ref ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo, string paramName)
        {
            if (c.X < 0 || c.X > bufferInfo.BufferSize.X)
            {
                throw PSTraceSource.NewArgumentOutOfRangeException(
                    paramName + ".X",
                    c.X,
                    ConsoleHostRawUserInterfaceStrings.CoordinateOutOfBufferErrorTemplate, bufferInfo.BufferSize);
            }

            if (c.Y < 0 || c.Y > bufferInfo.BufferSize.Y)
            {
                throw PSTraceSource.NewArgumentOutOfRangeException(
                    paramName + ".Y",
                    c.Y,
                    ConsoleHostRawUserInterfaceStrings.CoordinateOutOfBufferErrorTemplate, bufferInfo.BufferSize);
            }
        }
Beispiel #24
0
			internal static bool SetConsoleCursorPosition(IntPtr consoleOutput, ConsoleControl.COORD cursorPosition)
			{
				Console.SetCursorPosition(cursorPosition.X, cursorPosition.Y);
				return true;
			}
 /// <summary>
 /// Used by ReadKey, cache KeyEvent based on if input.RepeatCount > 1
 /// </summary>
 /// <param name="input">Input key event record</param>
 /// <param name="cache">Cache key event</param>
 private static void CacheKeyEvent(ConsoleControl.KEY_EVENT_RECORD input, ref ConsoleControl.KEY_EVENT_RECORD cache)
 {
     if (input.RepeatCount > 1)
     {
         cache = input;
         cache.RepeatCount--;
     }
 }
Beispiel #26
0
			/*
			[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleScreenBufferSize(IntPtr consoleOutput, ConsoleControl.COORD size);

			[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleTextAttribute(IntPtr consoleOutput, ushort attributes);

			[DllImport("KERNEL32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleTitle(string consoleTitle);

			[DllImport("KERNEL32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetConsoleWindowInfo(IntPtr consoleHandle, bool absolute, ref ConsoleControl.SMALL_RECT windowInfo);

			[DllImport("kernel32.dll", CharSet=CharSet.Unicode)]
			internal static extern bool SetCurrentConsoleFontEx(IntPtr consoleOutput, bool bMaximumWindow, ref ConsoleControl.CONSOLE_FONT_INFO_EX consoleFontInfo);
			*/


			internal static bool SetConsoleScreenBufferSize (IntPtr consoleOutput, ConsoleControl.COORD size)
			{
				Console.SetBufferSize (size.X,  size.Y);
				return true;
			}
Beispiel #27
0
 internal static void CheckWriteEdges(
     ConsoleHandle consoleHandle,
     uint codePage, Coordinates origin,
     BufferCell[,] contents,
     Rectangle contentsRegion,
     ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo,
     int firstLeftTrailingRow,
     int firstRightLeadingRow)
 {
     Rectangle existingRegion = new Rectangle(0, 0, 1, contentsRegion.Bottom - contentsRegion.Top);
     if (origin.X == 0)
     {
         if (firstLeftTrailingRow >= 0)
         {
             throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
                 firstLeftTrailingRow, contentsRegion.Left));
         }
     }
     else
     {
         // use ReadConsoleOutputCJK because checking the left and right edges of the existing output
         // is NOT needed
         BufferCell[,] leftExisting = new BufferCell[existingRegion.Bottom + 1, 2];
         ReadConsoleOutputCJK(consoleHandle, codePage,
             new Coordinates(origin.X - 1, origin.Y), existingRegion, ref leftExisting);
         for (int r = contentsRegion.Top, i = 0; r <= contentsRegion.Bottom; r++, i++)
         {
             if (leftExisting[r, 0].BufferCellType == BufferCellType.Leading ^
                     contents[r, contentsRegion.Left].BufferCellType == BufferCellType.Trailing)
             {
                 throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
                     r, contentsRegion.Left));
             }
         }
     }
     //Check right edge
     if (origin.X + (contentsRegion.Right - contentsRegion.Left) + 1 >= bufferInfo.BufferSize.X)
     {
         if (firstRightLeadingRow >= 0)
         {
             throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
                     firstRightLeadingRow, contentsRegion.Right));
         }
     }
     else
     {
         // use ReadConsoleOutputCJK because checking the left and right edges of the existing output
         // is NOT needed
         BufferCell[,] rightExisting = new BufferCell[existingRegion.Bottom + 1, 2];
         ReadConsoleOutputCJK(consoleHandle, codePage,
             new Coordinates(origin.X + (contentsRegion.Right - contentsRegion.Left), origin.Y), existingRegion, ref rightExisting);
         for (int r = contentsRegion.Top, i = 0; r <= contentsRegion.Bottom; r++, i++)
         {
             if (rightExisting[r, 0].BufferCellType == BufferCellType.Leading ^
                     contents[r, contentsRegion.Right].BufferCellType == BufferCellType.Leading)
             {
                 throw PSTraceSource.NewArgumentException(string.Format(CultureInfo.InvariantCulture, "contents[{0}, {1}]",
                     r, contentsRegion.Right));
             }
         }
     }
 }
Beispiel #28
0
			internal static bool SetConsoleWindowInfo(IntPtr consoleHandle, bool absolute, ref ConsoleControl.SMALL_RECT windowInfo)
			{
				return true;
			}
 /// <summary>
 /// 
 /// If <paramref name="m"/> is set on <paramref name="flagToUnset"/>, unset it and return true;
 /// otherwise return false
 /// 
 /// </summary>
 /// <param name="flagToUnset">
 /// 
 /// a flag in ConsoleControl.ConsoleModes to be unset in <paramref name="m"/>
 /// 
 /// </param>
 /// <param name="m">
 /// </param>
 /// <returns>
 /// 
 /// true if <paramref name="m"/> is set on <paramref name="flagToUnset"/>
 /// false otherwise
 /// 
 /// </returns>
 private static bool shouldUnsetMode(
     ConsoleControl.ConsoleModes flagToUnset,
     ref ConsoleControl.ConsoleModes m)
 {
     if ((m & flagToUnset) > 0)
     {
         m &= ~flagToUnset;
         return true;
     }
     return false;
 }
Beispiel #30
0
			internal static bool FillConsoleOutputAttribute(IntPtr consoleOutput, ushort attribute, int length, ConsoleControl.COORD writeCoord, out int numberOfAttrsWritten)
			{
				numberOfAttrsWritten = length;
				return true;
			}