Example #1
0
ssize_t
read_win32(int fildes, void *buf, size_t nbyte)
{
   DWORD val=0;

   DWORD filetype = GetFileType((HANDLE) fildes);

   if (fildes == fileno(stdin))
   {
      ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, nbyte, &val, NULL);
   }
   else if (filetype == FILE_TYPE_DISK) 
   {
      ReadFile((HANDLE)fildes, buf, nbyte, &val, NULL);
   } 
   else if (filetype == FILE_TYPE_CHAR) 
   {
      ReadConsole(GetStdHandle(STD_INPUT_HANDLE), buf, nbyte, &val, NULL);
   } 
   else 
   {
      OVERLAPPED overlap;
      overlap.hEvent = (HANDLE)NULL;
      if (ReadFile((HANDLE) fildes, buf, nbyte, &val, &overlap)==FALSE) 
      {
         if (!GetOverlappedResult((HANDLE) fildes, &overlap, &val, TRUE)) 
         {
            const DWORD error = GetLastError();
            cerr << "read_win32, error is: " << error << " - "
               << " - " << fildes << endl;
         }
      }
   }
   return val;
}
Example #2
0
std::tstring Console::ReadLine(void)
{
	std::vector<tchar_t>	accumulator;			// Character accumulator
	DWORD					mode = 0;				// Original console mode
	DWORD					read = 0;				// Characters read from the console
	tchar_t					next;					// Next character read from console

	// Prevent multiple threads from reading the console at the same time
	std::lock_guard<std::recursive_mutex> lock(m_readlock);

	// Ensure LINE_INPUT and ECHO_INPUT are enabled for the input mode
	if(!GetConsoleMode(m_stdin, &mode)) throw Win32Exception();
	if(!SetConsoleMode(m_stdin, mode | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT)) throw Win32Exception();

	try {

		// Repeatedly read characters from the console until CR has been detected
		if(!ReadConsole(m_stdin, &next, 1, &read, nullptr)) throw Win32Exception();
		while(next != _T('\n')) { 
		
			if(next != _T('\r')) accumulator.push_back(next); 
			if(!ReadConsole(m_stdin, &next, 1, &read, nullptr)) throw Win32Exception();
		}
	}

	// Be sure the restore the original console mode flags on any exception
	catch(...) { SetConsoleMode(m_stdin, mode); throw; }

	// Restore the previously set input mode flags
	SetConsoleMode(m_stdin, mode);

	// Convert the accumulated character data as a tstring instance
	return std::tstring(accumulator.data(), accumulator.size());
}
/*-----------------------------------------------------------------------------
SetUserThreshold(IDiskQuotaControl* lpDiskQuotaControl)
    Set the warning threshold limit for a specific user

Parameters
    lpDiskQuotaControl - Pointer to an object that implements the
                         IDiskQuotaControl interface

Return Value
    TRUE - Success
    FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL SetUserThreshold(IDiskQuotaControl* lpDiskQuotaControl)
{
    HRESULT  hr;
    IDiskQuotaUser* lpDiskQuotaUser;
    WCHAR    szUser[MAX_PATH] = {0};
    DWORD    dwCharsRead;
    LONGLONG llLimit = 0;
    HANDLE   hStdIn  = GetStdHandle(STD_INPUT_HANDLE);

    wprintf(L"\n\nEnter the logon name of the user ");
    wprintf(L"(ie. DOMAIN\\USERNAME): ");

    // Get the user for which to set a hard limit
    ReadConsole(hStdIn, szUser, MAX_PATH, &dwCharsRead, NULL);

    szUser[MAX_PATH-1] = L'\0'; // make sure szUSer is NULL terminated

    // Strip the line feed and carriage return
    LfcrToNull(szUser);

    // Check if the name is valid
    hr = lpDiskQuotaControl->FindUserName((LPCWSTR)szUser, &lpDiskQuotaUser);

    if (SUCCEEDED(hr))
    {
        WCHAR    szLimit[MAX_PATH] = {0};
        wprintf(L"\nEnter the new hard limit in bytes (-1 == No Limit): ");

        // Read the threshold from the console
        ReadConsole(hStdIn, szLimit, MAX_PATH, &dwCharsRead, NULL);
        LfcrToNull(szLimit);
        llLimit = _wtoi64(szLimit);

        if (llLimit >= -1)
        {
            // Set the warning threshold for the user
            hr = lpDiskQuotaUser->SetQuotaThreshold(llLimit, TRUE);

            if (FAILED(hr))
            {
                wprintf(L"\nCould not set the quota limit for %s", szUser);
                wprintf(L"to %i64 bytes\n", llLimit);
            }
        }
        else
        {
            wprintf(L"\nInvalid limit!");
        }
        lpDiskQuotaUser->Release();
    }
    else
    {
        PrintError(hr);
    }

    return SUCCEEDED(hr);
}
Example #4
0
JNIEXPORT jstring JNICALL Java_com_yifanlu_Josh_Josh_READCONSOLE
  (JNIEnv *env, jclass jcls, jlong pointer)
{
    HANDLE hIn = pointerToHandle(pointer);
	char ReadBuffer[1024] = {0};
	DWORD dwBytesRead = 0;

	ReadConsole(hIn, &ReadBuffer, 1024, &dwBytesRead, NULL);

	char input[1024];
	int count = 0;
	for(int i=0; i<1024; i++)
		if(ReadBuffer[i] != '\0' && count < dwBytesRead)
		{
			input[count] = ReadBuffer[i];
			count++;
		}

	int len = dwBytesRead - 2;
	jchar* unicodeChars = new jchar[len];
	for (int i=0; i<len; i++)
		unicodeChars[i] = input[i];
	jstring jInput = env->NewString(unicodeChars, len);
	delete[] unicodeChars;

	return jInput;
}
Example #5
0
globle int gengetchar(
  void *theEnv)
  {
#if WIN_BTC || WIN_MVC
   if (SystemDependentData(theEnv)->getcLength ==
       SystemDependentData(theEnv)->getcPosition)
     {
      TCHAR tBuffer = 0;
      DWORD count = 0;
      WCHAR wBuffer = 0;

      ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&tBuffer,1,&count,NULL);
      
      wBuffer = tBuffer;
      
      SystemDependentData(theEnv)->getcLength = 
         WideCharToMultiByte(CP_UTF8,0,&wBuffer,1,
                             (char *) SystemDependentData(theEnv)->getcBuffer,
                             7,NULL,NULL);
                             
      SystemDependentData(theEnv)->getcPosition = 0;
     }
     
   return SystemDependentData(theEnv)->getcBuffer[SystemDependentData(theEnv)->getcPosition++];
#else
   return(getc(stdin));
#endif
  }
/*-----------------------------------------------------------------------------
AddUser(IDiskQuotaControl* lpDiskQuotaControl)
    Add a user for which to track quota data

Parameters
    lpDiskQuotaControl - Pointer to an object that implements the
                         IDiskQuotaControl interface

Return Value
    TRUE - Success
    FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL AddUser(IDiskQuotaControl* lpDiskQuotaControl)
{
    HRESULT  hr;
    IDiskQuotaUser* lpDiskQuotaUser;
    WCHAR    szUser[MAX_PATH] = {0};
    DWORD    dwCharsRead;
    HANDLE   hStdIn = GetStdHandle(STD_INPUT_HANDLE);

    wprintf(L"\n\nEnter the logon name of the user (ie. DOMAIN\\USERNAME): ");

    // Get the user for which to track quota information 
    ReadConsole(hStdIn, szUser, MAX_PATH, &dwCharsRead, NULL);
    LfcrToNull(szUser);

    // Add the user
    hr = lpDiskQuotaControl->AddUserName(szUser,
                                DISKQUOTA_USERNAME_RESOLVE_SYNC,
                                &lpDiskQuotaUser);

    if (FAILED(hr))
    {
        PrintError(hr);
        return FALSE;
    }
    lpDiskQuotaUser->Release();

    return TRUE;
}
Example #7
0
/*
 * read-wrapper to support reading from stdin on Windows.
 */
