Skip to content

Commit eccbbe7

Browse files
committed
Fixes
Unhook on terminate, to properly exit (Vista CMD.EXE and a MinGW-built ansicon.exe would seem to exit okay, but the exit code was wrong). Fixes #123. Verify the DLL exists prior to injection. With the DLL now being added to the import table, failing to find it would prevent the process itself from loading.
1 parent 0472db8 commit eccbbe7

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

ANSI.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
always inject from ansicon.exe, even if it's GUI or excluded;
216216
log CreateFile calls;
217217
preserve last error.
218+
219+
v1.86, 4 November, 2018:
220+
always unhook, even on terminate;
221+
check the DLL still exists before adding to imports.
218222
*/
219223

220224
#include "ansicon.h"
@@ -3026,6 +3030,17 @@ void Inject( DWORD dwCreationFlags, LPPROCESS_INFORMATION lpi,
30263030
}
30273031
if (type > 0)
30283032
{
3033+
#if defined(_WIN64) || defined(W32ON64)
3034+
if (type == 32)
3035+
*(PDWORD)DllNameType = 0x320033/*L'23'*/;
3036+
else
3037+
*(PDWORD)DllNameType = 0x340036/*L'46'*/;
3038+
#endif
3039+
if (GetFileAttributes( DllName ) == INVALID_FILE_ATTRIBUTES)
3040+
type = 0;
3041+
}
3042+
if (type > 0)
3043+
{
30293044
#ifdef _WIN64
30303045
if (type == 64)
30313046
{
@@ -4122,14 +4137,14 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
41224137
if (lpReserved == NULL)
41234138
{
41244139
DEBUGSTR( 1, "Unloading" );
4125-
HookAPIAllMod( Hooks, TRUE, FALSE );
41264140
if (winmm != NULL)
41274141
FreeLibrary( winmm );
41284142
}
41294143
else
41304144
{
41314145
DEBUGSTR( 1, "Terminating" );
41324146
}
4147+
HookAPIAllMod( Hooks, TRUE, FALSE );
41334148
if (orgattr != 0)
41344149
{
41354150
hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,

ansicon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
add log level 32 to log CreateFile.
100100
*/
101101

102-
#define PDATE L"23 August, 2018"
102+
#define PDATE L"4 November, 2018"
103103

104104
#include "ansicon.h"
105105
#include "version.h"

ansicon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <stdio.h>
2424
#include <stdlib.h>
2525

26+
#ifndef INVALID_FILE_ATTRIBUTES
27+
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
28+
#endif
2629
#ifndef LOAD_LIBRARY_AS_IMAGE_RESOURCE
2730
#define LOAD_LIBRARY_AS_IMAGE_RESOURCE 0x20
2831
#endif

readme.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Copyright 2005-2018 Jason Hood
55

6-
Version 1.85. Freeware
6+
Version 1.86. Freeware
77

88

99
Description
@@ -340,6 +340,10 @@ Version History
340340

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

343+
1.86 - 4 November, 2018:
344+
- check the DLL exists before importing it (allows renaming to update);
345+
- unhook on terminate, as well (fixes issues with Vista and MinGW).
346+
343347
1.85 - 23 August, 2018:
344348
- fix wrap issues with a buffer bigger than the window;
345349
- fix -e et al when redirecting to NUL;
@@ -636,5 +640,5 @@ Distribution
636640
in LICENSE.txt.
637641

638642

639-
============================
640-
Jason Hood, 23 August, 2018.
643+
=============================
644+
Jason Hood, 4 November, 2018.

version.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
version.h - Version defines.
33
*/
44

5-
#define PVERS L"1.85" // wide string
6-
#define PVERSA "1.85" // ANSI string (windres 2.16.91 didn't like L)
7-
#define PVERE L"185" // wide environment string
8-
#define PVEREA "185" // ANSI environment string
9-
#define PVERB 1,8,5,0 // binary (resource)
5+
#define PVERS L"1.86" // wide string
6+
#define PVERSA "1.86" // ANSI string (windres 2.16.91 didn't like L)
7+
#define PVERE L"186" // wide environment string
8+
#define PVEREA "186" // ANSI environment string
9+
#define PVERB 1,8,6,0 // binary (resource)
1010

1111
#ifdef _WIN64
1212
# define BITS L"64"

0 commit comments

Comments
 (0)