Skip to content

Commit

Permalink
Fix ANSICON environment variable
Browse files Browse the repository at this point in the history
Creating a console handle in `set_ansicon` was assumed to succeed, but
that is not the case when there is no console (if the process was
started detached or freed its console).  This left the console info
uninitialised, causing my `printf` replacement to get stuck in a loop.

Resolves #127.
  • Loading branch information
adoxa committed Mar 1, 2019
1 parent a1bf74d commit d7a2d5e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
19 changes: 17 additions & 2 deletions ANSI.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@
v1.87, 3 February, 2019:
some hooked functions are not imported, so myimport wasn't set;
add missing SetCurrentConsoleFontEx to list of hooks.
v1.88, 1 March, 2019:
a detached process has no console handle (fixes set_ansicon).
*/

#include "ansicon.h"
Expand Down Expand Up @@ -3874,8 +3877,20 @@ void set_ansicon( PCONSOLE_SCREEN_BUFFER_INFO pcsbi )
hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL );
GetConsoleScreenBufferInfo( hConOut, &csbi );
CloseHandle( hConOut );
if (hConOut == INVALID_HANDLE_VALUE)
{
csbi.dwSize.X =
csbi.dwSize.Y =
csbi.srWindow.Left =
csbi.srWindow.Top =
csbi.srWindow.Right =
csbi.srWindow.Bottom = 0;
}
else
{
GetConsoleScreenBufferInfo( hConOut, &csbi );
CloseHandle( hConOut );
}
pcsbi = &csbi;
}

Expand Down
2 changes: 1 addition & 1 deletion ansicon.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
add log level 32 to log CreateFile.
*/

#define PDATE L"3 February, 2019"
#define PDATE L"1 March, 2019"

#include "ansicon.h"
#include "version.h"
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Copyright 2005-2019 Jason Hood

Version 1.87. Freeware
Version 1.88. Freeware


Description
Expand Down Expand Up @@ -340,6 +340,9 @@ Version History

Legend: + added, - bug-fixed, * changed.

1.88 - 1 March, 2019:
- fix ANSICON environment variable when there is no console.

1.87 - 3 February, 2019:
- fix crash when some programs start (bug during hooking);
- properly hook SetCurrentConsoleFontEx.
Expand Down Expand Up @@ -644,5 +647,5 @@ Distribution
in LICENSE.txt.


=============================
Jason Hood, 3 February, 2019.
==========================
Jason Hood, 1 March, 2019.
10 changes: 5 additions & 5 deletions version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
version.h - Version defines.
*/

#define PVERS L"1.87" // wide string
#define PVERSA "1.87" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"187" // wide environment string
#define PVEREA "187" // ANSI environment string
#define PVERB 1,8,7,0 // binary (resource)
#define PVERS L"1.88" // wide string
#define PVERSA "1.88" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"188" // wide environment string
#define PVEREA "188" // ANSI environment string
#define PVERB 1,8,8,0 // binary (resource)

#ifdef _WIN64
# define BITS L"64"
Expand Down

0 comments on commit d7a2d5e

Please sign in to comment.