static ssize_t read_wincon(int fd, void *buf, size_t count)
{
  HANDLE handle = NULL;
  DWORD mode, rcount = 0;
  BOOL success;

  if(fd == fileno(stdin)) {
    handle = GetStdHandle(STD_INPUT_HANDLE);
  }
  else {
    return read(fd, buf, count);
  }

  if(GetConsoleMode(handle, &mode)) {
    success = ReadConsole(handle, buf, curlx_uztoul(count), &rcount, NULL);
  }
  else {
    success = ReadFile(handle, buf, curlx_uztoul(count), &rcount, NULL);
  }
  if(success) {
    return rcount;
  }

  errno = GetLastError();
  return -1;
}
Example #8
0
static BOOL
ReadConsoleBytes(
    HANDLE hConsole,
    LPVOID lpBuffer,
    DWORD nbytes,
    LPDWORD nbytesread)
{
    DWORD ntchars;
    BOOL result;
    int tcharsize = sizeof(TCHAR);

    /*
     * If user types a Ctrl-Break or Ctrl-C, ReadConsole will return
     * success with ntchars == 0 and GetLastError() will be
     * ERROR_OPERATION_ABORTED. We do not want to treat this case
     * as EOF so we will loop around again. If no Ctrl signal handlers
     * have been established, the default signal OS handler in a separate 
     * thread will terminate the program. If a Ctrl signal handler
     * has been established (through an extension for example), it
     * will run and take whatever action it deems appropriate.
     */
    do {
        result = ReadConsole(hConsole, lpBuffer, nbytes / tcharsize, &ntchars,
                             NULL);
    } while (result && ntchars == 0 && GetLastError() == ERROR_OPERATION_ABORTED);
    if (nbytesread != NULL) {
	*nbytesread = ntchars * tcharsize;
    }
    return result;
}
Example #9
0
static DWORD WINAPI input_thread(LPVOID arg)
{
	struct ui_st *st = arg;

	/* Switch to raw mode */
	SetConsoleMode(st->hstdin, 0);

	while (st->run) {

		char buf[4];
		DWORD i, count = 0;

		ReadConsole(st->hstdin, buf, sizeof(buf), &count, NULL);

		for (i=0; i<count; i++) {
			int ch = buf[i];

			if (ch == '\r')
				ch = '\n';

			/*
			 * The keys are read from a thread so we have
			 * to send them to the RE main event loop via
			 * a message queue
			 */
			mqueue_push(st->mq, ch, 0);
		}
	}

	return 0;
}
Example #10
0
R_API int r_cons_readchar() {
	void *bed;
	char buf[2];
	buf[0] = -1;
	if (readbuffer_length > 0) {
		int ch = *readbuffer;
		readbuffer_length--;
		memmove (readbuffer, readbuffer + 1, readbuffer_length);
		return ch;
	}
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
	#if 1   // if something goes wrong set this to 0. skuater.....
	return readchar_win(0);
	#endif
	BOOL ret;
	DWORD out;
	DWORD mode;
	HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, &mode);
	SetConsoleMode (h, 0); // RAW
	bed = r_cons_sleep_begin ();
	ret = ReadConsole (h, buf, 1, &out, NULL);
	r_cons_sleep_end (bed);
	FlushConsoleInputBuffer (h);
	if (!ret) {
		return -1;
	}
	SetConsoleMode (h, mode);
