Fix running directly via ansicon

A program run directly by `ansicon` should always be hooked, regardless
if it's GUI or excluded.  This was broken in v1.84 due to the DLL being
imported.
This commit is contained in:
Jason Hood 2018-08-23 17:18:10 +10:00
parent eec487abb6
commit 4e84582f02
2 changed files with 8 additions and 4 deletions

9
ANSI.c
View File

@ -211,7 +211,8 @@
workaround Windows 10 1803 console bug. workaround Windows 10 1803 console bug.
v1.85, 22 August, 2018: v1.85, 22 August, 2018:
fix creating the wrap buffer. fix creating the wrap buffer;
always inject from ansicon.exe, even if it's GUI or excluded.
*/ */
#include "ansicon.h" #include "ansicon.h"
@ -236,6 +237,7 @@ DWORD orgmode; // original mode
CONSOLE_CURSOR_INFO orgcci; // original cursor state CONSOLE_CURSOR_INFO orgcci; // original cursor state
HANDLE hHeap; // local memory heap HANDLE hHeap; // local memory heap
HANDLE hBell, hFlush; HANDLE hBell, hFlush;
BOOL ansicon; // are we in ansicon.exe?
#define CACHE 5 #define CACHE 5
struct Cache struct Cache
@ -3003,7 +3005,7 @@ void Inject( DWORD dwCreationFlags, LPPROCESS_INFORMATION lpi,
name = get_program( app, child_pi->hProcess, wide, lpApp, lpCmd ); name = get_program( app, child_pi->hProcess, wide, lpApp, lpCmd );
DEBUGSTR( 1, "%S (%u)", name, child_pi->dwProcessId ); DEBUGSTR( 1, "%S (%u)", name, child_pi->dwProcessId );
if (search_env( L"ANSICON_EXC", name )) if (!ansicon && search_env( L"ANSICON_EXC", name ))
{ {
DEBUGSTR( 1, " Excluded" ); DEBUGSTR( 1, " Excluded" );
type = 0; type = 0;
@ -3011,7 +3013,7 @@ void Inject( DWORD dwCreationFlags, LPPROCESS_INFORMATION lpi,
else else
{ {
type = ProcessType( child_pi, &base, &gui ); type = ProcessType( child_pi, &base, &gui );
if (gui && type > 0) if (!ansicon && gui && type > 0)
{ {
if (!search_env( L"ANSICON_GUI", name )) if (!search_env( L"ANSICON_GUI", name ))
{ {
@ -3927,6 +3929,7 @@ void OriginalAttr( PVOID lpReserved )
else else
{ {
// We also want to restore the original attributes for ansicon.exe. // We also want to restore the original attributes for ansicon.exe.
ansicon =
org = (pNTHeader->OptionalHeader.MajorImageVersion == 20033 && // 'AN' org = (pNTHeader->OptionalHeader.MajorImageVersion == 20033 && // 'AN'
pNTHeader->OptionalHeader.MinorImageVersion == 18771); // 'SI' pNTHeader->OptionalHeader.MinorImageVersion == 18771); // 'SI'
} }

View File

@ -342,7 +342,8 @@ Version History
1.85 - 22 August, 2018: 1.85 - 22 August, 2018:
- fix wrap issues with a buffer bigger than the window; - fix wrap issues with a buffer bigger than the window;
- fix -e et al when redirecting to NUL; - fix -e et al when redirecting to NUL;
- prevent -p from injecting when already injected. - prevent -p from injecting when already injected;
- fix running directly via ansicon (hook even if it's GUI or excluded).
1.84 - 11 May, 2018: 1.84 - 11 May, 2018:
- close the flush handles on detach; - close the flush handles on detach;