General maintenance.
This commit is contained in:
parent
0c1ddeb8ea
commit
dd4e45686b
51
ANSI.c
51
ANSI.c
@ -391,15 +391,15 @@ void SendSequence( LPTSTR seq )
|
|||||||
INPUT_RECORD in;
|
INPUT_RECORD in;
|
||||||
HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );
|
HANDLE hStdIn = GetStdHandle( STD_INPUT_HANDLE );
|
||||||
|
|
||||||
|
in.EventType = KEY_EVENT;
|
||||||
|
in.Event.KeyEvent.bKeyDown = TRUE;
|
||||||
|
in.Event.KeyEvent.wRepeatCount = 1;
|
||||||
|
in.Event.KeyEvent.wVirtualKeyCode = 0;
|
||||||
|
in.Event.KeyEvent.wVirtualScanCode = 0;
|
||||||
|
in.Event.KeyEvent.dwControlKeyState = 0;
|
||||||
for (; *seq; ++seq)
|
for (; *seq; ++seq)
|
||||||
{
|
{
|
||||||
in.EventType = KEY_EVENT;
|
|
||||||
in.Event.KeyEvent.bKeyDown = TRUE;
|
|
||||||
in.Event.KeyEvent.wRepeatCount = 1;
|
|
||||||
in.Event.KeyEvent.wVirtualKeyCode = 0;
|
|
||||||
in.Event.KeyEvent.wVirtualScanCode = 0;
|
|
||||||
in.Event.KeyEvent.uChar.UnicodeChar = *seq;
|
in.Event.KeyEvent.uChar.UnicodeChar = *seq;
|
||||||
in.Event.KeyEvent.dwControlKeyState = 0;
|
|
||||||
WriteConsoleInput( hStdIn, &in, 1, &out );
|
WriteConsoleInput( hStdIn, &in, 1, &out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -733,16 +733,24 @@ void InterpretEscSeq( void )
|
|||||||
|
|
||||||
case 'n': // ESC[#n Device status report
|
case 'n': // ESC[#n Device status report
|
||||||
if (es_argc != 1) return; // ESC[n == ESC[0n -> ignored
|
if (es_argc != 1) return; // ESC[n == ESC[0n -> ignored
|
||||||
if (es_argv[0] == 5)
|
switch (es_argv[0])
|
||||||
SendSequence( L"\x1b[0n" ); // "OK"
|
|
||||||
else if (es_argv[0] == 6)
|
|
||||||
{
|
{
|
||||||
TCHAR buf[32];
|
case 5: // ESC[5n Report status
|
||||||
wsprintf( buf, L"\x1b[%d;%dR", Info.dwCursorPosition.Y + 1,
|
SendSequence( L"\33[0n" ); // "OK"
|
||||||
Info.dwCursorPosition.X + 1 );
|
return;
|
||||||
SendSequence( buf );
|
|
||||||
|
case 6: // ESC[6n Report cursor position
|
||||||
|
{
|
||||||
|
TCHAR buf[32];
|
||||||
|
wsprintf( buf, L"\33[%d;%dR", Info.dwCursorPosition.Y + 1,
|
||||||
|
Info.dwCursorPosition.X + 1 );
|
||||||
|
SendSequence( buf );
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
|
||||||
case 't': // ESC[#t Window manipulation
|
case 't': // ESC[#t Window manipulation
|
||||||
if (es_argc != 1) return;
|
if (es_argc != 1) return;
|
||||||
@ -769,7 +777,7 @@ void InterpretEscSeq( void )
|
|||||||
{
|
{
|
||||||
if (es_argc == 1 && es_argv[0] == 0) // ESC]0;titleST
|
if (es_argc == 1 && es_argv[0] == 0) // ESC]0;titleST
|
||||||
{
|
{
|
||||||
DEBUGSTR( L"SetConsoleTitle = %d", SetConsoleTitle( Pt_arg ) );
|
SetConsoleTitle( Pt_arg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1067,7 +1075,8 @@ WINAPI MyWriteConsoleA( HANDLE hCon, LPCVOID lpBuffer,
|
|||||||
if (GetConsoleMode( hCon, &Mode ) && (Mode & ENABLE_PROCESSED_OUTPUT))
|
if (GetConsoleMode( hCon, &Mode ) && (Mode & ENABLE_PROCESSED_OUTPUT))
|
||||||
{
|
{
|
||||||
UINT cp = GetConsoleOutputCP();
|
UINT cp = GetConsoleOutputCP();
|
||||||
DEBUGSTR( L"\\WriteConsoleA: %lu \"%.*S\"", nNumberOfCharsToWrite, nNumberOfCharsToWrite, lpBuffer );
|
DEBUGSTR( L"\\WriteConsoleA: %lu \"%.*S\"",
|
||||||
|
nNumberOfCharsToWrite, nNumberOfCharsToWrite, lpBuffer );
|
||||||
len = MultiByteToWideChar( cp, 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0 );
|
len = MultiByteToWideChar( cp, 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0 );
|
||||||
buf = malloc( len * sizeof(WCHAR) );
|
buf = malloc( len * sizeof(WCHAR) );
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
@ -1079,7 +1088,8 @@ WINAPI MyWriteConsoleA( HANDLE hCon, LPCVOID lpBuffer,
|
|||||||
MultiByteToWideChar( cp, 0, lpBuffer, nNumberOfCharsToWrite, buf, len );
|
MultiByteToWideChar( cp, 0, lpBuffer, nNumberOfCharsToWrite, buf, len );
|
||||||
rc = ParseAndPrintString( hCon, buf, len, lpNumberOfCharsWritten );
|
rc = ParseAndPrintString( hCon, buf, len, lpNumberOfCharsWritten );
|
||||||
free( buf );
|
free( buf );
|
||||||
if (rc && *lpNumberOfCharsWritten != nNumberOfCharsToWrite)
|
if (rc && lpNumberOfCharsWritten != NULL &&
|
||||||
|
*lpNumberOfCharsWritten != nNumberOfCharsToWrite)
|
||||||
{
|
{
|
||||||
// Converting a multibyte character to Unicode results in a different
|
// Converting a multibyte character to Unicode results in a different
|
||||||
// "character" count. This causes some programs to think not everything
|
// "character" count. This causes some programs to think not everything
|
||||||
@ -1088,7 +1098,7 @@ WINAPI MyWriteConsoleA( HANDLE hCon, LPCVOID lpBuffer,
|
|||||||
TCHAR env[2048];
|
TCHAR env[2048];
|
||||||
if (GetEnvironmentVariable( L"ANSICON_API", env, lenof(env) ))
|
if (GetEnvironmentVariable( L"ANSICON_API", env, lenof(env) ))
|
||||||
{
|
{
|
||||||
BOOL not;
|
BOOL not;
|
||||||
|
|
||||||
not = (*env == '!');
|
not = (*env == '!');
|
||||||
if (not && env[1] == '\0')
|
if (not && env[1] == '\0')
|
||||||
@ -1138,7 +1148,8 @@ WINAPI MyWriteConsoleW( HANDLE hCon, LPCVOID lpBuffer,
|
|||||||
DWORD Mode;
|
DWORD Mode;
|
||||||
if (GetConsoleMode( hCon, &Mode ) && (Mode & ENABLE_PROCESSED_OUTPUT))
|
if (GetConsoleMode( hCon, &Mode ) && (Mode & ENABLE_PROCESSED_OUTPUT))
|
||||||
{
|
{
|
||||||
DEBUGSTR( L"\\WriteConsoleW: %lu \"%.*s\"", nNumberOfCharsToWrite, nNumberOfCharsToWrite, lpBuffer );
|
DEBUGSTR( L"\\WriteConsoleW: %lu \"%.*s\"",
|
||||||
|
nNumberOfCharsToWrite, nNumberOfCharsToWrite, lpBuffer );
|
||||||
return ParseAndPrintString( hCon, lpBuffer,
|
return ParseAndPrintString( hCon, lpBuffer,
|
||||||
nNumberOfCharsToWrite,
|
nNumberOfCharsToWrite,
|
||||||
lpNumberOfCharsWritten );
|
lpNumberOfCharsWritten );
|
||||||
@ -1278,7 +1289,7 @@ BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
|
|||||||
if (dwReason == DLL_PROCESS_ATTACH)
|
if (dwReason == DLL_PROCESS_ATTACH)
|
||||||
{
|
{
|
||||||
#if (MYDEBUG > 1)
|
#if (MYDEBUG > 1)
|
||||||
DEBUGSTR( NULL );
|
DEBUGSTR( NULL ); // create a new file
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hDllInstance = hInstance; // save Dll instance handle
|
hDllInstance = hInstance; // save Dll instance handle
|
||||||
|
@ -100,7 +100,7 @@ BOOL Inject( LPPROCESS_INFORMATION ppi )
|
|||||||
while (dll[len-1] != '\\')
|
while (dll[len-1] != '\\')
|
||||||
--len;
|
--len;
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
swprintf( dll + len, L"ANSI%d.dll", type );
|
wsprintf( dll + len, L"ANSI%d.dll", type );
|
||||||
if (type == 32)
|
if (type == 32)
|
||||||
InjectDLL32( ppi, dll );
|
InjectDLL32( ppi, dll );
|
||||||
else
|
else
|
||||||
@ -233,7 +233,14 @@ int main( void )
|
|||||||
{
|
{
|
||||||
ansi = 0;
|
ansi = 0;
|
||||||
if (!installed)
|
if (!installed)
|
||||||
|
{
|
||||||
ansi = LoadLibrary( L"ANSI" BITS L".dll" );
|
ansi = LoadLibrary( L"ANSI" BITS L".dll" );
|
||||||
|
if (!ansi)
|
||||||
|
{
|
||||||
|
fputws( L"ANSICON: failed to load ANSI" BITS L".dll.\n", stderr );
|
||||||
|
rc = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (option && (argv[1][1] == 't' || argv[1][1] == 'T'))
|
if (option && (argv[1][1] == 't' || argv[1][1] == 'T'))
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ void InjectDLL64( LPPROCESS_INFORMATION, LPCTSTR );
|
|||||||
// ========== Auxiliary debug function
|
// ========== Auxiliary debug function
|
||||||
|
|
||||||
//#define MYDEBUG 1 // use OutputDebugString
|
//#define MYDEBUG 1 // use OutputDebugString
|
||||||
#define MYDEBUG 2 // use %temp%\ansicon.log
|
//#define MYDEBUG 2 // use %temp%\ansicon.log
|
||||||
#ifndef MYDEBUG
|
#ifndef MYDEBUG
|
||||||
# define MYDEBUG 0 // no debugging
|
# define MYDEBUG 0 // no debugging
|
||||||
#endif
|
#endif
|
||||||
@ -37,7 +37,7 @@ void InjectDLL64( LPPROCESS_INFORMATION, LPCTSTR );
|
|||||||
void DEBUGSTR( LPTSTR szFormat, ... );
|
void DEBUGSTR( LPTSTR szFormat, ... );
|
||||||
#else
|
#else
|
||||||
# if defined(_MSC_VER) && _MSC_VER <= 1400
|
# if defined(_MSC_VER) && _MSC_VER <= 1400
|
||||||
void DEBUGSTR() { }
|
#define DEBUGSTR (void)
|
||||||
# else
|
# else
|
||||||
# define DEBUGSTR(...)
|
# define DEBUGSTR(...)
|
||||||
# endif
|
# endif
|
||||||
|
@ -17,15 +17,12 @@ void DEBUGSTR( LPTSTR szFormat, ... ) // sort of OutputDebugStringf
|
|||||||
#if (MYDEBUG > 1)
|
#if (MYDEBUG > 1)
|
||||||
if (*tempfile == '\0')
|
if (*tempfile == '\0')
|
||||||
_snprintf( tempfile, MAX_PATH, "%s\\ansicon.log", getenv( "TEMP" ) );
|
_snprintf( tempfile, MAX_PATH, "%s\\ansicon.log", getenv( "TEMP" ) );
|
||||||
#endif
|
|
||||||
|
|
||||||
if (szFormat == NULL)
|
if (szFormat == NULL)
|
||||||
{
|
{
|
||||||
#if (MYDEBUG > 1)
|
|
||||||
DeleteFileA( tempfile );
|
DeleteFileA( tempfile );
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
va_start( pArgList, szFormat );
|
va_start( pArgList, szFormat );
|
||||||
_vsnwprintf( szBuffer, lenof(szBuffer), szFormat, pArgList );
|
_vsnwprintf( szBuffer, lenof(szBuffer), szFormat, pArgList );
|
||||||
|
2
makefile
2
makefile
@ -1,4 +1,4 @@
|
|||||||
# Simple makefile for ANSICON.
|
# Makefile for ANSICON.
|
||||||
# Jason Hood, 11 March, 2006. Updated 20 June, 2009.
|
# Jason Hood, 11 March, 2006. Updated 20 June, 2009.
|
||||||
|
|
||||||
# I've used TDM64 (gcc 4.5.0), building the 32-bit version in the x86 directory
|
# I've used TDM64 (gcc 4.5.0), building the 32-bit version in the x86 directory
|
||||||
|
@ -137,8 +137,8 @@
|
|||||||
|
|
||||||
If running CMD.EXE, its own COLOR will be the initial color.
|
If running CMD.EXE, its own COLOR will be the initial color.
|
||||||
|
|
||||||
The 64-bit version can inject into a 32-bit process, but that will not
|
The 64-bit version can inject into a 32-bit process, but the 32-bit
|
||||||
then inject into a 64-bit process.
|
version will not inject into a 64-bit process.
|
||||||
|
|
||||||
|
|
||||||
===============
|
===============
|
||||||
|
Loading…
x
Reference in New Issue
Block a user