int Process::exec(const QString &program, const QStringList &arguments, bool throwOnError) { Q_ASSERT(thisObject().engine() == engine()); if (!start(findExecutable(program), arguments)) { if (throwOnError) { context()->throwError(Tr::tr("Error running '%1': %2") .arg(program, m_qProcess->errorString())); } return -1; } m_qProcess->closeWriteChannel(); m_qProcess->waitForFinished(-1); if (throwOnError) { if (m_qProcess->error() != QProcess::UnknownError && m_qProcess->error() != QProcess::Crashed) { context()->throwError(Tr::tr("Error running '%1': %2") .arg(program, m_qProcess->errorString())); } else if (m_qProcess->exitStatus() == QProcess::CrashExit || m_qProcess->exitCode() != 0) { QString errorMessage = m_qProcess->error() == QProcess::Crashed ? Tr::tr("Error running '%1': %2").arg(program, m_qProcess->errorString()) : Tr::tr("Process '%1' finished with exit code %2.").arg(program).arg( m_qProcess->exitCode()); const QString stdOut = readStdOut(); if (!stdOut.isEmpty()) errorMessage.append(Tr::tr(" The standard output was:\n")).append(stdOut); const QString stdErr = readStdErr(); if (!stdErr.isEmpty()) errorMessage.append(Tr::tr(" The standard error output was:\n")).append(stdErr); context()->throwError(errorMessage); } } if (m_qProcess->error() != QProcess::UnknownError) return -1; return m_qProcess->exitCode(); }
void Player::start() { //Make sure we don't re-start a running process. if (this->isRunning()) { this->logError("Attempting to start a running process."); return; } //Launch a new bot process. m_process = new QProcess(this); QString launchCommand(m_launchCommand.c_str()); m_process->start(launchCommand); if (m_process->waitForStarted(1000)) { this->logMessage("Bot process started."); //Make some signal/slot connections. QObject::connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); QObject::connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); QObject::connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onProcessFinished(int,QProcess::ExitStatus))); } else {
int oLaucher::Crack(QSqlQuery qry) { pathFileName = qry.value(0).toString(); pathDictName = qry.value(1).toString(); AplicarDict = qry.value(2).toBool(); hashFileName = qry.value(5).toString(); hashDictName = qry.value(4).toString(); int ret = 0; //qDebug() << "[!] ATTACK:: " << qry.value(0).toString() << "DICT " << qry.value(1).toString(); if(QFile::exists(pathFileName)==false) { return -1; } if(QFile::exists(pathDictName)==false) { return -2; } QFileInfo fileInf(pathFileName); QString extension = fileInf.suffix(); oPrograms dats; QString fileTmpPass; connect(proc, SIGNAL(errorOccurred(QProcess::ProcessError)), this, SLOT(launchingError(QProcess::ProcessError))); //connect(proc, SIGNAL(finished(int)), this, SLOT(ProcCerrado(int))); connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); connect(proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(launchingError(QProcess::ProcessError))); fileTmpPass = fileTmpPass + "/tmp/filePwd" + QString::number(qrand() % 1000); #ifdef Q_OS_WIN32 fileTmpPass = getenv("TMP"); fileTmpPass = fileTmpPass + "\\filePwd" + QString::number(qrand() % 1000); #endif QFile::remove(fileTmpPass); if(extension.compare("cap", Qt::CaseInsensitive)==0) { // Crackea con Pyrit qDebug() << "[!] Es un CAP"; crackerProgram = 3; //QString strTmp = "attack_cowpatty"; oSqlite db; QSqlQuery qry; GetPathUtils(crackerProgram, &dats); if(db.GetInfWpa(&qry, hashFileName)>=0) { //GetParamPyrit(pathFileName, qry.value(0).toString(), qry.value(1).toString(), pathDictName, &dats.args); } } if(extension.compare("hccap", Qt::CaseInsensitive)==0) { // Crackea con oclHashcat crackerProgram = 2; qDebug() << "[!] Es un HCCAP"; GetParamHascat(pathFileName, AplicarDict, "QVariant::String", pathDictName, &dats.args); GetPathUtils(crackerProgram, &dats); } if(extension.compare("pdf", Qt::CaseInsensitive)==0) { qDebug() << "[+] Es un PDF"; GetPathUtils(1, &dats); dats.args << pathDictName; if(AplicarDict) dats.args << pathDictName; else { //Aplicar fuerza bruta } proc->start(dats.pathExec, dats.args); while(proc->isOpen()) { //qDebug() << "IS OPEN xD"; #ifdef Q_OS_WIN CheckIdleUser(); Sleep(1000); #endif } } if(extension.compare("rar", Qt::CaseInsensitive)==0) { //qDebug() << "[+] Es un rar"; GetPathUtils(1, &dats); dats.args << pathDictName; if(AplicarDict) dats.args << pathDictName; else { //Aplicar fuerza bruta } proc->start(dats.pathExec, dats.args); //proc->waitForFinished(-1); } if(extension.compare("docx", Qt::CaseInsensitive)==0) { //qDebug() << "[+] Es un MS DOCX"; GetPathUtils(1, &dats); dats.args << pathDictName; if(AplicarDict) dats.args << pathDictName; else { //Aplicar fuerza bruta } proc->start(dats.pathExec, dats.args); //proc->waitForFinished(-1); } qDebug() << "[+] Launching .. " << dats.pathExec << dats.args; proc->start(dats.pathExec, dats.args); proc->waitForFinished(-1); AnalyzeOutput(fileTmpPass, crackerProgram); delete proc; return ret; }
void MaximaSession::login() { qDebug()<<"login"; if (m_process) m_process->deleteLater(); #ifndef Q_OS_WIN m_process=new KPtyProcess(this); m_process->setPtyChannels(KPtyProcess::StdinChannel|KPtyProcess::StdoutChannel); m_process->pty()->setEcho(false); #else m_process=new KProcess(this); m_process->setOutputChannelMode(KProcess::SeparateChannels); #endif m_process->setProgram(MaximaSettings::self()->path().toLocalFile()); m_process->start(); connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(restartMaxima())); #ifndef Q_OS_WIN connect(m_process->pty(), SIGNAL(readyRead()), this, SLOT(readStdOut())); #else connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut())); #endif connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr())); connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError))); QString initFile=QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("cantor/maximabackend/cantor-initmaxima.lisp")); qDebug()<<"initFile: "<<initFile; QString cmd=initCmd.arg(initFile); qDebug()<<"sending cmd: "<<cmd<<endl; #ifndef Q_OS_WIN m_process->pty()->write(cmd.toUtf8()); #else m_process->write(cmd.toUtf8()); #endif Cantor::Expression* expr=evaluateExpression(QLatin1String("print(____END_OF_INIT____);"), Cantor::Expression::DeleteOnFinish); expr->setInternal(true); //check if we actually landed in the queue and there wasn't some //error beforehand instead if(m_expressionQueue.contains(dynamic_cast<MaximaExpression*>(expr))) { //move this expression to the front m_expressionQueue.prepend(m_expressionQueue.takeLast()); } //reset the typesetting state setTypesettingEnabled(isTypesettingEnabled()); m_initState=MaximaSession::Initializing; if(!MaximaSettings::self()->autorunScripts().isEmpty()){ QString autorunScripts = MaximaSettings::self()->autorunScripts().join(QLatin1String("\n")); evaluateExpression(autorunScripts, MaximaExpression::DeleteOnFinish); } runFirstExpression(); }