Exemple #1
0
QTextCodec * KviLocale::codecForName(const char * pcName)
{
	KviCString szTmp = pcName;
	bool bSendUtf8;

	int iIdx = szTmp.findFirstIdx('[');
	if(iIdx != -1)
	{
		// Might be a composite codec: either UTF-8 [child codec] or child codec [UTF-8]
		KviSmartTextCodec * pCodec = g_pSmartCodecDict->find(pcName);
		if(pCodec)
			return pCodec; // got cached copy

		if(kvi_strEqualCIN("UTF-8 [", pcName, 7))
		{
			// Likely a smart codec that sends UTF-8
			szTmp.replaceAll("UTF-8 [", "");
			szTmp.replaceAll("]", "");
			bSendUtf8 = true;
		}
		else
		{
			// Likely a smart codec that sends child encoding ?
			szTmp.cutFromFirst(' ');
			bSendUtf8 = false;
		}

		QTextCodec * pChildCodec = QTextCodec::codecForName(szTmp.ptr());
		if(pChildCodec)
		{
			pCodec = new KviSmartTextCodec(pcName, pChildCodec, bSendUtf8);

			if(pCodec->ok())
			{
				g_pSmartCodecDict->replace(pcName, pCodec);
				return pCodec;
			}

			delete pCodec;
		}
		else
		{
			// The name of the child codec was invalid: can't create such a smart codec.
			// We probably screwed up the guess above related to the [ char.
			// This code path is also triggered by the yircfuzzer by specifying completely invalid codec names.
		}
	}

	return QTextCodec::codecForName(pcName);
}
bool KviMircryptionEngine::init(const char * encKey, int encKeyLen, const char * decKey, int decKeyLen)
{
	if(encKey && (encKeyLen > 0))
	{
		if(!(decKey && (decKeyLen > 0)))
		{
			decKey = encKey;
			decKeyLen = encKeyLen;
		} // else all
	}
	else
	{
		// no encrypt key specified...
		if(decKey && decKeyLen)
		{
			encKey = decKey;
			encKeyLen = decKeyLen;
		}
		else
		{
			// both keys missing
			setLastError(__tr2qs("Missing both encryption and decryption key: at least one is needed"));
			return false;
		}
	}
	m_szEncryptKey = KviCString(encKey, encKeyLen);
	m_szDecryptKey = KviCString(decKey, decKeyLen);

	m_bEncryptCBC = true;
	m_bDecryptCBC = true;

	if((kvi_strEqualCIN("ecb:", m_szEncryptKey.ptr(), 4) || kvi_strEqualCIN("old:", m_szEncryptKey.ptr(), 4))
	    && (m_szEncryptKey.len() > 4))
	{
		m_bEncryptCBC = false;
		m_szEncryptKey.cutLeft(4);
	}
	else if(kvi_strEqualCIN("cbc:", m_szEncryptKey.ptr(), 4) && (m_szEncryptKey.len() > 4))
	{
		m_szEncryptKey.cutLeft(4);
	}

	if((kvi_strEqualCIN("ecb:", m_szDecryptKey.ptr(), 4) || kvi_strEqualCIN("old:", m_szDecryptKey.ptr(), 4))
	    && (m_szDecryptKey.len() > 4))
	{
		m_bDecryptCBC = false;
		m_szDecryptKey.cutLeft(4);
	}
	else if(kvi_strEqualCIN("cbc:", m_szDecryptKey.ptr(), 4) && (m_szDecryptKey.len() > 4))
	{
		m_szDecryptKey.cutLeft(4);
	}

	return true;
}
Exemple #3
0
bool DccChatWindow::event(QEvent * e)
{
	if(e->type() == KVI_THREAD_EVENT)
	{
		switch(((KviThreadEvent *)e)->id())
		{
			case KVI_DCC_THREAD_EVENT_ERROR:
			{
				KviError::Code * pError = ((KviThreadDataEvent<KviError::Code> *)e)->getData();
				QString szErr = KviError::getDescription(*pError);
				if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatError, this, szErr, m_pDescriptor->idString()))
					output(KVI_OUT_DCCERROR, __tr2qs_ctx("ERROR: %Q", "dcc"), &szErr);
				KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatDisconnected, this, m_pDescriptor->idString());
				delete pError;
				return true;
			}
			break;
			case KVI_DCC_THREAD_EVENT_DATA:
			{
				KviCString * encoded = ((KviThreadDataEvent<KviCString> *)e)->getData();
				KviCString d = KviCString(decodeText(encoded->ptr()));
				if(d.firstCharIs(0x01))
				{
					d.cutLeft(1);
					if(d.lastCharIs(0x01))
						d.cutRight(1);
					if(kvi_strEqualCIN("ACTION", d.ptr(), 6))
						d.cutLeft(6);
					d.stripLeftWhiteSpace();
					output(KVI_OUT_ACTION, "%Q %s", &(m_pDescriptor->szNick), d.ptr());
					if(!hasAttention(KviWindow::MainWindowIsVisible))
					{
						if(KVI_OPTION_BOOL(KviOption_boolFlashDccChatWindowOnNewMessages))
						{
							demandAttention();
						}
						if(KVI_OPTION_BOOL(KviOption_boolPopupNotifierOnNewDccChatMessages))
						{
							QString szMsg = "<b>";
							szMsg += m_pDescriptor->szNick;
							szMsg += "</b> ";
							szMsg += KviQString::toHtmlEscaped(QString(d.ptr()));
							//qDebug("KviIrcServerParser_ctcp.cpp:975 debug: %s",szMsg.data());
							g_pApp->notifierMessage(this, KVI_OPTION_MSGTYPE(KVI_OUT_ACTION).pixId(), szMsg, KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime));
						}
					}
				}
				else
				{

#ifdef COMPILE_CRYPT_SUPPORT
					if(KviCryptSessionInfo * cinf = cryptSessionInfo())
					{
						if(cinf->m_bDoDecrypt)
						{
							KviCString decryptedStuff;
							switch(cinf->m_pEngine->decrypt(d.ptr(), decryptedStuff))
							{
								case KviCryptEngine::DecryptOkWasEncrypted:
								case KviCryptEngine::DecryptOkWasEncoded:
								case KviCryptEngine::DecryptOkWasPlainText:
									if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage, this, QString(decryptedStuff.ptr()), m_pDescriptor->idString()))
									{
										g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_DCCCHATMSG,
										    m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szUser.toUtf8().data(),
										    m_pDescriptor->szHost.toUtf8().data(), decryptedStuff.ptr());
									}
									delete encoded;
									return true;
									break;

								default: // also case KviCryptEngine::DecryptError
								{
									QString szErr = cinf->m_pEngine->lastError();
									output(KVI_OUT_SYSTEMERROR,
									    __tr2qs_ctx("The following message appears to be encrypted, but the encryption engine failed to decode it: %Q", "dcc"),
									    &szErr);
								}
								break;
							}
						}
					}
					else
					{
#endif
						// FIXME!
						if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage, this, QString(d.ptr()), m_pDescriptor->idString()))
						{
							g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_DCCCHATMSG,
							    m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szUser.toUtf8().data(),
							    m_pDescriptor->szHost.toUtf8().data(), d.ptr());
							if(!hasAttention(KviWindow::MainWindowIsVisible))
							{
								if(KVI_OPTION_BOOL(KviOption_boolFlashDccChatWindowOnNewMessages))
								{
									demandAttention();
								}
								if(KVI_OPTION_BOOL(KviOption_boolPopupNotifierOnNewDccChatMessages))
								{
									QString szMsg = KviQString::toHtmlEscaped(QString(d.ptr()));
									g_pApp->notifierMessage(this, KviIconManager::DccChatMsg, szMsg, KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime));
								}
							}
						}
#ifdef COMPILE_CRYPT_SUPPORT
					}
#endif
				}
				delete encoded;
				return true;
			}
			break;
		}
	}
	return KviWindow::event(e);
}
Exemple #4
0
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;
}
	bool KviCryptController::initializeEngine(KviCryptEngine * pEngine)
	{
		KviCString szEncryptKey;
		KviCString szDecryptKey;
		KviCString szEncKey = "";
		KviCString szDecKey = "";

		if(m_pEnableEncrypt->isChecked())
		{
			bool bEcb=false, bOld=false;
			szEncryptKey = m_pEncryptKeyEdit->text();
			if(kvi_strEqualCIN("ecb:",szEncryptKey.ptr(),4) && (szEncryptKey.len() > 4))
			{
				szEncryptKey.cutLeft(4);
				bEcb=true;
			} else if(kvi_strEqualCIN("old:",szEncryptKey.ptr(),4) && (szEncryptKey.len() > 4)) {
				szEncryptKey.cutLeft(4);
				bOld=true;
			} else if(kvi_strEqualCIN("cbc:",szEncryptKey.ptr(),4)) {
				szEncryptKey.cutLeft(4);
			}

			if(m_pEncryptHexKeyCheck->isChecked())
			{
				char * pcTmpKey;
				if(szEncryptKey.hexToBuffer(&pcTmpKey,false))
				{
					szEncKey = pcTmpKey;
					KviCString::freeBuffer(pcTmpKey);
				}
			} else {
				szEncKey = szEncryptKey;
			}
			if(bEcb)
				szEncKey.prepend("ecb:");
			else if(bOld)
				szEncKey.prepend("old:");
		}

		if(m_pEnableDecrypt->isChecked())
		{
			bool bEcb=false, bOld=false;
			szDecryptKey = m_pDecryptKeyEdit->text();
			if(kvi_strEqualCIN("ecb:",szDecryptKey.ptr(),4) && (szDecryptKey.len() > 4))
			{
				szDecryptKey.cutLeft(4);
				bEcb=true;
			} else if(kvi_strEqualCIN("old:",szDecryptKey.ptr(),4) && (szDecryptKey.len() > 4)) {
				szDecryptKey.cutLeft(4);
				bOld=true;
			} else if(kvi_strEqualCIN("cbc:",szDecryptKey.ptr(),4)) {
				szDecryptKey.cutLeft(4);
			}

			if(m_pDecryptHexKeyCheck->isChecked())
			{
				char * pcTmpKey;
				if(szDecryptKey.hexToBuffer(&pcTmpKey,false))
				{
					szDecKey = pcTmpKey;
					KviCString::freeBuffer(pcTmpKey);
				}
			} else {
				szDecKey = szDecryptKey;
			}
			if(bEcb)
				szDecKey.prepend("ecb:");
			else if(bOld)
				szDecKey.prepend("old:");
		}

		bool bRet = pEngine->init(szEncKey.ptr(),szEncKey.len(),szDecKey.ptr(),szDecKey.len());

		return bRet;
	}