#else
	r_cons_set_raw (1);
	bed = r_cons_sleep_begin ();

	// Blocks until either stdin has something to read or a signal happens.
	// This serves to check if the terminal window was resized. It avoids the race
	// condition that could happen if we did not use pselect or select in case SIGWINCH
	// was handled immediately before the blocking call (select or read). The race is
	// prevented from happening by having SIGWINCH blocked process-wide except for in
	// pselect (that is what pselect is for).
	fd_set readfds;
	sigset_t sigmask;
	FD_ZERO (&readfds);
	FD_SET (STDIN_FILENO, &readfds);
	r_signal_sigmask (0, NULL, &sigmask);
	sigdelset (&sigmask, SIGWINCH);
	pselect (STDIN_FILENO + 1, &readfds, NULL, NULL, NULL, &sigmask);
	if (sigwinchFlag != 0) {
		resizeWin ();
	}

	ssize_t ret = read (STDIN_FILENO, buf, 1);
	r_cons_sleep_end (bed);
	if (ret != 1) {
		return -1;
	}
	if (bufactive) {
		r_cons_set_raw (0);
	}
#endif
	return r_cons_controlz (buf[0]);
}
Example #11
0
/**
 * Very simplistic console input
 */
static void console_input(void)
{
	TCHAR inp;
	DWORD read;
	if(!ReadConsole(events[1], &inp, 1, &read, NULL))
		return;

	switch(inp) {
	case 8:
		if(console_ptr > 0) {
			console_ptr--;
			printf("\b \b");
		}
		break;
	case 13:
		printf("\n\r");
		console_buf[console_ptr++] = 0;
		console_ptr = 0;
		enable_console = 0;
		cmd_exec_unparsed(console_buf);
		break;

	default:
		if(console_ptr < sizeof(console_buf) - 1) {
			printf("%c", (char)inp);
			console_buf[console_ptr++] = inp;
		}
		break;
	}
}
Example #12
0
static void GetPasswordText(wchar *Str,uint MaxLength)
{
  if (MaxLength==0)
    return;
#ifdef _WIN_ALL
  HANDLE hConIn=GetStdHandle(STD_INPUT_HANDLE);
  HANDLE hConOut=GetStdHandle(STD_OUTPUT_HANDLE);
  DWORD ConInMode,ConOutMode;
  DWORD Read=0;
  GetConsoleMode(hConIn,&ConInMode);
  GetConsoleMode(hConOut,&ConOutMode);
  SetConsoleMode(hConIn,ENABLE_LINE_INPUT);
  SetConsoleMode(hConOut,ENABLE_PROCESSED_OUTPUT|ENABLE_WRAP_AT_EOL_OUTPUT);

  ReadConsole(hConIn,Str,MaxLength-1,&Read,NULL);
  Str[Read]=0;
  SetConsoleMode(hConIn,ConInMode);
  SetConsoleMode(hConOut,ConOutMode);
#else
  char StrA[MAXPASSWORD];
#if defined(_EMX) || defined (__VMS) || defined(__AROS__)
  fgets(StrA,ASIZE(StrA)-1,stdin);
#elif defined(__sun)
  strncpyz(StrA,getpassphrase(""),ASIZE(StrA));
#else
  strncpyz(StrA,getpass(""),ASIZE(StrA));
#endif
  CharToWide(StrA,Str,MaxLength);
  cleandata(StrA,sizeof(StrA));
#endif
  Str[MaxLength-1]=0;
  RemoveLF(Str);
}
Example #13
0
R_API int r_cons_readchar() {
	char buf[2];
	buf[0] = -1;
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
	#if 1   // if something goes wrong set this to 0. skuater.....
	return readchar_win(0);
	#endif
	BOOL ret;
	DWORD out;
	DWORD mode;
	HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, &mode);
	SetConsoleMode (h, 0); // RAW
	ret = ReadConsole (h, buf, 1, &out, NULL);
	FlushConsoleInputBuffer (h);
	if (!ret) {
		return -1;
	}
	SetConsoleMode (h, mode);
