mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
win32.c: disable console colorizing
* win32/win32.c (console_emulator_p, constat_handle): disable built-in console colorizing when console-emulator-like DLL is injected. [Feature #8201] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fa105e6c20
commit
886e3bb1df
4 changed files with 48 additions and 4 deletions
|
@ -39,6 +39,8 @@
|
|||
#include <share.h>
|
||||
#include <shlobj.h>
|
||||
#include <mbstring.h>
|
||||
#include <psapi.h>
|
||||
#include <shlwapi.h>
|
||||
#if _MSC_VER >= 1400
|
||||
#include <crtdbg.h>
|
||||
#include <rtcapi.h>
|
||||
|
@ -604,6 +606,7 @@ static CRITICAL_SECTION select_mutex;
|
|||
static int NtSocketsInitialized = 0;
|
||||
static st_table *socklist = NULL;
|
||||
static st_table *conlist = NULL;
|
||||
#define conlist_disabled ((st_table *)-1)
|
||||
static char *envarea;
|
||||
static char *uenvarea;
|
||||
|
||||
|
@ -629,7 +632,7 @@ free_conlist(st_data_t key, st_data_t val, st_data_t arg)
|
|||
static void
|
||||
constat_delete(HANDLE h)
|
||||
{
|
||||
if (conlist) {
|
||||
if (conlist && conlist != conlist_disabled) {
|
||||
st_data_t key = (st_data_t)h, val;
|
||||
st_delete(conlist, &key, &val);
|
||||
xfree((struct constat *)val);
|
||||
|
@ -649,7 +652,7 @@ exit_handler(void)
|
|||
DeleteCriticalSection(&select_mutex);
|
||||
NtSocketsInitialized = 0;
|
||||
}
|
||||
if (conlist) {
|
||||
if (conlist && conlist != conlist_disabled) {
|
||||
st_foreach(conlist, free_conlist, 0);
|
||||
st_free_table(conlist);
|
||||
conlist = NULL;
|
||||
|
@ -5831,6 +5834,33 @@ rb_w32_pipe(int fds[2])
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
static int
|
||||
console_emulator_p(void)
|
||||
{
|
||||
HMODULE module_buf[10], *pmodule = module_buf;
|
||||
DWORD nmodule = numberof(module_buf), needed = 0, i;
|
||||
HANDLE proch = GetCurrentProcess();
|
||||
|
||||
if (!EnumProcessModules(proch, pmodule, nmodule * sizeof(HMODULE), &needed))
|
||||
return FALSE;
|
||||
if (needed / sizeof(HMODULE) > nmodule) {
|
||||
nmodule = needed / sizeof(HMODULE);
|
||||
pmodule = alloca(sizeof(HMODULE) * nmodule);
|
||||
if (!EnumProcessModules(proch, pmodule, needed, &needed))
|
||||
return FALSE;
|
||||
}
|
||||
for (i = 0; i < nmodule; i++) {
|
||||
WCHAR modname[MAX_PATH];
|
||||
|
||||
if (GetModuleBaseNameW(proch, pmodule[i], modname, numberof(modname))) {
|
||||
if (PathMatchSpecW(modname, L"conemu*.dll")) return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* License: Ruby's */
|
||||
static struct constat *
|
||||
constat_handle(HANDLE h)
|
||||
|
@ -5838,8 +5868,15 @@ constat_handle(HANDLE h)
|
|||
st_data_t data;
|
||||
struct constat *p;
|
||||
if (!conlist) {
|
||||
if (console_emulator_p()) {
|
||||
conlist = conlist_disabled;
|
||||
return NULL;
|
||||
}
|
||||
conlist = st_init_numtable();
|
||||
}
|
||||
else if (conlist == conlist_disabled) {
|
||||
return NULL;
|
||||
}
|
||||
if (st_lookup(conlist, (st_data_t)h, &data)) {
|
||||
p = (struct constat *)data;
|
||||
}
|
||||
|
@ -6483,6 +6520,7 @@ rb_w32_write_console(uintptr_t strarg, int fd)
|
|||
return -1L;
|
||||
|
||||
s = constat_handle(handle);
|
||||
if (!s) return -1L;
|
||||
encindex = ENCODING_GET(str);
|
||||
switch (encindex) {
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue