// Read one line from the console wchar_t *ConsoleLocalReadLine(CONSOLE *c, wchar_t *prompt, bool nofile) { wchar_t *ret; LOCAL_CONSOLE_PARAM *p; // Validate arguments if (c == NULL) { return NULL; } p = (LOCAL_CONSOLE_PARAM *)c->Param; if (prompt == NULL) { prompt = L">"; } ConsoleWriteOutFile(c, prompt, false); if (nofile == false && p->InBuf != NULL) { // Read the next line from the file ret = ConsoleReadNextFromInFile(c); if (ret != NULL) { // Display the pseudo prompt UniPrint(L"%s", prompt); // Display on the screen UniPrint(L"%s\n", ret); } } else { // Read the following line from the console ret = Prompt(prompt); } if (ret != NULL) { ConsoleWriteOutFile(c, ret, true); } else { ConsoleWriteOutFile(c, _UU("CON_USER_CANCEL"), true); } return ret; }
// Read the password from the console char *ConsoleLocalReadPassword(CONSOLE *c, wchar_t *prompt) { char tmp[64]; // Validate arguments if (c == NULL) { return NULL; } if (prompt == NULL) { prompt = L"Password>"; } UniPrint(L"%s", prompt); ConsoleWriteOutFile(c, prompt, false); if (PasswordPrompt(tmp, sizeof(tmp))) { ConsoleWriteOutFile(c, L"********", true); return CopyStr(tmp); } else { ConsoleWriteOutFile(c, _UU("CON_USER_CANCEL"), true); return NULL; } }
// Display a string to the console bool ConsoleLocalWrite(CONSOLE *c, wchar_t *str) { // Validate arguments if (c == NULL || str == NULL) { return false; } UniPrint(L"%s%s", str, (UniEndWith(str, L"\n") ? L"" : L"\n")); ConsoleWriteOutFile(c, str, true); return true; }
// Enumerate adapters TOKEN_LIST *SuEnumAdapters(SU *u) { UINT i; UINT ret_size; TOKEN_LIST *ret; // Validate arguments if (u == NULL) { return NullToken(); } Zero(&u->AdapterInfoList, sizeof(u->AdapterInfoList)); if (ReadFile(u->hFile, &u->AdapterInfoList, sizeof(u->AdapterInfoList), &ret_size, NULL) == false || u->AdapterInfoList.Signature != SL_SIGNATURE) { Debug("SuEnumAdapters: ReadFile error.\n"); return NullToken(); } ret = ZeroMalloc(sizeof(TOKEN_LIST)); ret->NumTokens = u->AdapterInfoList.NumAdapters; ret->Token = ZeroMalloc(sizeof(char *) * ret->NumTokens); Debug("SuEnumAdapters: u->AdapterInfoList.NumAdapters = %u\n", u->AdapterInfoList.NumAdapters); for (i = 0; i < ret->NumTokens; i++) { ret->Token[i] = CopyUniToStr(u->AdapterInfoList.Adapters[i].AdapterId); UniPrint(L"%s %u %S\n", u->AdapterInfoList.Adapters[i].AdapterId, u->AdapterInfoList.Adapters[i].MtuSize, u->AdapterInfoList.Adapters[i].FriendlyName); } return ret; }
// Show the prompt wchar_t *Prompt(wchar_t *prompt_str) { wchar_t *ret = NULL; wchar_t *tmp = NULL; // Validate arguments if (prompt_str == NULL) { prompt_str = L""; } #ifdef OS_WIN32 UniPrint(L"%s", prompt_str); tmp = Malloc(MAX_PROMPT_STRSIZE); if (fgetws(tmp, MAX_PROMPT_STRSIZE - 1, stdin) != NULL) { bool escape = false; UINT i, len; len = UniStrLen(tmp); for (i = 0;i < len;i++) { if (tmp[i] == 0x04 || tmp[i] == 0x1A) { escape = true; break; } } if (escape == false) { UniTrimCrlf(tmp); ret = UniCopyStr(tmp); } } Free(tmp); #else // OS_WIN32 { char *prompt = CopyUniToStr(prompt_str); char *s = readline(prompt); Free(prompt); if (s != NULL) { TrimCrlf(s); Trim(s); if (IsEmptyStr(s) == false) { add_history(s); } ret = CopyStrToUni(s); free(s); } } #endif // OS_WIN32 if (ret == NULL) { Print("\n"); } return ret; }