Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adoxa committed Nov 4, 2018
1 parent 0472db8 commit eccbbe7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
17 changes: 16 additions & 1 deletion ANSI.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@
always inject from ansicon.exe, even if it's GUI or excluded;
log CreateFile calls;
preserve last error.
v1.86, 4 November, 2018:
always unhook, even on terminate;
check the DLL still exists before adding to imports.
*/

#include "ansicon.h"
Expand Down Expand Up @@ -3026,6 +3030,17 @@ void Inject( DWORD dwCreationFlags, LPPROCESS_INFORMATION lpi,
}
if (type > 0)
{
#if defined(_WIN64) || defined(W32ON64)
if (type == 32)
*(PDWORD)DllNameType = 0x320033/*L'23'*/;
else
*(PDWORD)DllNameType = 0x340036/*L'46'*/;
#endif
if (GetFileAttributes( DllName ) == INVALID_FILE_ATTRIBUTES)
type = 0;
}
if (type > 0)
{
#ifdef _WIN64
if (type == 64)
{
Expand Down Expand Up @@ -4122,14 +4137,14 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
if (lpReserved == NULL)
{
DEBUGSTR( 1, "Unloading" );
HookAPIAllMod( Hooks, TRUE, FALSE );
if (winmm != NULL)
FreeLibrary( winmm );
}
else
{
DEBUGSTR( 1, "Terminating" );
}
HookAPIAllMod( Hooks, TRUE, FALSE );
if (orgattr != 0)
{
hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
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"23 August, 2018"
#define PDATE L"4 November, 2018"

#include "ansicon.h"
#include "version.h"
Expand Down
3 changes: 3 additions & 0 deletions ansicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <stdio.h>
#include <stdlib.h>

#ifndef INVALID_FILE_ATTRIBUTES
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
#endif
#ifndef LOAD_LIBRARY_AS_IMAGE_RESOURCE
#define LOAD_LIBRARY_AS_IMAGE_RESOURCE 0x20
#endif
Expand Down
10 changes: 7 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Copyright 2005-2018 Jason Hood

Version 1.85. Freeware
Version 1.86. Freeware


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

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

1.86 - 4 November, 2018:
- check the DLL exists before importing it (allows renaming to update);
- unhook on terminate, as well (fixes issues with Vista and MinGW).

1.85 - 23 August, 2018:
- fix wrap issues with a buffer bigger than the window;
- fix -e et al when redirecting to NUL;
Expand Down Expand Up @@ -636,5 +640,5 @@ Distribution
in LICENSE.txt.


============================
Jason Hood, 23 August, 2018.
=============================
Jason Hood, 4 November, 2018.
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.85" // wide string
#define PVERSA "1.85" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"185" // wide environment string
#define PVEREA "185" // ANSI environment string
#define PVERB 1,8,5,0 // binary (resource)
#define PVERS L"1.86" // wide string
#define PVERSA "1.86" // ANSI string (windres 2.16.91 didn't like L)
#define PVERE L"186" // wide environment string
#define PVEREA "186" // ANSI environment string
#define PVERB 1,8,6,0 // binary (resource)

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

0 comments on commit eccbbe7

Please sign in to comment.