void RfbInitializer::initVersion() { char initVersionMsg[] = "RFB 003.008\n"; char clientVersionMsg[13]; size_t msgLen = 12; m_output->writeFully(initVersionMsg, msgLen); m_input->readFully(clientVersionMsg, msgLen); clientVersionMsg[12] = 0; m_minorVerNum = getProtocolMinorVersion(clientVersionMsg); try { checkForLoopback(); // Checking for a ban before auth and then after. checkForBan(); } catch (Exception &e) { if (m_minorVerNum == 3) { m_output->writeUInt32(0); } else { m_output->writeUInt8(0); } AnsiStringStorage reason(&StringStorage(e.getMessage())); unsigned int reasonLen = (unsigned int)reason.getLength(); _ASSERT(reasonLen == reason.getLength()); m_output->writeUInt32(reasonLen); m_output->writeFully(reason.getString(), reasonLen); throw; } }
void CtrlAltDelSimulator::execute() { if (DesktopSelector::selectDesktop(&StringStorage(_T("Winlogon")))) { HWND hwndCtrlAltDel = FindWindow(_T("SAS window class"), _T("SAS window")); if (hwndCtrlAltDel == NULL) { hwndCtrlAltDel = HWND_BROADCAST; } PostMessage(hwndCtrlAltDel, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE)); } }
StringStorage WinClipboard::removeCR(const StringStorage *str) { const TCHAR *beginString = str->getString(); const TCHAR *endString = beginString + str->getLength() + 1; // start + lenght + '\0' vector<TCHAR> chars(beginString, endString); vector<TCHAR> newChars; size_t countLF = 0; for (size_t i = 0; i < chars.size(); i++) { if (chars[i] != CR || i + 1 == chars.size() || chars[i+1] != LF) { newChars.push_back(chars[i]); } } return StringStorage(&newChars.front()); }
void RfbInitializer::initAuthenticate() { try { // Determine effective security type from the configuration. UINT32 primSecType = SecurityDefs::VNC; if (!Configurator::getInstance()->getServerConfig()->isUsingAuthentication() || !m_authAllowed) { primSecType = SecurityDefs::NONE; } // Here the protocol varies between versions 3.3 and 3.7+. if (m_minorVerNum >= 7) { // Send a list with two security types -- VNC-compatible security type // and a special code allowing to enable TightVNC protocol extensions. m_output->writeUInt8(2); m_output->writeUInt8(primSecType); m_output->writeUInt8(SecurityDefs::TIGHT); // Read what the client has actually selected. UINT8 clientSecType = m_input->readUInt8(); if (clientSecType == SecurityDefs::TIGHT) { m_tightEnabled = true; doTightAuth(); } else { if (clientSecType != primSecType) { throw Exception(_T("Security types do not match")); } doAuth(AuthDefs::convertFromSecurityType(clientSecType)); } } else { // Just tell the client we will use the configured security type. m_output->writeUInt32(primSecType); doAuth(AuthDefs::convertFromSecurityType(primSecType)); } } catch (AuthException &e) { // FIXME: The authentication result must be sent in protocols 3.3 and 3.7 // as well, unless the authentication was set to AuthDefs::NONE. if (m_minorVerNum >= 8) { AnsiStringStorage reason(&StringStorage(e.getMessage())); unsigned int reasonLen = (unsigned int)reason.getLength(); _ASSERT(reasonLen == reason.getLength()); m_output->writeUInt32(1); // FIXME: Use a named constant instead of 1. m_output->writeUInt32(reasonLen); m_output->writeFully(reason.getString(), reasonLen); } throw; } }
int wmain(int argc, const wchar_t *_argv[]) { std::vector<const char *> StringPtrs(argc); std::vector<std::string> StringStorage(argc); for (int i = 0; i < argc; i++) { StringStorage[i] = utf16_to_utf8(_argv[i]); StringPtrs[i] = StringStorage[i].c_str(); } const char **argv = StringPtrs.data(); #else int main(int argc, const char *argv[]) { #endif try { if (argc <= 1) { PrintUsage(); return 0; } ParseCMDLine(argc, argv); } catch (Error const& e) { std::cout << e.msg << std::endl; return 1; } FFMS_Init(0, 0); switch (Verbose) { case 0: FFMS_SetLogLevel(FFMS_LOG_QUIET); break; case 1: FFMS_SetLogLevel(FFMS_LOG_WARNING); break; case 2: FFMS_SetLogLevel(FFMS_LOG_INFO); break; case 3: FFMS_SetLogLevel(FFMS_LOG_VERBOSE); break; default: FFMS_SetLogLevel(FFMS_LOG_DEBUG); // if user used -v 4 or more times, he deserves the spam } try { DoIndexing(); } catch (Error const& e) { std::cout << e.msg << std::endl; FFMS_Deinit(); return 1; } FFMS_Deinit(); return 0; }
StringStorage WinClipboard::addCR(const StringStorage *str) { const TCHAR *beginString = str->getString(); const TCHAR *endString = beginString + str->getLength() + 1; // start + lenght + '\0' vector<TCHAR> chars(beginString, endString); vector<TCHAR> newChars(str->getLength() * 2 + 1); size_t countLF = 0; for (size_t i = 0; i < chars.size(); i++) { // if is first byte or previous byte not CR, then add CR if ((i == 0 || chars[i-1] != CR) && chars[i] == LF) { newChars[i + countLF] = CR; ++countLF; } newChars[i + countLF] = chars[i]; } newChars.resize(chars.size() + countLF); return StringStorage(&newChars.front()); }
Utf8StringStorage::Utf8StringStorage() { fromStringStorage(&StringStorage(_T(""))); }