Пример #1
0
/**
 * Check if the stream is for a Window console.
 *
 * @returns true / false.
 * @param   pStream             The stream.
 * @param   phCon               Where to return the console handle.
 */
static bool rtStrmIsConsoleUnlocked(PRTSTREAM pStream, HANDLE *phCon)
{
    int fh = fileno(pStream->pFile);
    if (isatty(fh))
    {
        DWORD dwMode;
        HANDLE hCon = (HANDLE)_get_osfhandle(fh);
        if (GetConsoleMode(hCon, &dwMode))
        {
            *phCon = hCon;
            return true;
        }
    }
    return false;
}
Пример #2
0
CAMLprim value win_get_console_mode (value unit)
{
  DWORD mode;
  BOOL res;

  init_conin ();

  res = GetConsoleMode (conin, &mode);
  if (res == 0) {
    win32_maperr (GetLastError ());
    uerror("get_console_mode", Nothing);
  }

  return (Val_int (mode));
}
Пример #3
0
void TThreads::resume() {
   if (!inited) {
      SetFileApisToOEM();
      chandle[cnInput]  = GetStdHandle(STD_INPUT_HANDLE);
      chandle[cnOutput] = GetStdHandle(STD_OUTPUT_HANDLE);
      GetConsoleCursorInfo(chandle[cnOutput], &crInfo);
      GetConsoleScreenBufferInfo(chandle[cnOutput], &sbInfo);
      GetConsoleMode(chandle[cnInput],&consoleMode);
      consoleMode &= ~(ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_WINDOW_INPUT);
      SetConsoleMode(chandle[cnInput],consoleMode);

      evpending = 0;
      inited = 1;
   }
}
Пример #4
0
BOOL WINAPI OnPeekConsoleInputA(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)
{
	//typedef BOOL (WINAPI* OnPeekConsoleInputA_t)(HANDLE,PINPUT_RECORD,DWORD,LPDWORD);
	SUPPRESSORIGINALSHOWCALL;
	ORIGINAL_KRNL(PeekConsoleInputA);
	//if (gpFarInfo && bMainThread)
	//	TouchReadPeekConsoleInputs(1);
	BOOL lbRc = FALSE;

	if (ph && ph->PreCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);

		// Если функция возвращает FALSE - реальное чтение не будет вызвано
		if (!ph->PreCallBack(&args))
			return lbRc;
	}

	PreReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_Peek|rcif_LLInput);

	//#ifdef USE_INPUT_SEMAPHORE
	//DWORD nSemaphore = ghConInSemaphore ? WaitForSingleObject(ghConInSemaphore, INSEMTIMEOUT_READ) : 1;
	//_ASSERTE(nSemaphore<=1);
	//#endif

#if 0
	DWORD nMode = 0; GetConsoleMode(hConsoleInput, &nMode);
