KviCryptEngine::EncryptResult KviRijndaelEngine::encrypt(const char * plainText, KviCString & outBuffer) { if(!m_pEncryptCipher) { setLastError(__tr2qs("Oops! Encryption cipher not initialized")); return KviCryptEngine::EncryptError; } int len = (int)kvi_strLen(plainText); char * buf = (char *)KviMemory::allocate(len + 16); // needed for the eventual padding unsigned char * iv = nullptr; if(m_bEncryptMode == CBC) { iv = (unsigned char *)KviMemory::allocate(MAX_IV_SIZE); InitVectorEngine::fillRandomIV(iv, MAX_IV_SIZE); } int retVal = m_pEncryptCipher->padEncrypt((const unsigned char *)plainText, len, (unsigned char *)buf, iv); if(retVal < 0) { KviMemory::free(buf); setLastErrorFromRijndaelErrorCode(retVal); return KviCryptEngine::EncryptError; } if(m_bEncryptMode == CBC) { // prepend the iv to the cyphered text buf = (char *)KviMemory::reallocate(buf, retVal + MAX_IV_SIZE); KviMemory::move(buf + MAX_IV_SIZE, buf, retVal); KviMemory::move(buf, iv, MAX_IV_SIZE); KviMemory::free(iv); retVal += MAX_IV_SIZE; } if(!binaryToAscii(buf, retVal, outBuffer)) { KviMemory::free(buf); return KviCryptEngine::EncryptError; } KviMemory::free(buf); if(outBuffer.len() > maxEncryptLen()) { if(maxEncryptLen() > 0) { setLastError(__tr2qs("Data buffer too long")); return KviCryptEngine::EncryptError; } } outBuffer.prepend(KviControlCodes::CryptEscape); return KviCryptEngine::Encrypted; }
static void kvi_ipcSetRemoteCommand(Window w, const char * command) { if(!command) return; int len = kvi_strLen(command) + 1; char * buffer = (char *)::malloc(len + 8); *((kvi_u64_t *)buffer) = g_uLocalInstanceId; ::memcpy(buffer + 8, command, len); XChangeProperty(kvi_ipc_get_xdisplay(), w, kvi_atom_ipc_remote_command, XA_STRING, 8, PropModeReplace, (const unsigned char *)buffer, len + 8); ::free(buffer); }
int parseArgs(ParseArgs * a) { QString szServer; QString szPort; int idx; if(a->argc < 2)return KVI_ARGS_RETCODE_OK; for(idx = 1;idx < a->argc;idx++) { QString szMessage; char * p = a->argv[idx]; if((kvi_strLen(p) > 3) && (*p == '-') && (*(p+1) == '-'))p++; if(kvi_strEqualCI("-v",p) || kvi_strEqualCI("-version",p)) { KviQString::appendFormatted(szMessage,"KVIrc %s '%s'\n",KVI_VERSION,KVI_RELEASE_NAME); KviQString::appendFormatted(szMessage,"Sources date: %s\n",KVI_SOURCES_DATE); szMessage += "Build date: "; szMessage += KviBuildInfo::buildDate(); szMessage += "\n"; KviQString::appendFormatted(szMessage,"Home page: http://www.kvirc.net/\n"); #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) MessageBox(0,szMessage.toLocal8Bit().data(),"KVIrc",0); #else qDebug("%s",szMessage.toLocal8Bit().data()); #endif return KVI_ARGS_RETCODE_STOP; } if(kvi_strEqualCI("-h",p) || kvi_strEqualCI("-help",p)) { KviQString::appendFormatted(szMessage,"Usage:\n"); KviQString::appendFormatted(szMessage," %s [options] [server [port]] [ircurl [ircurl [...]]]\n",a->argv[0]); KviQString::appendFormatted(szMessage," \n"); KviQString::appendFormatted(szMessage,"Available options:\n"); KviQString::appendFormatted(szMessage," -h, --help : Print this help and exit\n"); KviQString::appendFormatted(szMessage," -v, --version: Print version information and exit\n"); KviQString::appendFormatted(szMessage," -c <file> : Use <file> as config file instead of ~/%s\n",KVI_HOME_CONFIG_FILE_NAME); KviQString::appendFormatted(szMessage," (defaults to $HOME/%s if <file> does not exist)\n",KVI_HOME_CONFIG_FILE_NAME); KviQString::appendFormatted(szMessage," -n <file> : Use <file> as config file instead of $HOME/%s\n",KVI_HOME_CONFIG_FILE_NAME); KviQString::appendFormatted(szMessage," (create <file> if it does not exist)\n"); #ifdef COMPILE_NO_IPC KviQString::appendFormatted(szMessage," -f : Accepted but ignored (for compatibility)\n"); #else KviQString::appendFormatted(szMessage," -f : Force a new KVIrc session, even if there is already\n"); KviQString::appendFormatted(szMessage," a running one.\n"); #endif KviQString::appendFormatted(szMessage," -e <commands>: If a KVIrc session is already running, execute\n"); KviQString::appendFormatted(szMessage," the <commands> in that session, otherwise start up\n"); KviQString::appendFormatted(szMessage," normally and execute <commands>\n"); KviQString::appendFormatted(szMessage," <commands> must be a single shell token.\n"); KviQString::appendFormatted(szMessage," You can eventually use this switch more than once\n"); KviQString::appendFormatted(szMessage," -x <commands>: If a KVIrc session is already running, execute\n"); KviQString::appendFormatted(szMessage," the <commands> in that session, otherwise exit from application without doing anything/\n"); KviQString::appendFormatted(szMessage," <commands> must be a single shell token.\n"); KviQString::appendFormatted(szMessage," You can eventually use this switch more than once\n"); KviQString::appendFormatted(szMessage," -r <commands>: If a KVIrc session is already running, execute the <commands>\n"); KviQString::appendFormatted(szMessage," in that session, otherwise start up normally (do not execute).\n"); KviQString::appendFormatted(szMessage," <commands> must be a single shell token.\n"); KviQString::appendFormatted(szMessage," You can eventually use this switch more than once\n"); KviQString::appendFormatted(szMessage," -m : If a KVIrc session is already running, show an informational\n"); KviQString::appendFormatted(szMessage," popup dialog instead of writing to the console\n"); KviQString::appendFormatted(szMessage," --nosplash : Do not show the splash screen at startup\n"); KviQString::appendFormatted(szMessage," [server] : Connect to this server after startup\n"); KviQString::appendFormatted(szMessage," [port] : Use this port for connection\n"); KviQString::appendFormatted(szMessage," [ircurl] : URL in the following form:\n"); KviQString::appendFormatted(szMessage," irc[6]://<server>[:<port>][/<channel>[?<pass>]]\n"); #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) MessageBox(0,szMessage.toLocal8Bit().data(),"KVIrc",0); #else qDebug("%s",szMessage.toLocal8Bit().data()); #endif return KVI_ARGS_RETCODE_STOP; } if(kvi_strEqualCI("-c",p)) { idx++; if(idx >= a->argc) { qDebug("Option -c requires a config file name"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; a->configFile = p; qDebug("Using file %s as config",p); continue; } if(kvi_strEqualCI("-e",p)) { idx++; if(idx >= a->argc) { qDebug("Option -e requires a command"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; if(!a->szExecCommand.isEmpty()) a->szExecCommand.append("\n"); a->szExecCommand.append(p); continue; } if(kvi_strEqualCI("-x",p)) { idx++; if(idx >= a->argc) { qDebug("Option -x requires a command"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; if(!a->szExecCommand.isEmpty()) a->szExecCommand.append("\n"); a->szExecCommand.append(p); a->bExecuteCommandAndClose=true; continue; } if(kvi_strEqualCI("-r",p)) { idx++; if(idx >= a->argc) { qDebug("Option -r requires a command"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; if(!a->szExecRemoteCommand.isEmpty()) a->szExecRemoteCommand.append("\n"); a->szExecRemoteCommand.append(p); continue; } if(kvi_strEqualCI("-m",p)) { a->bShowPopup = true; continue; } if(kvi_strEqualCI("-n",p)) { idx++; if(idx >= a->argc) { qDebug("Option -n requires a config file name"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; a->configFile = p; a->createFile=true; qDebug("Using file %s as config",p); continue; } if(kvi_strEqualCI("-nosplash",p)) { a->bShowSplashScreen = false; continue; } if(kvi_strEqualCI("-f",p)) { a->bForceNewSession = true; continue; } if(kvi_strEqualCI("-session",p)||kvi_strEqualCI("-display",p)||kvi_strEqualCI("-name",p)) { // Qt apps are supposed to handle the params to these switches, but we'll skip arg for now idx++; continue; } if(kvi_strEqualCI("-external",p)) { idx++; if(idx >= a->argc) { qDebug("Option --external requires n irc:// url"); return KVI_ARGS_RETCODE_ERROR; } p = a->argv[idx]; if(kvi_strEqualCIN(p,"irc://",6) || kvi_strEqualCIN(p,"irc6://",7) || kvi_strEqualCIN(p,"ircs://",7) || kvi_strEqualCIN(p,"ircs6://",8)) { a->szExecCommand = "openurl "; a->szExecCommand.append(QString::fromLocal8Bit(p).remove(QChar('$')).remove(QChar(';')).remove(QChar('%'))); return KVI_ARGS_RETCODE_OK; } return KVI_ARGS_RETCODE_ERROR; } if(*p != '-') { // no dash if(kvi_strEqualCIN(p,"irc://",6) || kvi_strEqualCIN(p,"irc6://",7) || kvi_strEqualCIN(p,"ircs://",7) || kvi_strEqualCIN(p,"ircs6://",8)) { if(!a->szExecCommand.isEmpty()) a->szExecCommand.append('\n'); a->szExecCommand = "openurl "; a->szExecCommand.append(QString::fromLocal8Bit(p).remove(QChar('$')).remove(QChar(';')).remove(QChar('%'))); } else { QString szTmp = QString::fromLocal8Bit(p); bool bOk; szTmp.toUInt(&bOk); if(bOk) { szPort = szTmp; } else { QString ri = szTmp.right(4); if(KviQString::equalCI(ri,".kvs")) { if(!a->szExecCommand.isEmpty()) a->szExecCommand.append('\n'); a->szExecCommand.append("parse \""); szTmp.replace(QChar('$'), QString("\\$")); szTmp.replace(QChar('\\'), QString("\\\\")); a->szExecCommand.append(szTmp); a->szExecCommand.append('"'); } else if(KviQString::equalCI(ri,".kvt")) { if(!a->szExecCommand.isEmpty()) a->szExecCommand.append('\n'); a->szExecCommand.append("theme.install \""); szTmp.replace(QChar('$'), QString("\\$")); szTmp.replace(QChar('\\'), QString("\\\\")); a->szExecCommand.append(szTmp); a->szExecCommand.append('"'); } else if(KviQString::equalCI(ri,".kva")) { if(!a->szExecCommand.isEmpty()) a->szExecCommand.append('\n'); a->szExecCommand.append("addon.install \""); szTmp.replace(QChar('$'), QString("\\$")); szTmp.replace(QChar('\\'), QString("\\\\")); a->szExecCommand.append(szTmp); a->szExecCommand.append('"'); } else { szServer = szTmp; // assume a plain server name } } } } } if(!szServer.isEmpty()) { if(!a->szExecCommand.isEmpty()) a->szExecCommand.append('\n'); a->szExecCommand.append("server -u "); a->szExecCommand.append(szServer); if(!szPort.isEmpty()) { a->szExecCommand.append(' '); a->szExecCommand.append(szPort); } } return KVI_ARGS_RETCODE_OK; }