#else
	r_cons_set_raw (1);
	if (read (0, buf, 1) == -1) {
		return -1;
	}
	r_cons_set_raw (0);
#endif
	return r_cons_controlz (buf[0]);
}
INPUT_RECORD *TThreads::get_next_event(void) {
   if (evpending) return &ir;
   PeekConsoleInput(chandle[cnInput],&ir,1,&evpending);
   if (evpending) {
      int code = event_type(ir);
      //    printf("evtype = %d\n",code);
      switch (code) {
         case IO_RAW_EVENT:
            ReadConsoleInput(chandle[cnInput],&ir,1,&evpending);
            break;
         case IO_CHR_EVENT:
            char chr;
            //      printf("before readconsole\n");
            ReadConsole(chandle[cnInput],&chr,1,&evpending,NULL);
            //      printf("key %x %d\n",chr,evpending);
            ir.Event.KeyEvent.uChar.AsciiChar = chr;
            break;
         case IO_IGN_EVENT:
            ReadConsoleInput(chandle[cnInput],&ir,1,&evpending);
            accept_event();
            break;
      }
   }
   return evpending ? &ir : NULL;
}
/*-----------------------------------------------------------------------------
SetDefaultThreshold(IDiskQuotaControl* lpDiskQuotaControl)
    Set the default warning threshold of the volume.

Parameters
    lpDiskQuotaControl - Pointer to an object that implements the
                         IDiskQuotaControl interface

Return Value
    TRUE - Success
    FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL SetDefaultThreshold(IDiskQuotaControl* lpDiskQuotaControl)
{
    HRESULT  hr;
    LONGLONG llLimit = 0;
    WCHAR    szLimit[MAX_PATH] = {0};
    DWORD    dwCharsRead;
    HANDLE   hStdIn = GetStdHandle(STD_INPUT_HANDLE);

    wprintf(L"\n\nEnter the new default threshold in Bytes ");
    wprintf(L"(-1 == No Limit): ");

    // Get the limit from the command prompt
    ReadConsole(hStdIn, szLimit, MAX_PATH, &dwCharsRead, NULL);
    LfcrToNull(szLimit);
    llLimit = _wtoi64(szLimit);

    if (llLimit < -1)
    {
        wprintf(L"\nInvalid limit!");
        return FALSE;
    }

    // Set the default warning threshold
    hr = lpDiskQuotaControl->SetDefaultQuotaThreshold(llLimit);

    if (FAILED(hr))
    {
        PrintError(hr);
        return FALSE;
    }

    return TRUE;
}
Example #16
0
File: terms.c Project: thioshp/w3m
static int
read_win32_console_input(void)
{
    INPUT_RECORD rec;
    DWORD nevents;

    if (PeekConsoleInput(hConIn, &rec, 1, &nevents) && nevents) {
	switch (rec.EventType) {
	case KEY_EVENT:
	    expand_win32_console_input_buffer(3);

	    if (ReadConsole(hConIn, &ConInV[nConIn], 1, &nevents, NULL)) {
		nConIn += nevents;
		return nevents;
	    }

	    break;
	default:
	    break;
	}

	ReadConsoleInput(hConIn, &rec, 1, &nevents);
    }
    return 0;
}
void ConsoleProc()
{
	CHAR	byte;
	DWORD	read;
	while ( ReadConsole( hConIn, &byte, 1, &read, NULL) )
	{
		if ( byte == 'C' || byte == 'c' )
		{
			COORD coordScreen = { 0, 0 };
			FillConsoleOutputCharacter(hConOut,' ', 0xFFFFFFFF, coordScreen, &read);
			SetConsoleCursorPosition(hConOut, coordScreen);
		}
		else if ( byte == 'W' || byte == 'w' )
		{
			Scanner::TPattern WardenPattern ("\x56\x57\xFC\x8B\x54\x24\x14\x8B\x74\x24\x10\x8B\x44\x24\x0C\x8B\xCA\x8B\xF8\xC1\xE9\x02\x74\x02\xF3\xA5" \
								  "\xB1\x03\x23\xCA\x74\x02\xF3\xA4\x5F\x5E\xC3", "x37");
			DWORD WardenProc = (DWORD) Scanner::ScanMem( &WardenPattern );
			if ( WardenProc )
			{
				Logger::OutLog("Warden::Scan proc:0x%.8x\r\n", WardenProc);
			}
			else 
				Logger::OutLog("Warden::Scan proc not found\r\n");
		}
	}
}
	/////////////////////////////////////////////////////////////////////// 
	// GetAndSendInputThreadOrig
	// Thread procedure that monitors the console for input and sends input
	// to the child process through the input pipe.
	// This thread ends when the child application exits.
	// Original from http://support.microsoft.com/kb/190351
	/////////////////////////////////////////////////////////////////////// 
	DWORD WINAPI GetAndSendInputThreadOrig(LPVOID lpvThreadParam)
	{
		CHAR read_buff[256];
		DWORD nBytesRead,nBytesWrote;
		HANDLE hPipeWrite = (HANDLE)lpvThreadParam;

		// Get input from our console and send it to child through the pipe.
		while (bRunThread)
		{
			if(!ReadConsole(hStdIn,read_buff,1,&nBytesRead,NULL))
				DisplayError("ReadConsole");

			read_buff[nBytesRead] = '\0'; // Follow input with a NULL.

			if (!WriteFile(hPipeWrite,read_buff,nBytesRead,&nBytesWrote,NULL))
			{
				if (GetLastError() == ERROR_NO_DATA)
					break; // Pipe was closed (normal exit path).
				else
					DisplayError("WriteFile");
			}
		}

		return 1;
	}
Example #19
0
static void ConsoleWriteReadDefault(LPSTR pReadBuf, DWORD lenReadBuf, LPCSTR pText)
{
  static HANDLE handle = INVALID_HANDLE_VALUE;

  if (handle == INVALID_HANDLE_VALUE) {
    AllocConsole();
    handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTitle(title);
    isConsoleOpen = TRUE;
  }

  if (pText) {
    DWORD cnt;

    if (GetFileType(handle) == FILE_TYPE_CHAR)
      WriteConsole(handle, pText, lstrlen(pText), &cnt, NULL);
    else
      WriteFile(handle, pText, lstrlen(pText), &cnt, NULL);
  }

  if (pReadBuf && lenReadBuf > 0) {
    if (lenReadBuf > 1 &&
        ReadConsole(GetStdHandle(STD_INPUT_HANDLE), pReadBuf, lenReadBuf - 1, &lenReadBuf, 0))
    {
      pReadBuf[lenReadBuf] = 0;
    } else {
      pReadBuf[0] = 0;
    }
  }
}
Example #20
0
static DWORD WINAPI
getInput(LPVOID h)
{ input_context *ctx = h;

  ctx->rc = ReadConsole(ctx->input, ctx->buf, ctx->len, &ctx->done, NULL);

  return ctx->rc;
}
Example #21
0
void DebugConsole::waitKey()
{
    INPUT_RECORD record;
    DWORD rr;
    writeline("--PRESS A KEY--");
    SetConsoleMode(m_in,ENABLE_PROCESSED_INPUT); 
    ReadConsole(m_in, &record, 1, &rr, NULL);
}
Example #22
0
 tstring Console::read()
 {
     tchar input[1024];
     DWORD numRead;
     ReadConsole(inHandle_, input, 1023, &numRead, NULL);
     input[numRead - 2] = KILLME_T('\0');
     return input;
 }
Example #23
0
int cgetch()
{
	char buffer[3];
	DWORD chread;

	ReadConsole(ConStdIn, buffer, sizeof(TCHAR), &chread, NULL);
	return (int)buffer[0];
}
Example #24
0
/*
* SfMain
*
* Purpose:
*
* Murasame main.
*
*/
void SfMain(
	VOID
	)
{
	BOOL         cond = FALSE;
	UINT         uResult = 0;
	DWORD        dwTemp;
	HANDLE       StdIn;
	INPUT_RECORD inp1;

	__security_init_cookie();

	do {

		g_ConOut = GetStdHandle(STD_OUTPUT_HANDLE);
		if (g_ConOut == INVALID_HANDLE_VALUE) {
			uResult = (UINT)-1;
			break;
		}

		g_ConsoleOutput = TRUE;
		if (!GetConsoleMode(g_ConOut, &dwTemp)) {
			g_ConsoleOutput = FALSE;
		}

		SetConsoleTitle(T_SFEXTRACTTITLE);
		SetConsoleMode(g_ConOut, ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_OUTPUT);
		if (g_ConsoleOutput == FALSE) {
			WriteFile(g_ConOut, &BE, sizeof(WCHAR), &dwTemp, NULL);
		}

		if (SfInitGdiPlus()) {
			uResult = SfExtractDropper(GetCommandLine());
		}
		else {
			SfcuiPrintText(g_ConOut,
				T_SFINITFAILED,
				g_ConsoleOutput, FALSE);
		}

		if (g_ConsoleOutput) {

			SfcuiPrintText(g_ConOut,
				T_SFPRESSANYKEY,
				TRUE, FALSE);

			StdIn = GetStdHandle(STD_INPUT_HANDLE);
			if (StdIn != INVALID_HANDLE_VALUE) {
				RtlSecureZeroMemory(&inp1, sizeof(inp1));
				ReadConsoleInput(StdIn, &inp1, 1, &dwTemp);
				ReadConsole(StdIn, &BE, sizeof(BE), &dwTemp, NULL);
			}
		}

	} while (cond);

	ExitProcess(uResult);
}
/*-----------------------------------------------------------------------------
GetUserQuotaInfo(IDiskQuotaControl* lpDiskQuotaControl)
    Get quota information for a specific user

Parameters
    lpDiskQuotaControl - Pointer to an object that implements the
                         IDiskQuotaControl interface

Return Value
    TRUE - Success
    FALSE - Failure
-----------------------------------------------------------------------------*/
BOOL GetUserQuotaInfo(IDiskQuotaControl* lpDiskQuotaControl)
{
    WCHAR    szUser[MAX_PATH] = {0};
    IDiskQuotaUser* lpDiskQuotaUser;
    DWORD    dwCharsRead;
    HANDLE   hStdIn  = GetStdHandle(STD_INPUT_HANDLE);
    HRESULT  hr;

    wprintf(L"\n\nEnter the logon name of the user");
    wprintf(L"(ie. DOMAIN\\USERNAME): ");

    // Get the user for which to get quota information 
    ReadConsole(hStdIn, szUser, MAX_PATH, &dwCharsRead, NULL);
    szUser[MAX_PATH-1] = L'\0'; // make sure szUser is NULL terminated
    LfcrToNull(szUser);

    // Check if the name is valid
    hr = lpDiskQuotaControl->FindUserName((LPCWSTR)szUser, &lpDiskQuotaUser);
    if (SUCCEEDED(hr))
    {
        WCHAR    szQuotaUsedText[MAX_PATH] = {0};
        WCHAR    szQuotaLimitText[MAX_PATH] = {0};
        WCHAR    szQuotaThresholdText[MAX_PATH] = {0};

        if (SUCCEEDED(hr = lpDiskQuotaUser->GetQuotaThresholdText(
                                    szQuotaThresholdText, MAX_PATH))         &&
            SUCCEEDED(hr = lpDiskQuotaUser->GetQuotaLimitText(
                                    szQuotaLimitText, MAX_PATH))             &&
            SUCCEEDED(hr = lpDiskQuotaUser->GetQuotaUsedText(
                                    szQuotaUsedText, MAX_PATH)))
        {
            szQuotaUsedText[MAX_PATH-1] = L'\0'; // make sure szQuotaUsedText is NULL terminated
            szQuotaLimitText[MAX_PATH-1] = L'\0'; // make sure szQuotaLimitText is NULL terminated
            szQuotaThresholdText[MAX_PATH-1] = L'\0'; // make sure szQuotaThresholdText is NULL terminated

            wprintf(L"Amount Used        Limit    Threshold\n");
            wprintf(L"-----------        -----    ---------\n");
            wprintf(L"   %10s", szQuotaUsedText);
            wprintf(L"   %10s", szQuotaLimitText);
            wprintf(L"   %10s", szQuotaThresholdText);
            wprintf(L"\n");
        }
        else
        {
            wprintf(L"\nCould not get the quota information for %s", szUser);
        }

        lpDiskQuotaUser->Release();
    }
    else
    {
        wprintf(L"\nCould not find quota data for %s\n", szUser);
    }

    WaitForKeyPress();

    return SUCCEEDED(hr);
}
Example #26
0
// Console IO //////////////////////////////////////////////////
UInt System::ConsoleRead( GChar * outBuffer, UInt iMaxLength ) const
{
    HANDLE hIn = GetStdHandle( STD_INPUT_HANDLE );
    DebugAssert( hIn != INVALID_HANDLE_VALUE );

    DWord iRead = 0;
    BOOL bOk = ReadConsole( hIn, outBuffer, iMaxLength, &iRead, NULL );
    DebugAssert( bOk && iRead >= 2 );

    outBuffer[iRead-2] = NULLBYTE; // remove trailing cr/lf
    return (UInt)iRead;
}
Example #27
0
/* were just going to fake it here and get input from the keyboard */
void get_tty_password_buff(const char *opt_message, char *to, size_t length)
{
  HANDLE consoleinput;
  DWORD oldstate;
  char *pos=to,*end=to+length-1;
  int i=0;

  consoleinput= CreateFile("CONIN$", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ ,
    NULL, OPEN_EXISTING, 0, NULL); 
  if (consoleinput == NULL || consoleinput == INVALID_HANDLE_VALUE) 
  {
     /* This is a GUI application or service  without console input, bail out. */
     *to= 0;
     return;
  }
  _cputs(opt_message ? opt_message : "Enter password: "******"\b \b");
	pos--;
	continue;
      }
    }
    if (tmp == '\n' || tmp == '\r')
      break;
    if (iscntrl(tmp) || pos == end)
      continue;
    _cputs("*");
    *(pos++) = tmp;
  }
  /* Reset console mode after password input. */ 
  SetConsoleMode(consoleinput, oldstate);
  CloseHandle(consoleinput);
  *pos=0;
  _cputs("\n");
}
Example #28
0
int gets_quiet(char *s, int len)
{
#ifdef WIN32
	HANDLE h;
	DWORD con_orig, con_quiet;
	DWORD read_len = 0;

	memset(s, 0, len);
	h  = GetStdHandle(STD_INPUT_HANDLE);
	GetConsoleMode(h, &con_orig);
	con_quiet &= ~ENABLE_ECHO_INPUT;
	con_quiet |= ENABLE_LINE_INPUT;
	SetConsoleMode(h, con_quiet);
	if(!ReadConsole(h, s, len, &read_len, NULL)){
		SetConsoleMode(h, con_orig);
		return 1;
	}
	while(s[strlen(s)-1] == 10 || s[strlen(s)-1] == 13){
		s[strlen(s)-1] = 0;
	}
	if(strlen(s) == 0){
		return 1;
	}
	SetConsoleMode(h, con_orig);

	return 0;
#else
	struct termios ts_quiet, ts_orig;
	char *rs;

	memset(s, 0, len);
	tcgetattr(0, &ts_orig);
	ts_quiet = ts_orig;
	ts_quiet.c_lflag &= ~(ECHO | ICANON);
	tcsetattr(0, TCSANOW, &ts_quiet);

	rs = fgets(s, len, stdin);
	tcsetattr(0, TCSANOW, &ts_orig);

	if(!rs){
		return 1;
	}else{
		while(s[strlen(s)-1] == 10 || s[strlen(s)-1] == 13){
			s[strlen(s)-1] = 0;
		}
		if(strlen(s) == 0){
			return 1;
		}
	}
	return 0;
#endif
}
	~WindowsAppConsoleOutput()
	{
		std::cout << std::endl << "Press any key to exit" << std::endl;

		// Disable line-based input mode so we can get a single character
		HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
		SetConsoleMode(ConsoleInput, 0);

		// Read a single character
		TCHAR InputBuffer;
		DWORD CharsRead;
		ReadConsole(ConsoleInput, &InputBuffer, 1, &CharsRead, 0);
	}
Example #30
0
char keyboard_char(void)
{
  char buffer[1] ;
  DWORD rbytes ;

  if ( !ReadConsole(conin, buffer, 1, &rbytes, NULL) || rbytes != 1 )
    error("Can't read character from console") ;

  if ( buffer[0] == '\r' )
    buffer[0] = '\n' ;

  return buffer[0] ;
}