#endif

	lbRc = F(PeekConsoleInputA)(hConsoleInput, lpBuffer, nLength, lpNumberOfEventsRead);

	PostReadConsoleInput(hConsoleInput, rcif_Ansi|rcif_Peek|rcif_LLInput);

	//#ifdef USE_INPUT_SEMAPHORE
	//if ((nSemaphore == WAIT_OBJECT_0) && ghConInSemaphore) ReleaseSemaphore(ghConInSemaphore, 1, NULL);
	//#endif

	if (ph && ph->PostCallBack)
	{
		SETARGS4(&lbRc,hConsoleInput,lpBuffer,nLength,lpNumberOfEventsRead);
		ph->PostCallBack(&args);
	}

	if (lbRc && lpNumberOfEventsRead && *lpNumberOfEventsRead && lpBuffer)
		OnPeekReadConsoleInput('P', 'A', hConsoleInput, lpBuffer, *lpNumberOfEventsRead);

	return lbRc;
}
Пример #5
0
/*
==================
CON_Init
==================
*/
void CON_Init( void )
{
	CONSOLE_CURSOR_INFO        curs;
	CONSOLE_SCREEN_BUFFER_INFO info;
	int                        i;

	// handle Ctrl-C or other console termination
	SetConsoleCtrlHandler( CON_CtrlHandler, TRUE );

	qconsole_hin = GetStdHandle( STD_INPUT_HANDLE );

	if ( qconsole_hin == INVALID_HANDLE_VALUE )
	{
		return;
	}

	qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE );

	if ( qconsole_hout == INVALID_HANDLE_VALUE )
	{
		return;
	}

	GetConsoleMode( qconsole_hin, &qconsole_orig_mode );

	// allow mouse wheel scrolling
	SetConsoleMode( qconsole_hin,
	                qconsole_orig_mode & ~ENABLE_MOUSE_INPUT );

	FlushConsoleInputBuffer( qconsole_hin );

	GetConsoleScreenBufferInfo( qconsole_hout, &info );
	qconsole_attrib = info.wAttributes;

	SetConsoleTitle( "Daemon Console" );

	// make cursor invisible
	GetConsoleCursorInfo( qconsole_hout, &qconsole_orig_cursorinfo );
	curs.dwSize = 1;
	curs.bVisible = FALSE;
	SetConsoleCursorInfo( qconsole_hout, &curs );

	// initialize history
	for ( i = 0; i < QCONSOLE_HISTORY; i++ )
	{
		qconsole_history[ i ][ 0 ] = '\0';
	}
}
Пример #6
0
static void
disable_quick_edit(void)
{
    DWORD mode = 0;
    HANDLE console = GetStdHandle(STD_INPUT_HANDLE);

    // Get current console mode
    if (console == NULL || !GetConsoleMode(console, &mode)) {
        return;
    }

    // Clear the quick edit bit in the mode flags
    mode &= ~ENABLE_QUICK_EDIT;
    mode |= ENABLE_EXTENDED_FLAGS;
    SetConsoleMode(console, mode);
}
Пример #7
0
ConsoleMedia::ConsoleMedia()
{
    m_bRedirectedToFile = true;

    m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    if (m_hConsole == NULL)
    {
        if (!AllocConsole() //|| !SetConsoleTitle(_T("Log"))
            || (m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE)) == NULL)
            return;
    }
    GetConsoleScreenBufferInfo(m_hConsole, &m_info);

    DWORD t;
    m_bRedirectedToFile = GetConsoleMode(m_hConsole, &t) == FALSE;
}
Пример #8
0
void alloc_console() {
	CONSOLE_SCREEN_BUFFER_INFO coninfo;
	HANDLE hStdin = GetStdHandle (STD_INPUT_HANDLE);
	DWORD lpMode;

	AllocConsole ();
	GetConsoleMode (hStdin, &lpMode);
	SetConsoleMode (hStdin, lpMode & (~ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT));
	GetConsoleScreenBufferInfo (hStdin, &coninfo);
	coninfo.dwSize.Y = 4096;
	SetConsoleScreenBufferSize (hStdin, coninfo.dwSize);

	freopen ("conin$", "r", stdin);
	freopen ("conout$", "w", stdout);
	freopen ("conout$", "w", stderr);
}
Пример #9
0
void console_widget_NT_t::init_new_console()
{	
	allocated_console = false;

	saved_hwnd = GetConsoleWindow();
	if (saved_hwnd == (HWND)0) {
		AllocConsole();
		allocated_console = true;
		saved_hwnd = GetConsoleWindow();
	}

	saved_input = GetStdHandle(STD_INPUT_HANDLE);
	saved_output = GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleCursorInfo(saved_output, &saved_cursor);
	GetConsoleMode(saved_input, &saved_mode);
}
Пример #10
0
int rktio_system_fd_is_terminal(rktio_t *rktio, intptr_t fd)
{
#ifdef RKTIO_SYSTEM_UNIX
  return isatty(fd);
#endif
#ifdef RKTIO_SYSTEM_WINDOWS
  if (GetFileType((HANDLE)fd) == FILE_TYPE_CHAR) {
    DWORD mode;
    if (GetConsoleMode((HANDLE)fd, &mode))
      return 1;
    else
      return 0;
  } else
    return 0;
#endif
}
Пример #11
0
int
SLMprintf(
    WCHAR *szformat, ...)
{
    va_list marker;
    int iret = 0;
    int count;
    long cbWritten;
    DWORD dwMode;

    va_start(marker, szformat);
    count = vswprintf(szText, szformat, marker);

    if (!bUnicode) {
        memset (chBuf, 0, sizeof(chBuf));
#ifdef _WIN32
        WideCharToMultiByte (CP_ACP, 0, szText, count, chBuf, sizeof(chBuf), NULL, NULL);
#else
        wcstombs (chBuf, szText, sizeof(chBuf));
#endif
        iret = printf("%s", chBuf);
        if (fCkSum)
            CheckSum(chBuf, strlen(chBuf));
    }
    else {
#ifdef _WIN32
        if (GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdout)), &dwMode)) {
            WriteConsoleW ((HANDLE)_get_osfhandle(_fileno(stdout)),
                           szText,
                           count,
                           &cbWritten,
                           NULL);
            iret = cbWritten;
        }
        else
            iret = wprintf(szText);
