From eec487abb6127e1b075aec382e40b90a8f767b94 Mon Sep 17 00:00:00 2001 From: Jason Hood Date: Thu, 23 Aug 2018 17:06:49 +1000 Subject: [PATCH] Prevent -p injecting when already injected Don't inject into the parent if injection has already occurred. This prevents the reference count from increasing, allowing a single -pu to unload, rather than one -pu for each -p. --- ansicon.c | 12 +++++++++--- readme.txt | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ansicon.c b/ansicon.c index 1399f20..92c35b7 100644 --- a/ansicon.c +++ b/ansicon.c @@ -94,7 +94,8 @@ import the DLL. v1.85, 22 August, 2018: - use IsConsoleHandle for my_fputws, to distinguish NUL. + use IsConsoleHandle for my_fputws, to distinguish NUL; + don't load into the parent if already loaded. */ #define PDATE L"22 August, 2018" @@ -219,10 +220,10 @@ void RemoteLoad( LPPROCESS_INFORMATION ppi, LPCTSTR app, BOOL unload ) if (_wcsicmp( me.szModule, L"kernel32.dll" ) == 0) { proc = me.modBaseAddr; - if (!unload || param) + if (param) break; } - else if (unload) + else { #ifdef _WIN64 if (_wcsicmp( me.szModule, DllNameType - 4 ) == 0) @@ -247,6 +248,11 @@ void RemoteLoad( LPPROCESS_INFORMATION ppi, LPCTSTR app, BOOL unload ) DEBUGSTR( 1, " Unable to locate ANSICON's DLL" ); return; } + else if (!unload && param != NULL) + { + DEBUGSTR( 1, " ANSICON already loaded" ); + return; + } #ifdef _WIN64 rva = GetProcRVA( L"kernel32.dll", (unload) ? "FreeLibrary" diff --git a/readme.txt b/readme.txt index 8e2b007..1c065b3 100644 --- a/readme.txt +++ b/readme.txt @@ -341,7 +341,8 @@ Version History 1.85 - 22 August, 2018: - 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. 1.84 - 11 May, 2018: - close the flush handles on detach;