Test if the real WriteFile handle is console

This commit is contained in:
Jason Hood 2018-05-03 23:46:33 +10:00
parent d7a2be9964
commit f4697b59fa
2 changed files with 9 additions and 7 deletions

8
ANSI.c
View File

@ -202,7 +202,8 @@
dynamically load WINMM.DLL;
use sprintf/_snprintf/_snwprintf instead of wsprintf, avoiding USER32.DLL;
replace bsearch (in procrva.c) with specific code;
if the primary thread is detached exit the process.
if the primary thread is detached exit the process;
get real WriteFile handle before testing for console.
*/
#include "ansicon.h"
@ -3490,12 +3491,11 @@ BOOL
WINAPI MyWriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped )
{
if (nNumberOfBytesToWrite != 0 && IsConsoleHandle( hFile ))
{
if (HandleToULong( hFile ) == STD_OUTPUT_HANDLE ||
HandleToULong( hFile ) == STD_ERROR_HANDLE)
hFile = GetStdHandle( HandleToULong( hFile ) );
if (nNumberOfBytesToWrite != 0 && IsConsoleHandle( hFile ))
{
write_func = "WriteFile";
MyWriteConsoleA( hFile, lpBuffer,nNumberOfBytesToWrite, NULL,lpOverlapped );
if (lpNumberOfBytesWritten != NULL)

View File

@ -339,8 +339,10 @@ Version History
Legend: + added, - bug-fixed, * changed.
1.84-wip - 2 May, 2018:
1.84-wip - 3 May, 2018:
- close the flush handles on detach;
- use remote load on Win8+ if the process has no IAT;
- WriteFile wasn't properly testing if its handle was for a console;
* remove dependency on USER32, dynamically load WINMM;
* exit process if the primary thread is detached (for processes on Win10
that return, rather than call ExitProcess).
@ -619,4 +621,4 @@ Distribution
========================
Jason Hood, 2 May, 2018.
Jason Hood, 3 May, 2018.