#else
        iret = wprintf(szText);
#endif
        if (fCkSum)
            CheckSum((char *)szText, wcslen(szText) * sizeof(WCHAR));
    }

    va_end(marker);

    return (iret);
}
Пример #12
0
int csync_getpass(const char *prompt,
                char *buf,
                size_t len,
                int echo,
                int verify,
                void *userdata
               ) {
    /* unused variables */
    (void) userdata;

    HANDLE h;
    DWORD mode = 0;
    int ok;

    /* fgets needs at least len - 1 */
    if (prompt == NULL || buf == NULL || len < 2) {
        return -1;
    }

    /* get stdin and mode */
    h = GetStdHandle(STD_INPUT_HANDLE);
    if (!GetConsoleMode(h, &mode)) {
        return -1;
    }

    /* disable echo */
    if (!echo) {
        if (!SetConsoleMode(h, mode & ~ENABLE_ECHO_INPUT)) {
            return -1;
        }
    }

    ok = csync_gets(prompt, buf, len, verify);

    /* reset echo */
    SetConsoleMode(h, mode);

    if (!ok) {
        memset (buf, '\0', len);
        return -1;
    }

    /* force termination */
    buf[len - 1] = '\0';

    return 0;
}
/* ************************************
* VOID ChangeMode( HANDLE hStdin, HANDLE hStdout)
* 功能	改变控制台的模式,关闭ENABLE_LINE_INPUT和ENABLE_ECHO_INPUT
* 参数	HANDLE hStdin, HANDLE hStdout,句柄
**************************************/
VOID ChangeMode( HANDLE hStdin, HANDLE hStdout)
{
		LPSTR lpszPrompt = "Mode changeed Type any key, or q to quit: ";
		CHAR chBuffer[256];

	DWORD fdwMode, fdwOldMode;
	DWORD cRead,cWritten;
	// 获取当前模式
	if (! GetConsoleMode(hStdin, &fdwOldMode)) 
	{
		MessageBox(NULL, "GetConsoleMode", "Console Error", MB_OK); 
		return;
	}
	// 修改模式并重新设置
	fdwMode = fdwOldMode & 
		~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT); 
	if (! SetConsoleMode(hStdin, fdwMode)) 
	{
		MessageBox(NULL, "SetConsoleMode", "Console Error", MB_OK); 
		return;
	}
	// 换行
	NewLine();
	// 循环等待输入并处理
	while (1) 
	{ 
		if (! WriteFile( hStdout, 
			lpszPrompt,  lstrlen(lpszPrompt), 
			&cWritten, NULL) )
		{
			MyErrorExit("WriteFile");
			return;
		}

		if (! ReadFile(hStdin, chBuffer, 1, &cRead, NULL)) 
			break; 
		if (chBuffer[0] == '\r')
			NewLine();
		else if (! WriteFile(hStdout, chBuffer, cRead, 
			&cWritten, NULL)) break;
		else
			NewLine();
		if (chBuffer[0] == 'q') break; // 输入q,退出 
	} 
	// 恢复模式
	SetConsoleMode(hStdin, fdwOldMode);
}
Пример #14
0
R_API RCons *r_cons_new () {
	I.line = r_line_new ();
	I.event_interrupt = NULL;
	I.blankline = R_TRUE;
	I.heightfix = 0;
	I.widthfix = 0;
	I.event_resize = NULL;
	I.data = NULL;
	I.event_data = NULL;
	I.is_interactive = R_TRUE;
	I.noflush = R_FALSE;
	I.force_rows = 0;
	I.force_columns = 0;
	I.fdin = stdin;
	I.fdout = 1;
	I.breaked = R_FALSE;
	//I.lines = 0;
	I.buffer = NULL;
	I.buffer_sz = 0;
	I.buffer_len = 0;
	r_cons_get_size (NULL);
	I.num = NULL;
#if EMSCRIPTEN
	/* do nothing here :? */
#elif __UNIX__
	tcgetattr (0, &I.term_buf);
	memcpy (&I.term_raw, &I.term_buf, sizeof (I.term_raw));
	I.term_raw.c_iflag &= ~(BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
	I.term_raw.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
	I.term_raw.c_cflag &= ~(CSIZE|PARENB);
	I.term_raw.c_cflag |= CS8;
	I.term_raw.c_cc[VMIN] = 1; // Solaris stuff hehe
	signal (SIGWINCH, resize);
#elif __WINDOWS__
	h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, (PDWORD) &I.term_buf);
	I.term_raw = 0;
	if (!SetConsoleCtrlHandler ((PHANDLER_ROUTINE)__w32_control, TRUE))
		eprintf ("r_cons: Cannot set control console handler\n");
#endif
	I.pager = NULL; /* no pager by default */
	I.truecolor = 0;
	r_cons_pal_init (NULL);
	r_cons_rgb_init ();
	r_cons_reset ();
	return &I;
}
Пример #15
0
/* MS runtime's isatty returns non-zero for any character device,
   including the null device, which is not what we want.  */
