Loading include/MainWindow.h +38 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ #define MAINWINDOW_H #include "Statsgen.h" #include "Utils.h" #include <QMainWindow> #include <QThread> Loading @@ -20,6 +21,42 @@ #include <QVBoxLayout> #include <QtCharts> class ProgressThread : public QThread { Q_OBJECT void run() { unsigned int progress = 0; uint64_t processed = 0; int finished = 0; const int nbthreads = _s.getNbThreads(); const struct thread_data* td = _s.getThreadsData(); while(td[nbthreads-1].lineEnd == 0){ msleep(500); } const uint64_t nblines = td[nbthreads-1].lineEnd; while(finished != nbthreads){ processed = 0; finished = 0; for(int i=0; i < nbthreads; ++i){ processed += td[i].total_counter; finished += td[i].finished; } progress = (int) percentage(processed, nblines); _qpb.setValue(progress); msleep(500); } _qpb.setValue(100); } public: ProgressThread(Statsgen &s, QProgressBar& qpb):_s(s), _qpb(qpb){} private: Statsgen &_s; QProgressBar &_qpb; }; namespace Ui { class MainWindow; } Loading Loading @@ -50,6 +87,7 @@ private: QMessageBox waitBox; QVBoxLayout * layoutCharset = nullptr; QVBoxLayout * layoutLength = nullptr; ProgressThread* progressThread = nullptr; int firstTime=1; double initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCharset, double & percentageTotal, double & percentageSecurity); }; Loading include/Statsgen.h +7 −3 Original line number Diff line number Diff line Loading @@ -59,8 +59,8 @@ struct minMax { struct thread_data { int thread_id; std::string filename; uint64_t lineBegin; uint64_t lineEnd; uint64_t lineBegin = 0; uint64_t lineEnd = 0; uint64_t total_counter = 0; uint64_t total_filter = 0; Loading @@ -81,6 +81,8 @@ struct thread_data { int limitAdvancedmask; SecurityRules sr; bool finished = false; }; Loading Loading @@ -191,12 +193,14 @@ public: inline uint64_t getTotalCounter() const { return total_counter; } inline uint64_t getTotalFilter() const { return total_filter; } inline uint64_t getNbSecurePasswords() const { return _sr.nbSecurePassword; } inline int getNbThreads() const { return nbThread; } inline const IntOccurrence& getStatsLength() const { return stats_length; } inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; } inline const thread_data* getThreadsData() const { return td; } private: std::string filename; struct thread_data td[MAX_THREADS]; // Filters Loading src/core/Statsgen.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,6 @@ int Statsgen::generate_stats() { } pthread_t threads[MAX_THREADS]; struct thread_data td[MAX_THREADS]; pthread_attr_t attr; Loading Loading @@ -171,6 +170,7 @@ int Statsgen::generate_stats() { } for(int i=0; i < nbThread; i++) { td[i].finished = true; mergeThread(td[i]); } Loading src/gui/MainWindow.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -153,6 +153,8 @@ void MainWindow::startGame() { stats.setSecurityRules(8,0,1,1,1); } ui->fileLine->setDisabled(true); ui->Browser->setDisabled(true); ui->threadNumberSpin->setDisabled(true); ui->TopXAnswerSpin->setDisabled(true); ui->MaxSimpleMaxSpin->setDisabled(true); Loading @@ -168,6 +170,7 @@ void MainWindow::startGame() { ui->regexCheckBox->setDisabled(true); ui->maxAdvancedCheckBox->setDisabled(true); ui->maxSimpleCheckBox->setDisabled(true); ui->progressBar->setValue(0); delete layoutLength; delete layoutCharset; Loading @@ -176,8 +179,11 @@ void MainWindow::startGame() { connect(workerThread, SIGNAL(resultReady()), this, SLOT(handleResults())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); workerThread->start(); waitBox.setText("Analysis in progress"); waitBox.exec(); ui->progressBar->setEnabled(true); delete progressThread; progressThread = new ProgressThread(stats, *ui->progressBar); progressThread->start(); } Loading Loading @@ -246,7 +252,11 @@ double MainWindow::initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCh void MainWindow::handleResults() { waitBox.close(); progressThread->terminate(); progressThread->wait(); ui->progressBar->setValue(100); ui->fileLine->setDisabled(false); ui->Browser->setDisabled(false); ui->charsetWidget->setHidden(false); ui->lengthWidget->show(); ui->threadNumberSpin->setDisabled(false); Loading src/gui/MainWindow.ui +29 −10 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1"> <item> <layout class="QGridLayout" name="settingsLayout"> <item row="3" column="0" colspan="3"> <item row="6" column="0" colspan="3"> <widget class="QGroupBox" name="securityPolicy"> <property name="title"> <string>Security rules</string> Loading Loading @@ -113,14 +113,7 @@ </widget> </widget> </item> <item row="4" column="0" colspan="3"> <widget class="QPushButton" name="startButton"> <property name="text"> <string>Start</string> </property> </widget> </item> <item row="2" column="0" colspan="3"> <item row="5" column="0" colspan="3"> <widget class="QGroupBox" name="advancedOptions"> <property name="title"> <string>Advanced options (only shown in "result.txt")</string> Loading Loading @@ -169,6 +162,13 @@ </widget> </widget> </item> <item row="1" column="0" colspan="3"> <widget class="QPushButton" name="startButton"> <property name="text"> <string>Start</string> </property> </widget> </item> <item row="0" column="1"> <widget class="QLineEdit" name="fileLine"> <property name="sizePolicy"> Loading Loading @@ -205,7 +205,7 @@ </property> </widget> </item> <item row="1" column="0" colspan="3"> <item row="4" column="0" colspan="3"> <widget class="QGroupBox" name="globalOptions"> <property name="title"> <string>Options</string> Loading Loading @@ -268,6 +268,25 @@ </widget> </widget> </item> <item row="2" column="0" colspan="3"> <widget class="QProgressBar" name="progressBar"> <property name="enabled"> <bool>false</bool> </property> <property name="value"> <number>0</number> </property> <property name="textVisible"> <bool>true</bool> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="format"> <string>Progression : %p%</string> </property> </widget> </item> </layout> </item> <item> Loading Loading
include/MainWindow.h +38 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ #define MAINWINDOW_H #include "Statsgen.h" #include "Utils.h" #include <QMainWindow> #include <QThread> Loading @@ -20,6 +21,42 @@ #include <QVBoxLayout> #include <QtCharts> class ProgressThread : public QThread { Q_OBJECT void run() { unsigned int progress = 0; uint64_t processed = 0; int finished = 0; const int nbthreads = _s.getNbThreads(); const struct thread_data* td = _s.getThreadsData(); while(td[nbthreads-1].lineEnd == 0){ msleep(500); } const uint64_t nblines = td[nbthreads-1].lineEnd; while(finished != nbthreads){ processed = 0; finished = 0; for(int i=0; i < nbthreads; ++i){ processed += td[i].total_counter; finished += td[i].finished; } progress = (int) percentage(processed, nblines); _qpb.setValue(progress); msleep(500); } _qpb.setValue(100); } public: ProgressThread(Statsgen &s, QProgressBar& qpb):_s(s), _qpb(qpb){} private: Statsgen &_s; QProgressBar &_qpb; }; namespace Ui { class MainWindow; } Loading Loading @@ -50,6 +87,7 @@ private: QMessageBox waitBox; QVBoxLayout * layoutCharset = nullptr; QVBoxLayout * layoutLength = nullptr; ProgressThread* progressThread = nullptr; int firstTime=1; double initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCharset, double & percentageTotal, double & percentageSecurity); }; Loading
include/Statsgen.h +7 −3 Original line number Diff line number Diff line Loading @@ -59,8 +59,8 @@ struct minMax { struct thread_data { int thread_id; std::string filename; uint64_t lineBegin; uint64_t lineEnd; uint64_t lineBegin = 0; uint64_t lineEnd = 0; uint64_t total_counter = 0; uint64_t total_filter = 0; Loading @@ -81,6 +81,8 @@ struct thread_data { int limitAdvancedmask; SecurityRules sr; bool finished = false; }; Loading Loading @@ -191,12 +193,14 @@ public: inline uint64_t getTotalCounter() const { return total_counter; } inline uint64_t getTotalFilter() const { return total_filter; } inline uint64_t getNbSecurePasswords() const { return _sr.nbSecurePassword; } inline int getNbThreads() const { return nbThread; } inline const IntOccurrence& getStatsLength() const { return stats_length; } inline const StringOccurrence& getStatsCharsets() const { return stats_charactersets; } inline const thread_data* getThreadsData() const { return td; } private: std::string filename; struct thread_data td[MAX_THREADS]; // Filters Loading
src/core/Statsgen.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,6 @@ int Statsgen::generate_stats() { } pthread_t threads[MAX_THREADS]; struct thread_data td[MAX_THREADS]; pthread_attr_t attr; Loading Loading @@ -171,6 +170,7 @@ int Statsgen::generate_stats() { } for(int i=0; i < nbThread; i++) { td[i].finished = true; mergeThread(td[i]); } Loading
src/gui/MainWindow.cpp +13 −3 Original line number Diff line number Diff line Loading @@ -153,6 +153,8 @@ void MainWindow::startGame() { stats.setSecurityRules(8,0,1,1,1); } ui->fileLine->setDisabled(true); ui->Browser->setDisabled(true); ui->threadNumberSpin->setDisabled(true); ui->TopXAnswerSpin->setDisabled(true); ui->MaxSimpleMaxSpin->setDisabled(true); Loading @@ -168,6 +170,7 @@ void MainWindow::startGame() { ui->regexCheckBox->setDisabled(true); ui->maxAdvancedCheckBox->setDisabled(true); ui->maxSimpleCheckBox->setDisabled(true); ui->progressBar->setValue(0); delete layoutLength; delete layoutCharset; Loading @@ -176,8 +179,11 @@ void MainWindow::startGame() { connect(workerThread, SIGNAL(resultReady()), this, SLOT(handleResults())); connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater())); workerThread->start(); waitBox.setText("Analysis in progress"); waitBox.exec(); ui->progressBar->setEnabled(true); delete progressThread; progressThread = new ProgressThread(stats, *ui->progressBar); progressThread->start(); } Loading Loading @@ -246,7 +252,11 @@ double MainWindow::initGraphicalStats(QBarSeries * barLength, QPieSeries * pieCh void MainWindow::handleResults() { waitBox.close(); progressThread->terminate(); progressThread->wait(); ui->progressBar->setValue(100); ui->fileLine->setDisabled(false); ui->Browser->setDisabled(false); ui->charsetWidget->setHidden(false); ui->lengthWidget->show(); ui->threadNumberSpin->setDisabled(false); Loading
src/gui/MainWindow.ui +29 −10 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1"> <item> <layout class="QGridLayout" name="settingsLayout"> <item row="3" column="0" colspan="3"> <item row="6" column="0" colspan="3"> <widget class="QGroupBox" name="securityPolicy"> <property name="title"> <string>Security rules</string> Loading Loading @@ -113,14 +113,7 @@ </widget> </widget> </item> <item row="4" column="0" colspan="3"> <widget class="QPushButton" name="startButton"> <property name="text"> <string>Start</string> </property> </widget> </item> <item row="2" column="0" colspan="3"> <item row="5" column="0" colspan="3"> <widget class="QGroupBox" name="advancedOptions"> <property name="title"> <string>Advanced options (only shown in "result.txt")</string> Loading Loading @@ -169,6 +162,13 @@ </widget> </widget> </item> <item row="1" column="0" colspan="3"> <widget class="QPushButton" name="startButton"> <property name="text"> <string>Start</string> </property> </widget> </item> <item row="0" column="1"> <widget class="QLineEdit" name="fileLine"> <property name="sizePolicy"> Loading Loading @@ -205,7 +205,7 @@ </property> </widget> </item> <item row="1" column="0" colspan="3"> <item row="4" column="0" colspan="3"> <widget class="QGroupBox" name="globalOptions"> <property name="title"> <string>Options</string> Loading Loading @@ -268,6 +268,25 @@ </widget> </widget> </item> <item row="2" column="0" colspan="3"> <widget class="QProgressBar" name="progressBar"> <property name="enabled"> <bool>false</bool> </property> <property name="value"> <number>0</number> </property> <property name="textVisible"> <bool>true</bool> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="format"> <string>Progression : %p%</string> </property> </widget> </item> </layout> </item> <item> Loading