mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-23 05:55:41 +02:00
Fixes to line ending handling in Windows SSHD.
This commit is contained in:
parent
6c5f1c6835
commit
d6a1ff42ae
@ -250,8 +250,8 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||||||
case 10:
|
case 10:
|
||||||
pszBuffer++;
|
pszBuffer++;
|
||||||
AutoWrap = 1;
|
AutoWrap = 1;
|
||||||
GoToNextLine();
|
bAtEOLN = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
pszBuffer++;
|
pszBuffer++;
|
||||||
@ -264,7 +264,7 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||||||
case 13:
|
case 13:
|
||||||
pszBuffer++;
|
pszBuffer++;
|
||||||
AutoWrap = 1;
|
AutoWrap = 1;
|
||||||
bAtEOLN = FALSE;
|
GoToNextLine();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
|
@ -62,7 +62,6 @@ typedef struct consoleEvent {
|
|||||||
consoleEvent* head = NULL;
|
consoleEvent* head = NULL;
|
||||||
consoleEvent* tail = NULL;
|
consoleEvent* tail = NULL;
|
||||||
|
|
||||||
BOOL isRedirected = FALSE;
|
|
||||||
BOOL bRet = FALSE;
|
BOOL bRet = FALSE;
|
||||||
BOOL bNoScrollRegion = FALSE;
|
BOOL bNoScrollRegion = FALSE;
|
||||||
BOOL bStartup = TRUE;
|
BOOL bStartup = TRUE;
|
||||||
@ -86,6 +85,7 @@ DWORD hostThreadId = 0;
|
|||||||
DWORD childProcessId = 0;
|
DWORD childProcessId = 0;
|
||||||
DWORD dwStatus = 0;
|
DWORD dwStatus = 0;
|
||||||
DWORD currentLine = 0;
|
DWORD currentLine = 0;
|
||||||
|
DWORD lastLineLength = 0;
|
||||||
|
|
||||||
UINT cp = 0;
|
UINT cp = 0;
|
||||||
|
|
||||||
@ -141,41 +141,46 @@ void SendKeyStroke(HANDLE hInput, int keyStroke, char character)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VT output routines
|
// VT output routines
|
||||||
|
void SendLF(HANDLE hInput) {
|
||||||
|
DWORD wr = 0;
|
||||||
|
|
||||||
|
if (bUseAnsiEmulation)
|
||||||
|
WriteFile(hInput, "\n", 1, &wr, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void SendClearScreen(HANDLE hInput) {
|
void SendClearScreen(HANDLE hInput) {
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
|
|
||||||
WriteFile(hInput, "\033[2J", 4, &wr, NULL);
|
if (bUseAnsiEmulation)
|
||||||
|
WriteFile(hInput, "\033[2J", 4, &wr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendClearScreenFromCursor(HANDLE hInput) {
|
void SendClearScreenFromCursor(HANDLE hInput) {
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
|
|
||||||
WriteFile(hInput, "\033[1J", 4, &wr, NULL);
|
if (bUseAnsiEmulation)
|
||||||
}
|
WriteFile(hInput, "\033[1J", 4, &wr, NULL);
|
||||||
|
|
||||||
void SendCRLF(HANDLE hInput) {
|
|
||||||
|
|
||||||
DWORD wr = 0;
|
|
||||||
|
|
||||||
WriteFile(hInput, "\n", 2, &wr, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendHideCursor(HANDLE hInput) {
|
void SendHideCursor(HANDLE hInput) {
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
|
|
||||||
WriteFile(hInput, "\033[?25l", 6, &wr, NULL);
|
if (bUseAnsiEmulation)
|
||||||
|
WriteFile(hInput, "\033[?25l", 6, &wr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendShowCursor(HANDLE hInput) {
|
void SendShowCursor(HANDLE hInput) {
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
|
|
||||||
WriteFile(hInput, "\033[?25h", 6, &wr, NULL);
|
if (bUseAnsiEmulation)
|
||||||
|
WriteFile(hInput, "\033[?25h", 6, &wr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCursorPositionRequest(HANDLE hInput) {
|
void SendCursorPositionRequest(HANDLE hInput) {
|
||||||
DWORD wr = 0;
|
DWORD wr = 0;
|
||||||
|
|
||||||
WriteFile(hInput, "\033[6n", 4, &wr, NULL);
|
if (bUseAnsiEmulation)
|
||||||
|
WriteFile(hInput, "\033[6n", 4, &wr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendSetCursor(HANDLE hInput, int X, int Y) {
|
void SendSetCursor(HANDLE hInput, int X, int Y) {
|
||||||
@ -428,8 +433,6 @@ void SizeWindow(HANDLE hInput) {
|
|||||||
|
|
||||||
DWORD WINAPI MonitorChild(_In_ LPVOID lpParameter) {
|
DWORD WINAPI MonitorChild(_In_ LPVOID lpParameter) {
|
||||||
WaitForSingleObject(child, INFINITE);
|
WaitForSingleObject(child, INFINITE);
|
||||||
if (isRedirected)
|
|
||||||
CloseHandle(pipe_in);
|
|
||||||
PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0);
|
PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -519,7 +522,7 @@ DWORD ProcessEvent(void *p) {
|
|||||||
readRect.Right = LOWORD(idChild);
|
readRect.Right = LOWORD(idChild);
|
||||||
|
|
||||||
// Detect a "cls" (Windows).
|
// Detect a "cls" (Windows).
|
||||||
if (!bStartup &&
|
if (!bStartup &&
|
||||||
(readRect.Top == consoleInfo.srWindow.Top || readRect.Top == nextConsoleInfo.srWindow.Top))
|
(readRect.Top == consoleInfo.srWindow.Top || readRect.Top == nextConsoleInfo.srWindow.Top))
|
||||||
{
|
{
|
||||||
BOOL isClearCommand = FALSE;
|
BOOL isClearCommand = FALSE;
|
||||||
@ -555,7 +558,7 @@ DWORD ProcessEvent(void *p) {
|
|||||||
|
|
||||||
if (bufferSize > MAX_EXPECTED_BUFFER_SIZE) {
|
if (bufferSize > MAX_EXPECTED_BUFFER_SIZE) {
|
||||||
|
|
||||||
if (!bStartup) {
|
if (!bStartup) {
|
||||||
SendClearScreen(pipe_out);
|
SendClearScreen(pipe_out);
|
||||||
ViewPortY = 0;
|
ViewPortY = 0;
|
||||||
lastViewPortY = 0;
|
lastViewPortY = 0;
|
||||||
@ -563,7 +566,7 @@ DWORD ProcessEvent(void *p) {
|
|||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the screen scrape buffer
|
// Create the screen scrape buffer
|
||||||
CHAR_INFO *pBuffer = (PCHAR_INFO)malloc(sizeof(CHAR_INFO) * bufferSize);
|
CHAR_INFO *pBuffer = (PCHAR_INFO)malloc(sizeof(CHAR_INFO) * bufferSize);
|
||||||
|
|
||||||
@ -586,6 +589,10 @@ DWORD ProcessEvent(void *p) {
|
|||||||
return dwError;
|
return dwError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (readRect.Top > currentLine)
|
||||||
|
for(SHORT n = currentLine; n < readRect.Top; n++)
|
||||||
|
SendLF(pipe_out);
|
||||||
|
|
||||||
// Set cursor location based on the reported location from the message.
|
// Set cursor location based on the reported location from the message.
|
||||||
CalculateAndSetCursor(pipe_out, ViewPortY, viewPortHeight, readRect.Left,
|
CalculateAndSetCursor(pipe_out, ViewPortY, viewPortHeight, readRect.Left,
|
||||||
readRect.Top);
|
readRect.Top);
|
||||||
@ -594,6 +601,7 @@ DWORD ProcessEvent(void *p) {
|
|||||||
SendBuffer(pipe_out, pBuffer, bufferSize);
|
SendBuffer(pipe_out, pBuffer, bufferSize);
|
||||||
|
|
||||||
lastViewPortY = ViewPortY;
|
lastViewPortY = ViewPortY;
|
||||||
|
lastLineLength = readRect.Left;
|
||||||
|
|
||||||
free(pBuffer);
|
free(pBuffer);
|
||||||
|
|
||||||
@ -1062,8 +1070,6 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
|
|
||||||
cp = GetConsoleCP();
|
cp = GetConsoleCP();
|
||||||
|
|
||||||
isRedirected = !GetConsoleMode(pipe_in, &dwMode);
|
|
||||||
|
|
||||||
ZeroMemory(&inputSi, sizeof(STARTUPINFO));
|
ZeroMemory(&inputSi, sizeof(STARTUPINFO));
|
||||||
GetStartupInfo(&inputSi);
|
GetStartupInfo(&inputSi);
|
||||||
|
|
||||||
@ -1086,13 +1092,10 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
hostThreadId = GetCurrentThreadId();
|
hostThreadId = GetCurrentThreadId();
|
||||||
hostProcessId = GetCurrentProcessId();
|
hostProcessId = GetCurrentProcessId();
|
||||||
|
|
||||||
if (isRedirected)
|
InitializeCriticalSection(&criticalSection);
|
||||||
{
|
|
||||||
InitializeCriticalSection(&criticalSection);
|
|
||||||
|
|
||||||
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
|
hEventHook = SetWinEventHook(EVENT_CONSOLE_CARET, EVENT_CONSOLE_LAYOUT, NULL,
|
||||||
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
|
ConsoleEventProc, 0, 0, WINEVENT_OUTOFCONTEXT);
|
||||||
}
|
|
||||||
|
|
||||||
memset(&si, 0, sizeof(STARTUPINFO));
|
memset(&si, 0, sizeof(STARTUPINFO));
|
||||||
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
|
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
|
||||||
@ -1101,11 +1104,8 @@ int wmain(int ac, wchar_t **av) {
|
|||||||
si.cb = sizeof(STARTUPINFO);
|
si.cb = sizeof(STARTUPINFO);
|
||||||
si.dwFlags = 0;
|
si.dwFlags = 0;
|
||||||
|
|
||||||
if (isRedirected)
|
/* disable inheritance on pipe_in*/
|
||||||
{
|
GOTO_CLEANUP_ON_FALSE(SetHandleInformation(pipe_in, HANDLE_FLAG_INHERIT, 0));
|
||||||
/* disable inheritance on pipe_in*/
|
|
||||||
GOTO_CLEANUP_ON_FALSE(SetHandleInformation(pipe_in, HANDLE_FLAG_INHERIT, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*TODO - pick this up from system32*/
|
/*TODO - pick this up from system32*/
|
||||||
cmd[0] = L'\0';
|
cmd[0] = L'\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user