int
isatty (int fd)
{
  HANDLE fh = (HANDLE) _get_osfhandle (fd);
  DWORD con_mode;

  if (fh == INVALID_HANDLE_VALUE)
    {
      errno = EBADF;
      return 0;
    }
  if (GetConsoleMode (fh, &con_mode))
    return 1;

  errno = ENOTTY;
  return 0;
}
Пример #16
0
JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_getConsoleMode
  (JNIEnv *env, jobject ob)
{
	DWORD mode;
	HANDLE hConsole = GetStdHandle (STD_INPUT_HANDLE);

	if (hConsole == INVALID_HANDLE_VALUE)
		return -1;

	if (!GetConsoleMode (hConsole, &mode))
		return -1;

	// CloseHandle (hConsole);

	// printf ("JNI get mode=%d\n", mode);
	return mode;
}
Пример #17
0
char *
getpass (const char * prompt)
{
  static char input[256];
  HANDLE in;
  HANDLE err;
  DWORD  count;

  in = GetStdHandle (STD_INPUT_HANDLE);
  err = GetStdHandle (STD_ERROR_HANDLE);

  if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
    return NULL;

  if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
    {
      int istty = (GetFileType (in) == FILE_TYPE_CHAR);
      DWORD old_flags;
      int rc;

      if (istty)
	{
	  if (GetConsoleMode (in, &old_flags))
	    SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
	  else
	    istty = 0;
	}
      rc = ReadFile (in, input, sizeof (input), &count, NULL);
      if (count >= 2 && input[count - 2] == '\r')
	input[count - 2] = '\0';
      else
	{
	  char buf[256];
	  while (ReadFile (in, buf, sizeof (buf), &count, NULL) > 0)
	    if (count >= 2 && buf[count - 2] == '\r')
	      break;
	}
      WriteFile (err, "\r\n", 2, &count, NULL);
      if (istty)
	SetConsoleMode (in, old_flags);
      if (rc)
	return input;
    }

  return NULL;
}
Пример #18
0
bool CConsole::Create(const char *szTitle, bool bNoClose)
{
    unsigned long ulMode;
    // Has console been already created?
    if(hConsole != NULL)
        return false;

    // Allocate a new console for our app
    if(!AllocConsole())
        return false;

    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    // Create the actual console
//	hConsole = CreateFile("CONOUT$", GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
    if(hConsole == INVALID_HANDLE_VALUE)
        return false;

    ulMode = (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT );
    if(SetConsoleMode(hConsole, ulMode ) == 0)
        return false;

    // if true, disable the [x] button of the console
    if(bNoClose)
        DisableClose();

    // set the console title
    if(szTitle != NULL)
        SetConsoleTitle(szTitle);


    // Disable QuickEdit mode - it's dangerous:
    // just a click on the console window can stop the application
#define ENABLE_QUICK_EDIT_MODE 0x0040
#define ENABLE_EXTENDED_FLAGS  0x0080
    HANDLE hStdIn;
    hStdIn = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hStdIn,  &ulMode );

    ulMode |= ENABLE_EXTENDED_FLAGS;
    ulMode &= ~ENABLE_QUICK_EDIT_MODE;
    if(SetConsoleMode(hStdIn,  ulMode ) == 0)
        return false;

    return true;
}
Пример #19
0
int
SLMprintfLn(
    WCHAR *szLine)
{
    long cbWritten;
    WORD count;
    BYTE *lpBuf;
    DWORD dwMode;

    count = wcslen(szLine);

    if (!bUnicode) {
        lpBuf = pvAllocMem (count + 50);
        memset (lpBuf, 0, count + 50);
#ifdef _WIN32
        WideCharToMultiByte (CP_ACP, 0, szLine, count, lpBuf, count + 50, NULL, NULL);
#else
        wcstombs (lpBuf, szLine, count + 50);
#endif
        count = printf("%s", lpBuf);

        if (fCkSum)
            CheckSum(lpBuf, strlen(lpBuf));

        FreeMem (lpBuf);

        return (count);
    }
    else {
        if (fCkSum)
            CheckSum((char *)szLine, count * sizeof(WCHAR));

#ifdef _WIN32
        if (GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdout)), &dwMode))
            return (WriteConsoleW ((HANDLE)_get_osfhandle(_fileno(stdout)),
                                   szLine,
                                   wcslen(szLine),
                                   &cbWritten,
                                   NULL));
        else
            return (wprintf(L"%s", szLine));
