1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-18 04:00:03 +02:00

main.cpp: add support for --dict and --lang flags.

This commit is contained in:
Henrik Hautakoski 2020-02-17 15:39:40 +01:00
parent ade4708b50
commit 62626c14c0

View file

@ -26,6 +26,8 @@
#endif /* HAVE_THREADS */
#include <iostream>
#include <cstring>
#include "config.h"
#include "core/dictionary.h"
#include "string.h"
#include "WIF.h"
#include "crypto/ec.h"
@ -39,10 +41,12 @@ bool option_l33t = false;
int option_num_threads = std::thread::hardware_concurrency();
#endif /* HAVE_THREADS */
void cmd_search(const eoskeygen::strlist_t& words, int count) {
void cmd_search(const eoskeygen::strlist_t& words, const eoskeygen::Dictionary& dict, int count) {
eoskeygen::KeySearch ks;
ks.addDictionary(dict);
if (option_l33t) {
for(std::size_t i = 0; i < words.size(); i++) {
ks.addList(eoskeygen::l33twords(words[i]));
@ -72,7 +76,8 @@ void usage(const char *name) {
#ifdef HAVE_THREADS
<< " | --threads=<num>"
#endif /* HAVE_THREADS */
<< " ] <word_list> [ <count:10> ]"
<< " | --dict=<file> ... "
<< " | --lang=<value> ... ] <word_list> [ <count:10> ]"
<< " | benchmark [ <num:1000> ]"
<< " ]"
<< std::endl << std::endl;
@ -97,6 +102,17 @@ void usage(const char *name) {
<< " --threads=<num>: Use <num> of parallel threads for searching." << std::endl
<< " Default is what the operating system recomend."
#endif /* HAVE_THREADS */
<< std::endl << std::endl
<< " --dict=<file>: Use words found in <file> (separated by newline) to" << std::endl
<< " highlight words in the keys found (note that the words in this" << std::endl
<< " file are not used for search. only for highlight output)." << std::endl
<< " There can be more then one --dict flag. In that case contents" << std::endl
<< " of all files are merged into one dictionary." << std::endl
<< std::endl << std::endl
<< " --lang=<value>: Same as --dict but will use <value>" << std::endl
<< " to find a file in " << CONFIG_SHARE_FULL_PATH << "/dict." << std::endl
<< " There can be more then one --lang flag. In that case contents" << std::endl
<< " of all files are merged into one dictionary." << std::endl
<< std::endl;
std::cout << " Benchmark: " << std::endl
@ -140,6 +156,7 @@ int main(int argc, char **argv) {
int count = 10;
eoskeygen::strlist_t words;
eoskeygen::Dictionary dict;
while(p++ < argc - 1) {
if (!strcmp(argv[p], "--l33t")) {
@ -159,6 +176,29 @@ int main(int argc, char **argv) {
<< " thread support. this option is ignored." << std::endl;
#endif /* HAVE_THREADS */
}
// Dictionary.
else if (!memcmp(argv[p], "--dict=", 7)) {
eoskeygen::Dictionary d;
std::string filename(argv[p] + 7);
if (d.loadFromFile(filename)) {
dict.add(d);
} else {
std::cerr << "Could not load dictionary from file: " << filename << std::endl;
}
}
// Language (dictionary, but we find the file in <CONFIG_SHARE_FULL_PATH>/dict/<lang>)
else if (!memcmp(argv[p], "--lang=", 7)) {
eoskeygen::Dictionary d;
std::string lang(argv[p] + 7);
std::string filename(std::string(CONFIG_SHARE_FULL_PATH) + "/dict" + lang);
if (d.loadFromFile(filename)) {
dict.add(d);
} else {
std::cerr << "Could not load language " << lang << " (" << filename << ")" << std::endl;
}
}
// Error out on any flag we don't support.
else if (argv[p][0] == '-') {
std::cerr << "Unrecognized flag: " << argv[p] << std::endl;
@ -184,7 +224,7 @@ int main(int argc, char **argv) {
return 1;
}
cmd_search(words, count);
cmd_search(words, dict, count);
}
// Benchmark
else if (!strcmp(argv[p], "benchmark")) {