예제 #1
0
파일: hkProcess.cpp 프로젝트: AITW/ConEmu
// May be called from "C" programs
VOID WINAPI OnExitProcess(UINT uExitCode)
{
	//typedef BOOL (WINAPI* OnExitProcess_t)(UINT uExitCode);
	ORIGINAL_KRNL(ExitProcess);

	#if 0
	if (gbIsLessProcess)
	{
		_ASSERTE(FALSE && "Continue to ExitProcess");
	}
	#endif

	gnDllState |= ds_OnExitProcess;

	#ifdef PRINT_ON_EXITPROCESS_CALLS
	wchar_t szInfo[80]; _wsprintf(szInfo, SKIPCOUNT(szInfo) L"\n\x1B[1;31;40m::ExitProcess(%u) called\x1B[m\n", uExitCode);
	WriteProcessed(szInfo, lstrlen(szInfo), NULL);
	#endif

	// And terminate our threads
	DoDllStop(false, ds_OnExitProcess);

	bool bUseForceTerminate;

	// Issue 1865: Due to possible dead locks in LdrpAcquireLoaderLock() call TerminateProcess
	bUseForceTerminate = gbHookServerForcedTermination;

	#ifdef USE_GH_272_WORKAROUND
	// gh#272: For unknown yet reason existance of nvd3d9wrap.dll (or nvd3d9wrapx.dll on 64-bit)
	//		caused stack overflow with following calls
	//
	//		nvd3d9wrap!GetNVDisplayW+0x174f
	//		nvd3d9wrap!GetNVDisplayW+0x174f
	//		user32!_UserClientDllInitialize+0x2ca
	//		ntdll!LdrpCallInitRoutine+0x14
	//		ntdll!LdrShutdownProcess+0x1aa
	//		ntdll!RtlExitUserProcess+0x74
	//		kernel32!ExitProcessStub+0x12
	//		CallExit!main+0x47
	if (!bUseForceTerminate && GetModuleHandle(WIN3264TEST(L"nvd3d9wrap.dll",L"nvd3d9wrapx.dll")))
	{
		bUseForceTerminate = true;
	}
	#endif // USE_GH_272_WORKAROUND

	if (bUseForceTerminate)
	{
		ORIGINAL_KRNL(TerminateProcess);
		F(TerminateProcess)(GetCurrentProcess(), uExitCode);
		return; // Assume not to get here
	}

	F(ExitProcess)(uExitCode);
}
예제 #2
0
HANDLE WINAPI OnCreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode, const SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData)
{
	//typedef HANDLE(WINAPI* OnCreateConsoleScreenBuffer_t)(DWORD dwDesiredAccess, DWORD dwShareMode, const SECURITY_ATTRIBUTES *lpSecurityAttributes, DWORD dwFlags, LPVOID lpScreenBufferData);
	ORIGINAL_KRNL(CreateConsoleScreenBuffer);

	#ifdef SHOWCREATEBUFFERINFO
	wchar_t szDebugInfo[255];
	msprintf(szDebugInfo, countof(szDebugInfo), L"CreateConsoleScreenBuffer(0x%X,0x%X,0x%X,0x%X,0x%X)",
		dwDesiredAccess, dwShareMode, (DWORD)(DWORD_PTR)lpSecurityAttributes, dwFlags, (DWORD)(DWORD_PTR)lpScreenBufferData);

	#endif

	if ((dwShareMode & (FILE_SHARE_READ|FILE_SHARE_WRITE)) != (FILE_SHARE_READ|FILE_SHARE_WRITE))
		dwShareMode |= (FILE_SHARE_READ|FILE_SHARE_WRITE);

	if ((dwDesiredAccess & (GENERIC_READ|GENERIC_WRITE)) != (GENERIC_READ|GENERIC_WRITE))
		dwDesiredAccess |= (GENERIC_READ|GENERIC_WRITE);

	if (!ghStdOutHandle)
		ghStdOutHandle = GetStdHandle(STD_OUTPUT_HANDLE);

	HANDLE h = INVALID_HANDLE_VALUE;
	if (F(CreateConsoleScreenBuffer))
		h = F(CreateConsoleScreenBuffer)(dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwFlags, lpScreenBufferData);

#ifdef SHOWCREATEBUFFERINFO
	msprintf(szDebugInfo+lstrlen(szDebugInfo), 32, L"=0x%X", (DWORD)(DWORD_PTR)h);
	GuiMessageBox(ghConEmuWnd, szDebugInfo, L"ConEmuHk", MB_SETFOREGROUND|MB_SYSTEMMODAL);
#endif

	return h;
}
예제 #3
0
HWND WINAPI OnGetConsoleWindow(void)
{
	//typedef HWND (WINAPI* OnGetConsoleWindow_t)(void);
	ORIGINAL_KRNL(GetConsoleWindow);

	_ASSERTE(F(GetConsoleWindow) != GetRealConsoleWindow);
	// && F(GetConsoleWindow) != GetConsoleWindow - for minhook generation

	if (ghConEmuWndDC && IsWindow(ghConEmuWndDC) /*ghConsoleHwnd*/)
	{
		if (ghAttachGuiClient)
		{
			// В GUI режиме (notepad, putty) отдавать реальный результат GetRealConsoleWindow()
			// в этом режиме не нужно отдавать ни ghConEmuWndDC, ни серверную консоль
			HWND hReal = GetRealConsoleWindow();
			return hReal;
		}
		else
		{
			//return ghConsoleHwnd;
			return ghConEmuWndDC;
		}
	}

	HWND h;
	h = F(GetConsoleWindow)();
	return h;
}
예제 #4
0
BOOL WINAPI OnFreeConsole(void)
{
	//typedef BOOL (WINAPI* OnFreeConsole_t)(void);
	ORIGINAL_KRNL(FreeConsole);
	BOOL lbRc = FALSE;

	if (ph && ph->PreCallBack)
	{
		SETARGS(&lbRc);

		if (!ph->PreCallBack(&args))
			return lbRc;
	}

	//ReleaseConsoleInputSemaphore();

	lbRc = F(FreeConsole)();

	if (ph && ph->PostCallBack)
	{
		SETARGS(&lbRc);
		ph->PostCallBack(&args);
	}

	return lbRc;
}
예제 #5
0
파일: hkStdIO.cpp 프로젝트: Maximus5/ConEmu
BOOL WINAPI OnWriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
{
	//typedef BOOL (WINAPI* OnWriteFile_t)(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
	ORIGINAL_KRNL(WriteFile);
	BOOL lbRc = FALSE;
	CEAnsi* pObj = NULL;

	if (lpBuffer && nNumberOfBytesToWrite && hFile)
	{
		bool bConOut = false;
		if (HandleKeeper::IsAnsiCapable(hFile, &bConOut) && ((pObj = CEAnsi::Object()) != NULL))
		{
			lbRc = pObj->OurWriteConsoleA(hFile, (LPCSTR)lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten);
			goto wrap;
		}
		else if (bConOut && CEAnsi::ghAnsiLogFile)
		{
			CEAnsi::WriteAnsiLogA((LPCSTR)lpBuffer, nNumberOfBytesToWrite);
		}
	}

	lbRc = F(WriteFile)(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
wrap:
	return lbRc;
}
예제 #6
0
파일: hkStdIO.cpp 프로젝트: Maximus5/ConEmu
HANDLE WINAPI OnCreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances,DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut,LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
	//typedef HANDLE(WINAPI* OnCreateNamedPipeW_t)(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances,DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut,LPSECURITY_ATTRIBUTES lpSecurityAttributes);
	ORIGINAL_KRNL(CreateNamedPipeW);

	#ifdef _DEBUG
	if (!lpName || !*lpName)
	{
		_ASSERTE(lpName && *lpName);
	}
	else
	{
		int nLen = lstrlen(lpName)+64;
		wchar_t* psz = (wchar_t*)malloc(nLen*sizeof(*psz));
		if (psz)
		{
			msprintf(psz, nLen, L"CreateNamedPipeW(%s)\n", lpName);
			DebugString(psz);
			free(psz);
		}
	}
	#endif

	HANDLE hPipe = F(CreateNamedPipeW)(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes);
	return hPipe;
} // OnCreateNamedPipeW
예제 #7
0
BOOL WINAPI OnSetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
{
	//typedef BOOL (WINAPI* OnSetConsoleActiveScreenBuffer_t)(HANDLE hConsoleOutput);
	ORIGINAL_KRNL(SetConsoleActiveScreenBuffer);

	if (!ghStdOutHandle)
		ghStdOutHandle = GetStdHandle(STD_OUTPUT_HANDLE);

	#ifdef _DEBUG
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	HANDLE hIn  = GetStdHandle(STD_INPUT_HANDLE);
	HANDLE hErr = GetStdHandle(STD_ERROR_HANDLE);
	#endif

	BOOL lbRc = FALSE;
	if (F(SetConsoleActiveScreenBuffer))
		lbRc = F(SetConsoleActiveScreenBuffer)(hConsoleOutput);

	if (lbRc && (ghCurrentOutBuffer || (hConsoleOutput != ghStdOutHandle)))
	{
		#ifdef SHOWCREATEBUFFERINFO
		CONSOLE_SCREEN_BUFFER_INFO lsbi = {};
		BOOL lbTest = GetConsoleScreenBufferInfo(hConsoleOutput, &lsbi);
		DWORD nErrCode = GetLastError();
		_ASSERTE(lbTest && lsbi.dwSize.Y && "GetConsoleScreenBufferInfo(hConsoleOutput) failed");
		#endif

		ghCurrentOutBuffer = hConsoleOutput;
		RequestLocalServerParm Parm = {(DWORD)sizeof(Parm), slsf_SetOutHandle, &ghCurrentOutBuffer};
		RequestLocalServer(&Parm);
	}

	return lbRc;
}
예제 #8
0
BOOL WINAPI OnTerminateThread(HANDLE hThread, DWORD dwExitCode)
{
	//typedef BOOL (WINAPI* OnTerminateThread_t)(HANDLE hThread, UINT dwExitCode);
	ORIGINAL_KRNL(TerminateThread);
	BOOL lbRc;

	#if 0
	if (gbIsLessProcess)
	{
		_ASSERTE(FALSE && "Continue to terminate thread");
	}
	#endif

	if (hThread == GetCurrentThread())
	{
		// And terminate our service threads
		gnDllState |= ds_OnTerminateThread;

		// Main thread is abnormally terminating?
		if (GetCurrentThreadId() == gnHookMainThreadId)
		{
			DoDllStop(false, ds_OnTerminateThread);
		}
	}

	lbRc = F(TerminateThread)(hThread, dwExitCode);

	return lbRc;
}
예제 #9
0
BOOL WINAPI OnSetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
{
	//typedef BOOL (WINAPI* OnSetConsoleMode_t)(HANDLE hConsoleHandle, DWORD dwMode);
	ORIGINAL_KRNL(SetConsoleMode);
	BOOL lbRc = FALSE;

	#if 0
	if (!(dwMode & ENABLE_PROCESSED_OUTPUT))
	{
		_ASSERTEX((dwMode & ENABLE_PROCESSED_OUTPUT)==ENABLE_PROCESSED_OUTPUT);
	}
	#endif

	if (gbIsVimProcess)
	{
		if ((dwMode & (ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT)) != (ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT))
		{
			if (CEAnsi::IsOutputHandle(hConsoleHandle))
			{
				dwMode |= ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT;
			}
			else
			{
				dwMode |= ENABLE_WINDOW_INPUT;
			}
		}
	}

	lbRc = F(SetConsoleMode)(hConsoleHandle, dwMode);

	return lbRc;
}
예제 #10
0
BOOL WINAPI OnWriteConsoleInputA(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten)
{
	//typedef BOOL (WINAPI* OnWriteConsoleInputA_t)(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten);
	ORIGINAL_KRNL(WriteConsoleInputA);
	BOOL lbRc = FALSE;

	#ifdef _DEBUG
	PreWriteConsoleInput(FALSE, lpBuffer, nLength);
	#endif

	if (ph && ph->PreCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten);

		// Если функция возвращает FALSE - реальная запись не будет вызвана
		if (!ph->PreCallBack(&args))
			return lbRc;
	}

	lbRc = F(WriteConsoleInputA)(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsWritten);

	if (ph && ph->PostCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten);
		ph->PostCallBack(&args);
	}

	return lbRc;
}
예제 #11
0
BOOL WINAPI OnGetNumberOfConsoleInputEvents(HANDLE hConsoleInput, LPDWORD lpcNumberOfEvents)
{
	//typedef BOOL (WINAPI* OnGetNumberOfConsoleInputEvents_t)(HANDLE hConsoleInput, LPDWORD lpcNumberOfEvents);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(GetNumberOfConsoleInputEvents);
	BOOL lbRc = FALSE;

	//if (gpFarInfo && bMainThread)
	//	TouchReadPeekConsoleInputs();

	if (ph && ph->PreCallBack)
	{
		SETARGS2(&lbRc,hConsoleInput,lpcNumberOfEvents);

		// Если функция возвращает FALSE - реальное чтение не будет вызвано
		if (!ph->PreCallBack(&args))
			return lbRc;
	}

	lbRc = F(GetNumberOfConsoleInputEvents)(hConsoleInput, lpcNumberOfEvents);

	// Hiew fails pasting from clipboard on high speed
	if (gbIsHiewProcess && lpcNumberOfEvents && (*lpcNumberOfEvents > 1))
	{
		*lpcNumberOfEvents = 1;
	}

	if (ph && ph->PostCallBack)
	{
		SETARGS2(&lbRc,hConsoleInput,lpcNumberOfEvents);
		ph->PostCallBack(&args);
	}

	return lbRc;
}
예제 #12
0
BOOL WINAPI OnReadConsoleInputA(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)
{
	//typedef BOOL (WINAPI* OnReadConsoleInputA_t)(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(ReadConsoleInputA);
	//if (gpFarInfo && bMainThread)
	//	TouchReadPeekConsoleInputs(0);
	BOOL lbRc = FALSE;

	#if defined(_DEBUG)
	#if 1
	UINT nCp = GetConsoleCP();
	UINT nOutCp = GetConsoleOutputCP();
	UINT nOemCp = GetOEMCP();
	UINT nAnsiCp = GetACP();
	#endif
	#endif

	// To minimize startup duration and possible problems
	// hook server will start on first 'user interaction'
	CheckHookServer();

	if (ph && ph->PreCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);

		// Если функция возвращает FALSE - реальное чтение не будет вызвано
		if (!ph->PreCallBack(&args))
			return lbRc;
	}

	CESERVER_CONSOLE_APP_MAPPING* pAppMap = NULL;
	PreReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_LLInput, &pAppMap);

	//#ifdef USE_INPUT_SEMAPHORE
	//DWORD nSemaphore = ghConInSemaphore ? WaitForSingleObject(ghConInSemaphore, INSEMTIMEOUT_READ) : 1;
	//_ASSERTE(nSemaphore<=1);
	//#endif

	lbRc = F(ReadConsoleInputA)(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead);

	PostReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_LLInput, pAppMap);

	//#ifdef USE_INPUT_SEMAPHORE
	//if ((nSemaphore == WAIT_OBJECT_0) && ghConInSemaphore) ReleaseSemaphore(ghConInSemaphore, 1, NULL);
	//#endif

	if (ph && ph->PostCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);
		ph->PostCallBack(&args);
	}

	if (lbRc && lpNumberOfEventsRead && *lpNumberOfEventsRead && lpBuffer)
	{
		OnPeekReadConsoleInput('R', 'A', hConsoleInput, lpBuffer, *lpNumberOfEventsRead);
	}

	return lbRc;
}
예제 #13
0
COORD WINAPI OnGetLargestConsoleWindowSize(HANDLE hConsoleOutput)
{
	//typedef COORD (WINAPI* OnGetLargestConsoleWindowSize_t)(HANDLE hConsoleOutput);
	ORIGINAL_KRNL(GetLargestConsoleWindowSize);
	COORD cr = {80,25}, crLocked = {0,0};

	if (ghConEmuWndDC && IsVisibleRectLocked(crLocked))
	{
		cr = crLocked;
	}
	else
	{
		if (F(GetLargestConsoleWindowSize))
		{
			cr = F(GetLargestConsoleWindowSize)(hConsoleOutput);
		}

		// Wine BUG
		//if (!cr.X || !cr.Y)
		if ((cr.X == 80 && cr.Y == 24) && IsWine())
		{
			cr.X = 255;
			cr.Y = 255;
		}
	}

	return cr;
}
예제 #14
0
// For example, mintty is terminated ‘abnormally’. It calls TerminateProcess instead of ExitProcess.
BOOL WINAPI OnTerminateProcess(HANDLE hProcess, UINT uExitCode)
{
	//typedef BOOL (WINAPI* OnTerminateProcess_t)(HANDLE hProcess, UINT uExitCode);
	ORIGINAL_KRNL(TerminateProcess);
	BOOL lbRc;

	if (hProcess == GetCurrentProcess())
	{
		#ifdef PRINT_ON_EXITPROCESS_CALLS
		wchar_t szInfo[80]; _wsprintf(szInfo, SKIPCOUNT(szInfo) L"\n\x1B[1;31;40m::TerminateProcess(%u) called\x1B[m\n", uExitCode);
		WriteProcessed2(szInfo, lstrlen(szInfo), NULL, wps_Error);
		#endif

		gnDllState |= ds_OnTerminateProcess;
		// We don't need to do proper/full deinitialization,
		// because the process is to be terminated abnormally
		DoDllStop(false, ds_OnTerminateProcess);

		lbRc = F(TerminateProcess)(hProcess, uExitCode);
	}
	else
	{
		lbRc = F(TerminateProcess)(hProcess, uExitCode);
	}

	return lbRc;
}
예제 #15
0
// Sets the attributes of characters written to the console screen buffer by
// the WriteFile or WriteConsole function, or echoed by the ReadFile or ReadConsole function.
// This function affects text written after the function call.
BOOL WINAPI OnSetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes)
{
	//typedef BOOL (WINAPI* OnSetConsoleTextAttribute_t)(HANDLE hConsoleOutput, WORD wAttributes);
	ORIGINAL_KRNL(SetConsoleTextAttribute);

	BOOL lbRc = FALSE;

	if (ph && ph->PreCallBack)
	{
		SETARGS2(&lbRc, hConsoleOutput, wAttributes);
		ph->PreCallBack(&args);
	}

	#ifdef _DEBUG
	// We do not care if visible ChildGui is doing smth in their console
	// Process here only our native console windows
	if ((ghAttachGuiClient == NULL) && !gbAttachGuiClient && (wAttributes != 7))
	{
		wchar_t szDbgInfo[128];
		msprintf(szDbgInfo, countof(szDbgInfo), L"PID=%u, SetConsoleTextAttribute=0x%02X(%u)\n", GetCurrentProcessId(), (int)wAttributes, (int)wAttributes);
		DebugString(szDbgInfo);
	}
	#endif

	lbRc = F(SetConsoleTextAttribute)(hConsoleOutput, wAttributes);

	if (ph && ph->PostCallBack)
	{
		SETARGS2(&lbRc, hConsoleOutput, wAttributes);
		ph->PostCallBack(&args);
	}

	return lbRc;
}
예제 #16
0
BOOL WINAPI OnWriteConsoleOutputA(HANDLE hConsoleOutput,const CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpWriteRegion)
{
	//typedef BOOL (WINAPI* OnWriteConsoleOutputA_t)(HANDLE hConsoleOutput,const CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpWriteRegion);
	ORIGINAL_KRNL(WriteConsoleOutputA);
	BOOL lbRc = FALSE;

	#ifdef _DEBUG
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD dwMode = 0;
	GetConsoleMode(hOut, &dwMode);
	GetConsoleMode(hConsoleOutput, &dwMode);
	#endif

	if (ph && ph->PreCallBack)
	{
		SETARGS5(&lbRc, hConsoleOutput, lpBuffer, &dwBufferSize, &dwBufferCoord, lpWriteRegion);
		ph->PreCallBack(&args);
	}

	lbRc = F(WriteConsoleOutputA)(hConsoleOutput, lpBuffer, dwBufferSize, dwBufferCoord, lpWriteRegion);

	if (ph && ph->PostCallBack)
	{
		SETARGS5(&lbRc, hConsoleOutput, lpBuffer, &dwBufferSize, &dwBufferCoord, lpWriteRegion);
		ph->PostCallBack(&args);
	}

	return lbRc;
}
예제 #17
0
BOOL WINAPI OnSetConsoleCursorPosition(HANDLE hConsoleOutput, COORD dwCursorPosition)
{
	//typedef BOOL (WINAPI* OnSetConsoleCursorPosition_t)(HANDLE,COORD);
	ORIGINAL_KRNL(SetConsoleCursorPosition);

	BOOL lbRc;

	if (gbIsVimAnsi)
	{
		#ifdef DUMP_VIM_SETCURSORPOS
		wchar_t szDbg[80]; msprintf(szDbg, countof(szDbg), L"ViM trying to set cursor pos: {%i,%i}\n", (UINT)dwCursorPosition.X, (UINT)dwCursorPosition.Y);
		OutputDebugString(szDbg);
		#endif
		lbRc = FALSE;
	}
	else
	{
		lbRc = F(SetConsoleCursorPosition)(hConsoleOutput, dwCursorPosition);
	}

	if (ghConsoleCursorChanged)
		SetEvent(ghConsoleCursorChanged);

	return lbRc;
}
예제 #18
0
BOOL WINAPI OnReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID pInputControl)
{
	// typedef BOOL (WINAPI* OnReadConsoleA_t)(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID pInputControl);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(ReadConsoleA);
	BOOL lbRc = FALSE;

	OnReadConsoleStart(false, hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, pInputControl);

	lbRc = F(ReadConsoleA)(hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, pInputControl);
	DWORD nErr = GetLastError();

	// gh#465: For consistence with OnReadConsoleW
	if (lbRc && lpBuffer && lpNumberOfCharsRead && *lpNumberOfCharsRead
		// pInputControl has no evvect on ANSI version
		&& (*lpNumberOfCharsRead <= 3))
	{
		// To avoid checking of the mapping, we check result first
		const char* pchTest = (const char*)lpBuffer;
		if ((pchTest[0] == 26 /* Ctrl-Z / ^Z / (char)('Z' - '@') */)
			&& (((*lpNumberOfCharsRead == 3) && (pchTest[1] == '\r') && (pchTest[2] == '\n')) // Expected variant
				|| ((*lpNumberOfCharsRead == 2) && (pchTest[1] == '\n')) // Possible variant?
				))
		{
			if (isProcessCtrlZ())
				*lpNumberOfCharsRead = 0;
		}
	}

	OnReadConsoleEnd(lbRc, false, hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, pInputControl);
	SetLastError(nErr);

	return lbRc;
}
예제 #19
0
파일: hkKernel.cpp 프로젝트: AITW/ConEmu
void WINAPI OnGetLocalTime(LPSYSTEMTIME lpSystemTime)
{
	//typedef void (WINAPI* OnGetLocalTime_t)(LPSYSTEMTIME);
	ORIGINAL_KRNL(GetLocalTime);

	if (!GetTime(false, lpSystemTime))
		F(GetLocalTime)(lpSystemTime);
}
예제 #20
0
DWORD WINAPI OnGetConsoleAliasesW(LPWSTR AliasBuffer, DWORD AliasBufferLength, LPWSTR ExeName)
{
	//typedef DWORD (WINAPI* OnGetConsoleAliasesW_t)(LPWSTR AliasBuffer, DWORD AliasBufferLength, LPWSTR ExeName);
	ORIGINAL_KRNL(GetConsoleAliasesW);
	DWORD nError = 0;
	DWORD nRc = F(GetConsoleAliasesW)(AliasBuffer,AliasBufferLength,ExeName);

	if (!nRc)
	{
		nError = GetLastError();

		// финт ушами
		if (nError == ERROR_NOT_ENOUGH_MEMORY) // && gdwServerPID)
		{
			DWORD nServerPID = gnServerPID;
			HWND hConWnd = GetRealConsoleWindow();
			_ASSERTE(hConWnd == ghConWnd);

			//MFileMapping<CESERVER_CONSOLE_MAPPING_HDR> ConInfo;
			//ConInfo.InitName(CECONMAPNAME, (DWORD)hConWnd); //-V205
			//CESERVER_CONSOLE_MAPPING_HDR *pInfo = ConInfo.Open();
			//if (pInfo
			//	&& (pInfo->cbSize >= sizeof(CESERVER_CONSOLE_MAPPING_HDR))
			//	//&& (pInfo->nProtocolVersion == CESERVER_REQ_VER)
			//	)
			//{
			//	nServerPID = pInfo->nServerPID;
			//	ConInfo.CloseMap();
			//}

			if (nServerPID)
			{
				CESERVER_REQ_HDR In;
				ExecutePrepareCmd(&In, CECMD_GETALIASES, sizeof(CESERVER_REQ_HDR));
				CESERVER_REQ* pOut = ExecuteSrvCmd(nServerPID/*gdwServerPID*/, (CESERVER_REQ*)&In, hConWnd);

				if (pOut)
				{
					size_t nData = min(AliasBufferLength,(pOut->hdr.cbSize-sizeof(pOut->hdr)));

					if (nData)
					{
						memmove(AliasBuffer, pOut->Data, nData);
						nRc = TRUE;
					}

					ExecuteFreeResult(pOut);
				}
			}
		}

		if (!nRc)
			SetLastError(nError); // вернуть, вдруг какая функция его поменяла
	}

	return nRc;
}
예제 #21
0
BOOL WINAPI OnSetConsoleTitleA(LPCSTR lpConsoleTitle)
{
	//typedef BOOL (WINAPI* OnSetConsoleTitleA_t)(LPCSTR lpConsoleTitle);
	ORIGINAL_KRNL(SetConsoleTitleA);
	BOOL bRc = FALSE;
	if (F(SetConsoleTitleA))
		bRc = F(SetConsoleTitleA)(lpConsoleTitle);
	return bRc;
}
예제 #22
0
LPWCH WINAPI OnGetEnvironmentStringsW()
{
	//typedef LPWCH (WINAPI* OnGetEnvironmentStringsW_t)();
	ORIGINAL_KRNL(GetEnvironmentStringsW);

	CheckVariables();

	LPWCH lpRc = F(GetEnvironmentStringsW)();
	return lpRc;
}
예제 #23
0
// Spare?
BOOL WINAPI OnGetConsoleMode(HANDLE hConsoleHandle,LPDWORD lpMode)
{
	//typedef BOOL (WINAPI* OnGetConsoleMode_t)(HANDLE,LPDWORD);
	ORIGINAL_KRNL(GetConsoleMode);
	BOOL b;

	b = F(GetConsoleMode)(hConsoleHandle,lpMode);

	return b;
}
예제 #24
0
파일: hkStdIO.cpp 프로젝트: Maximus5/ConEmu
BOOL WINAPI OnSetStdHandle(DWORD nStdHandle, HANDLE hHandle)
{
	//typedef BOOL (WINAPI* OnSetStdHandle_t)(DWORD  nStdHandle, HANDLE hHandle);
	ORIGINAL_KRNL(SetStdHandle);
	BOOL bRc;

	bRc = F(SetStdHandle)(nStdHandle, hHandle);

	return bRc;
}
예제 #25
0
파일: hkProcess.cpp 프로젝트: AITW/ConEmu
// Required in VisualStudio and CodeBlocks (gdb) for DefTerm support while debugging
DWORD WINAPI OnResumeThread(HANDLE hThread)
{
	//typedef DWORD (WINAPI* OnResumeThread_t)(HANDLE);
	ORIGINAL_KRNL(ResumeThread);

	CShellProc::OnResumeDebugeeThreadCalled(hThread);

	DWORD nRc = F(ResumeThread)(hThread);

	return nRc;
}
예제 #26
0
BOOL WINAPI OnSetConsoleCursorInfo(HANDLE hConsoleOutput, const CONSOLE_CURSOR_INFO *lpConsoleCursorInfo)
{
	//typedef BOOL (WINAPI* OnSetConsoleCursorInfo_t)(HANDLE,const CONSOLE_CURSOR_INFO *);
	ORIGINAL_KRNL(SetConsoleCursorInfo);

	BOOL lbRc = F(SetConsoleCursorInfo)(hConsoleOutput, lpConsoleCursorInfo);

	if (ghConsoleCursorChanged)
		SetEvent(ghConsoleCursorChanged);

	return lbRc;
}
예제 #27
0
파일: hkProcess.cpp 프로젝트: AITW/ConEmu
BOOL WINAPI OnSetCurrentDirectoryW(LPCWSTR lpPathName)
{
	//typedef BOOL (WINAPI* OnSetCurrentDirectoryW_t)(LPCWSTR lpPathName);
	ORIGINAL_KRNL(SetCurrentDirectoryW);
	BOOL lbRc = FALSE;

	lbRc = F(SetCurrentDirectoryW)(lpPathName);

	gbCurDirChanged |= (lbRc != FALSE);

	return lbRc;
}
예제 #28
0
파일: hkKernel.cpp 프로젝트: AITW/ConEmu
VOID WINAPI OnSetLastError(DWORD dwErrCode)
{
	//typedef DWORD (WINAPI* OnSetLastError_t)(DWORD dwErrCode);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(SetLastError);

	if (dwErrCode == HOOK_ERROR_NO)
	{
		dwErrCode = HOOK_ERROR_NO;
	}

	if (F(SetLastError))
		F(SetLastError)(dwErrCode);
}
예제 #29
0
BOOL WINAPI OnFlushConsoleInputBuffer(HANDLE hConsoleInput)
{
	//typedef BOOL (WINAPI* OnFlushConsoleInputBuffer_t)(HANDLE hConsoleInput);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(FlushConsoleInputBuffer);
	BOOL lbRc = FALSE;

	//_ASSERTEX(FALSE && "calling FlushConsoleInputBuffer");
	DebugString(L"### calling FlushConsoleInputBuffer\n");

	lbRc = F(FlushConsoleInputBuffer)(hConsoleInput);

	return lbRc;
}
예제 #30
0
파일: hkProcess.cpp 프로젝트: AITW/ConEmu
// ssh (msysgit) crash issue. Need to know if thread was started by application but not remotely.
HANDLE WINAPI OnCreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId)
{
	//typedef HANDLE(WINAPI* OnCreateThread_t)(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
	ORIGINAL_KRNL(CreateThread);
	DWORD nTemp = 0;
	LPDWORD pThreadID = lpThreadId ? lpThreadId : &nTemp;

	HANDLE hThread = F(CreateThread)(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, pThreadID);

	if (hThread)
		gStartedThreads.Set(*pThreadID,true);

	return hThread;
}