#else
        return (wprintf(L"%s", szLine));
#endif
    }
}
Пример #20
0
JNIEXPORT jint JNICALL Java_org_trafodion_ci_WCIUtils_getConsoleMode
   (JNIEnv *env, jobject ob)
{
   DWORD mode;
   HANDLE hConsole = GetStdHandle (STD_INPUT_HANDLE);

   if (hConsole == INVALID_HANDLE_VALUE)
      return -1;

   if (!GetConsoleMode (hConsole, &mode))
      return -1;

   // CloseHandle (hConsole);
   //printf ("JNI get mode=%d\n", mode);

   return mode;
}
Пример #21
0
static int enableRawMode(int fd) {
#ifdef _WIN32
    if (!console_in) {
        console_in = GetStdHandle(STD_INPUT_HANDLE);
        console_out = GetStdHandle(STD_OUTPUT_HANDLE);

        GetConsoleMode(console_in, &oldMode);
        SetConsoleMode(console_in, oldMode & ~(ENABLE_LINE_INPUT | ENABLE_LINE_INPUT));
    }
    return 0;
#else
    struct termios raw;

    if (!isatty(STDIN_FILENO)) goto fatal;
    if (!atexit_registered) {
        atexit(linenoiseAtExit);
        atexit_registered = 1;
    }
    if (tcgetattr(fd,&orig_termios) == -1) goto fatal;

    raw = orig_termios;  /* modify the original mode */
    /* input modes: no break, no CR to NL, no parity check, no strip char,
     * no start/stop output control. */
    raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
    /* output modes - disable post processing */
    raw.c_oflag &= ~(OPOST);
    /* control modes - set 8 bit chars */
    raw.c_cflag |= (CS8);
    /* local modes - choing off, canonical off, no extended functions,
     * no signal chars (^Z,^C) */
    raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
    /* control chars - set return condition: min number of bytes and timer.
     * We want read to return every single byte, without timeout. */
    raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */

    /* put terminal in raw mode after flushing */
    if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal;
    rawmode = 1;
    return 0;

fatal:
    errno = ENOTTY;
    return -1;
#endif
}
Пример #22
0
/*
 * Ask whether to wipe a session log file before writing to it.
 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
 */
