diff --git a/gui/SearchWindow.cpp b/gui/SearchWindow.cpp index 9543467..bc5d9b7 100644 --- a/gui/SearchWindow.cpp +++ b/gui/SearchWindow.cpp @@ -30,12 +30,15 @@ #include #include #include +#include "config.h" +#include "helpers.h" #include "SearchWindow.h" SearchWindow::SearchWindow(QWidget *parent, Qt::WindowFlags flags) : QWidget (parent, flags), m_status ("status"), m_leet_cb ("L33t"), +m_dict_lang ("Dictionary Language"), m_btn_exec ("Search"), m_btn_clear ("Clear") { @@ -54,6 +57,9 @@ m_btn_clear ("Clear") m_layout.setColumnStretch(0, 10); // First row. + m_dict_lang.addItems(get_files(CONFIG_DICT_FULL_PATH)); + m_layout.addWidget(&m_dict_lang, 0, 0); + m_layout.addWidget(&m_leet_cb, 0, 1); m_num_threads.setValue((int) eoskeygen::KeySearch::max_threads()); @@ -98,6 +104,8 @@ void SearchWindow::initSignals() connect(&m_worker, SIGNAL(finished()), this, SLOT(searchFinished())); connect(this, SIGNAL(addOutput(QString)), this, SLOT(output(QString))); + + connect(&m_dict_lang, SIGNAL(selectionChanged(QStringList)), this, SLOT(langSelected(QStringList))); } void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct eoskeygen::KeySearch::result& result) @@ -108,6 +116,7 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct QString mid = pub.mid(pos, len); QString left = pub.left(pos); QString right = pub.mid(pos + len, pub.size() - pos); + eoskeygen::Dictionary::search_result_t dict_res = m_dict.search(pub.toStdString()); QString out = "Public: " + pub.left(3); for(int i = 3; i < pub.length(); ) { @@ -118,6 +127,16 @@ void SearchWindow::onResult(const struct libeosio::ec_keypair* key, const struct continue; } + // Look in the dictionary. + auto dp = dict_res.find(i); + if (dp != dict_res.end()) { + int p = (int) dp->first; + int l = (int) dp->second; + out += "" + pub.mid(p, l) + ""; + i += l; + continue; + } + out += pub[i++]; } @@ -181,10 +200,29 @@ void SearchWindow::output(const QString& html) m_output.verticalScrollBar()->setValue(m_output.verticalScrollBar()->maximum()); } +void SearchWindow::langSelected(QStringList selected) +{ + std::string base_path(CONFIG_DICT_FULL_PATH); + + // Clear dictionary first. + m_dict.clear(); + + // Go through all selected languages. + for(QStringList::const_iterator it = selected.cbegin(); it != selected.cend(); it++) { + + // Load and add them to dictionary. + eoskeygen::Dictionary dict; + dict.loadFromFile(base_path + "/" + it->toStdString()); + + m_dict.add(dict); + } +} + void SearchWindow::searchStarted() { m_txt_search.setEnabled(false); m_txt_search.setHidden(true); + m_dict_lang.setEnabled(false); m_btn_exec.setEnabled(false); m_btn_clear.setEnabled(false); m_num_threads.setEnabled(false); @@ -195,6 +233,7 @@ void SearchWindow::searchFinished() { m_txt_search.setEnabled(true); m_txt_search.setHidden(false); + m_dict_lang.setEnabled(true); m_btn_exec.setEnabled(true); m_btn_clear.setEnabled(true); m_num_threads.setEnabled(true); diff --git a/gui/SearchWindow.h b/gui/SearchWindow.h index 0bc6a65..1aff8b1 100644 --- a/gui/SearchWindow.h +++ b/gui/SearchWindow.h @@ -35,6 +35,7 @@ #include #include #include +#include "MultiSelect.h" class SearchWindow : public QWidget, public eoskeygen::IKeySearchResult { @@ -62,6 +63,9 @@ private slots: // Called when a search is done. void searchFinished(); + // Called when dictionary language(s) are selected. + void langSelected(QStringList selected); + signals: void addOutput(const QString& line); @@ -72,6 +76,8 @@ private: eoskeygen::KeySearch m_ksearch; + eoskeygen::Dictionary m_dict; + // Widgets // ---------------- @@ -89,6 +95,8 @@ private: QCheckBox m_leet_cb; + MultiSelect m_dict_lang; + // Buttons QPushButton m_btn_exec; QPushButton m_btn_clear;