bool KviRijndaelEngine::init(const char * encKey, int encKeyLen, const char * decKey, int decKeyLen)
{
	if(m_pEncryptCipher)
	{
		delete m_pEncryptCipher;
		m_pEncryptCipher = nullptr;
	}
	if(m_pDecryptCipher)
	{
		delete m_pDecryptCipher;
		m_pDecryptCipher = nullptr;
	}

	if(encKey && (encKeyLen > 0))
	{
		if(!(decKey && (decKeyLen > 0)))
		{
			decKey = encKey;
			decKeyLen = encKeyLen;
		} // else all
	}
	else
	{
		// no encrypt key specified...
		if(decKey && decKeyLen)
		{
			encKey = decKey;
			encKeyLen = decKeyLen;
		}
		else
		{
			// both keys missing
			setLastError(__tr2qs("Missing both encryption and decryption key: at least one is needed"));
			return false;
		}
	}

	KviCString szTmpEncryptKey = KviCString(encKey, encKeyLen);
	KviCString szTmpDecryptKey = KviCString(decKey, decKeyLen);

	m_bEncryptMode = CBC; // default mode
	m_bDecryptMode = CBC; // default mode

	if(kvi_strEqualCIN("ecb:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
		m_bEncryptMode = ECB;
	}
	else if(kvi_strEqualCIN("old:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
		m_bEncryptMode = OldCBC;
	}
	else if(kvi_strEqualCIN("cbc:", szTmpEncryptKey.ptr(), 4) && (szTmpEncryptKey.len() > 4))
	{
		szTmpEncryptKey.cutLeft(4);
	}

	if(kvi_strEqualCIN("ecb:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
		m_bDecryptMode = ECB;
	}
	else if(kvi_strEqualCIN("old:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
		m_bDecryptMode = OldCBC;
	}
	else if(kvi_strEqualCIN("cbc:", szTmpDecryptKey.ptr(), 4) && (szTmpDecryptKey.len() > 4))
	{
		szTmpDecryptKey.cutLeft(4);
	}

	int defLen = getKeyLen();

	szTmpEncryptKey.padRight(defLen);
	szTmpDecryptKey.padRight(defLen);

	m_pEncryptCipher = new Rijndael();

	int retVal = m_pEncryptCipher->init(
	    (m_bEncryptMode == ECB) ? Rijndael::ECB : Rijndael::CBC,
	    Rijndael::Encrypt,
	    (unsigned char *)szTmpEncryptKey.ptr(),
	    getKeyLenId());
	if(retVal != RIJNDAEL_SUCCESS)
	{
		delete m_pEncryptCipher;
		m_pEncryptCipher = nullptr;
		setLastErrorFromRijndaelErrorCode(retVal);
		return false;
	}

	m_pDecryptCipher = new Rijndael();
	retVal = m_pDecryptCipher->init(
	    (m_bEncryptMode == ECB) ? Rijndael::ECB : Rijndael::CBC,
	    Rijndael::Decrypt,
	    (unsigned char *)szTmpDecryptKey.ptr(),
	    getKeyLenId());
	if(retVal != RIJNDAEL_SUCCESS)
	{
		delete m_pEncryptCipher;
		m_pEncryptCipher = nullptr;
		delete m_pDecryptCipher;
		m_pDecryptCipher = nullptr;
		setLastErrorFromRijndaelErrorCode(retVal);
		return false;
	}

	return true;
}
bool KviApplication::checkFileAssociations()
{
#if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)

#define QUERY_BUFFER 2048

	char * pcBuffer;
	DWORD len = QUERY_BUFFER;
	DWORD err;
	pcBuffer = (char *)malloc(len * sizeof(char));
	HKEY hKey;

	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, ".kvs", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if((err = RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len)) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCIN("KVIrcScript", pcBuffer, 11))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcScript", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if((err = RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len)) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCI(__tr2qs("KVIrc KVS Script").toLocal8Bit().data(), pcBuffer))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcScript\\DefaultIcon", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if(RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		QString szIcon = applicationFilePath() + ",1";
		szIcon.replace('/', "\\");
		if(!kvi_strEqualCI(szIcon.toLocal8Bit().data(), pcBuffer))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcScript\\Shell\\Parse", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if(RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCI(__tr2qs("Run KVS Script").toLocal8Bit().data(), pcBuffer))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcScript\\Shell\\Parse\\command", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if(RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		QString szCmd = applicationFilePath() + " \"%1\"";
		szCmd.replace('/', "\\");
		if(!kvi_strEqualCI(szCmd.toLocal8Bit().data(), pcBuffer))
		{
			free(pcBuffer);
			return false;
		}
	}

	//Config
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, ".kvc", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if((err = RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len)) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCIN("KVIrcConfig", pcBuffer, 11))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcConfig", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	//Addon
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, ".kva", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if((err = RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len)) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCIN("KVIrcAddon", pcBuffer, 11))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcAddon", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	//Theme
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, ".kvt", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	if((err = RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pcBuffer, &len)) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}
	else
	{
		if(!kvi_strEqualCIN("KVIrcTheme", pcBuffer, 11))
		{
			free(pcBuffer);
			return false;
		}
	}

	len = QUERY_BUFFER;
	if(RegOpenKeyEx(HKEY_CLASSES_ROOT, "KVIrcTheme", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
	{
		free(pcBuffer);
		return false;
	}

	free(pcBuffer);
#endif
	return true;
}