int askappend(char *filename)
{
    HANDLE hin;
    DWORD savemode, i;

    static const char msgtemplate[] =
	"The session log file \"%.*s\" already exists.\n"
	"You can overwrite it with a new session log,\n"
	"append your session log to the end of it,\n"
	"or disable session logging for this session.\n"
	"Enter \"y\" to wipe the file, \"n\" to append to it,\n"
	"or just press Return to disable logging.\n"
	"Wipe the log file? (y/n, Return cancels logging) ";

    static const char msgtemplate_batch[] =
	"The session log file \"%.*s\" already exists.\n"
	"Logging will not be enabled.\n";

    char line[32];

    if (cfg.logxfovr != LGXF_ASK) {
	return ((cfg.logxfovr == LGXF_OVR) ? 2 : 1);
    }
    if (console_batch_mode) {
	fprintf(stderr, msgtemplate_batch, FILENAME_MAX, filename);
	fflush(stderr);
	return 0;
    }
    fprintf(stderr, msgtemplate, FILENAME_MAX, filename);
    fflush(stderr);

    hin = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hin, &savemode);
    SetConsoleMode(hin, (savemode | ENABLE_ECHO_INPUT |
			 ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
    ReadFile(hin, line, sizeof(line) - 1, &i, NULL);
    SetConsoleMode(hin, savemode);

    if (line[0] == 'y' || line[0] == 'Y')
	return 2;
    else if (line[0] == 'n' || line[0] == 'N')
	return 1;
    else
	return 0;
}
Пример #23
0
/*
 * Ask whether the selected cipher is acceptable (since it was
 * below the configured 'warn' threshold).
 * cs: 0 = both ways, 1 = client->server, 2 = server->client
 */
void askcipher(char *ciphername, int cs)
{
    HANDLE hin;
    DWORD savemode, i;

    static const char msg[] =
	"The first %scipher supported by the server is\n"
	"%s, which is below the configured warning threshold.\n"
	"Continue with connection? (y/n) ";
    static const char msg_batch[] =
	"The first %scipher supported by the server is\n"
	"%s, which is below the configured warning threshold.\n"
	"Connection abandoned.\n";
    static const char abandoned[] = "Connection abandoned.\n";

    char line[32];

    if (console_batch_mode) {
	fprintf(stderr, msg_batch,
		(cs == 0) ? "" :
		(cs == 1) ? "client-to-server " : "server-to-client ",
		ciphername);
	cleanup_exit(1);
    }

    fprintf(stderr, msg,
	    (cs == 0) ? "" :
	    (cs == 1) ? "client-to-server " : "server-to-client ",
	    ciphername);
    fflush(stderr);

    hin = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hin, &savemode);
    SetConsoleMode(hin, (savemode | ENABLE_ECHO_INPUT |
			 ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
    ReadFile(hin, line, sizeof(line) - 1, &i, NULL);
    SetConsoleMode(hin, savemode);

    if (line[0] == 'y' || line[0] == 'Y') {
	return;
    } else {
	fprintf(stderr, abandoned);
	cleanup_exit(0);
    }
}
Пример #24
0
void setEcho(int flag) 
{
#ifdef WINDOWS
   HANDLE hConsole;
   DWORD  dwMode;

   hConsole = CreateFile("CONIN$", 
              GENERIC_READ|GENERIC_WRITE, 
              FILE_SHARE_READ|FILE_SHARE_WRITE,
              NULL,
              OPEN_EXISTING,
              0,
              NULL);

   if(hConsole != INVALID_HANDLE_VALUE) {
      GetConsoleMode(hConsole, &dwMode);
      if(flag) {
         dwMode |= ENABLE_ECHO_INPUT;
      } else {
         dwMode &= ~ENABLE_ECHO_INPUT;
      }
      SetConsoleMode(hConsole, dwMode);
      CloseHandle(hConsole);
   }
#else /* unix */
   static struct termios init_set;
   static int initialized = 0;

   struct termios new_set;
   
   if(initialized == 0) {
      tcgetattr(fileno(stdin), &init_set);
      initialized = 1;
   }

   new_set = init_set;
   if(flag) {   
      tcsetattr(fileno(stdin), TCSAFLUSH, &init_set);
   } else {
      new_set.c_lflag &= ~ECHO;
      tcsetattr(fileno(stdin), TCSAFLUSH, &new_set);
   }

#endif
}
Пример #25
0
int simple_get_pass(char* passwd, size_t max_size){
    int ret = 0;
#if defined HAVE_TERMIOS_H
    struct termios old_term, new_term;
    FILE* stream = stdin;

    /* Turn echoing off and fail if we can't. */
    if (tcgetattr (fileno (stream), &old_term) != 0)
      return -1;
    new_term = old_term;
    new_term.c_lflag &= ~ECHO;
    if (tcsetattr (fileno (stream), TCSAFLUSH, &new_term) != 0)
      return -1;

    /* Read the password. */
    std::cin.getline(passwd, max_size);
    ret = strlen(passwd);

    /* Restore terminal. */
    (void) tcsetattr (fileno (stream), TCSAFLUSH, &old_term);

#elif HAVE_SETCONSOLEMODE
	HANDLE hstdin = GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	
	if (!GetConsoleMode(hstdin, &mode))
		return -1;

	if (hstdin == INVALID_HANDLE_VALUE || !(SetConsoleMode(hstdin, 0)))
		return -1; 
    std::cin.getline(passwd, max_size);
    ret = strlen(passwd);
	
	if (!SetConsoleMode(hstdin, mode))
		return -1;		
#else
    char* p;
    if((p = getpass("")) == NULL)
        return -1;
    *passwd = strdup(p);
    ret = strlen(p);
#endif
    return ret;

}
Пример #26
0
static int enableRawMode(struct current *current) {
    DWORD n;
    INPUT_RECORD irec;

    current->outh = GetStdHandle(STD_OUTPUT_HANDLE);
    current->inh = GetStdHandle(STD_INPUT_HANDLE);

    if (!PeekConsoleInput(current->inh, &irec, 1, &n)) {
        return -1;
    }
    if (getWindowSize(current) != 0) {
        return -1;
    }
    if (GetConsoleMode(current->inh, &orig_consolemode)) {
        SetConsoleMode(current->inh, ENABLE_PROCESSED_INPUT);
    }
    return 0;
}
Пример #27
0
void qemu_set_tty_echo(int fd, bool echo)
{
    HANDLE handle = (HANDLE)_get_osfhandle(fd);
    DWORD dwMode = 0;

    if (handle == INVALID_HANDLE_VALUE) {
        return;
    }

    GetConsoleMode(handle, &dwMode);

    if (echo) {
        SetConsoleMode(handle, dwMode | ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
    } else {
        SetConsoleMode(handle,
                       dwMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
    }
}
Пример #28
0
void init_console(void)
{
  int Mode;
  struct _CONSOLE_SCREEN_BUFFER_INFO sbi;
  HANDLE    Hstd;
  FILE      *stream;

  Hstd = GetStdHandle(STD_INPUT_HANDLE);
  AllocConsole();
  GetConsoleMode(Hstd, (LPDWORD)&Mode);
  SetConsoleMode(Hstd, Mode & 0xFFFFFFEF);
  GetConsoleScreenBufferInfo(Hstd, &sbi);
  sbi.dwSize.Y = 4096;
  SetConsoleScreenBufferSize(Hstd, sbi.dwSize);
  freopen_s(&stream, "conin$", "r", stdin);
  freopen_s(&stream, "conout$", "w", stdout);
  freopen_s(&stream, "conout$", "w", stderr);
}
Пример #29
0
static int disable_echo(void)
{
	hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
	    FILE_SHARE_READ, NULL, OPEN_EXISTING,
	    FILE_ATTRIBUTE_NORMAL, NULL);
	if (hconin == INVALID_HANDLE_VALUE)
		return -1;

	GetConsoleMode(hconin, &cmode);
	sigchain_push_common(restore_term_on_signal);
	if (!SetConsoleMode(hconin, cmode & (~ENABLE_ECHO_INPUT))) {
		CloseHandle(hconin);
		hconin = INVALID_HANDLE_VALUE;
		return -1;
	}

	return 0;
}
Пример #30
0
static void installsighandler()
{
	#ifndef _WIN32
		signal(SIGHUP,sighandler);
		signal(SIGUSR1,sighandler);
		signal(SIGPIPE,sighandler);
	#endif
	signal(SIGINT,sighandler);
	#ifdef _WIN32
		SetConsoleCtrlHandler(ConsoleCtrlHandler,true);
		HANDLE hs=GetStdHandle(STD_INPUT_HANDLE);
		DWORD mode;
		if (GetConsoleMode(hs,&mode)) {
			mode|=ENABLE_PROCESSED_INPUT;
			SetConsoleMode(hs,mode);
		};
	#endif
}