From 161241951dfcd646cf7efcfdf449410e3d436089 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Tue, 3 Feb 2015 10:55:54 +0100 Subject: [PATCH] Allow wordlist as fileparameter --- CHANGES | 2 ++ src/pp.c | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 9a94b4c..39c1e12 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ - Exit if stdout is closed or has a error - Fix for "Bug --pw-min" issue +- Print position when stopped +- Allow wordlist as fileparameter * v0.19 -> v0.20: diff --git a/src/pp.c b/src/pp.c index e684fb7..38cd8bd 100644 --- a/src/pp.c +++ b/src/pp.c @@ -167,7 +167,7 @@ static const u32 DEF_HASH_LOG_SIZE[33] = static const char *USAGE_MINI[] = { - "Usage: %s [options] < wordlist", + "Usage: %s [options] [<] wordlist", "", "Try --help for more help.", NULL @@ -175,7 +175,7 @@ static const char *USAGE_MINI[] = static const char *USAGE_BIG[] = { - "Usage: %s [options] < wordlist", + "Usage: %s [options] [<] wordlist", "", "* Startup:", "", @@ -782,13 +782,20 @@ int main (int argc, char *argv[]) return (-1); } - if (optind != argc) + if ((optind != argc) && (optind + 1 != argc)) { usage_mini_print (argv[0]); return (-1); } + char *wordlist = NULL; + + if (optind + 1 == argc) + { + wordlist = argv[optind]; + } + if (pw_min <= 0) { fprintf (stderr, "Value of --pw-min (%d) must be greater than %d\n", pw_min, 0); @@ -875,9 +882,9 @@ int main (int argc, char *argv[]) if (dupe_check) { - int in_max = MIN(IN_LEN_MAX, pw_max); - - for (int pw_len = IN_LEN_MIN; pw_len <= in_max; pw_len++) + int in_max = MIN(IN_LEN_MAX, pw_max); + + for (int pw_len = IN_LEN_MIN; pw_len <= in_max; pw_len++) { db_entry_t *db_entry = &db_entries[pw_len]; @@ -914,7 +921,6 @@ int main (int argc, char *argv[]) } } - /* * catch signal user interrupt */ @@ -928,11 +934,25 @@ int main (int argc, char *argv[]) * load elems from stdin */ - while (!feof (stdin)) + FILE *read_fp = stdin; + + if (wordlist) + { + read_fp = fopen (wordlist, "rb"); + + if (read_fp == NULL) + { + fprintf (stderr, "%s: %s\n", wordlist, strerror (errno)); + + return (-1); + } + } + + while (!feof (read_fp)) { char buf[BUFSIZ]; - char *input_buf = fgets (buf, sizeof (buf), stdin); + char *input_buf = fgets (buf, sizeof (buf), read_fp); if (input_buf == NULL) continue; @@ -991,11 +1011,16 @@ int main (int argc, char *argv[]) } } + if (wordlist) + { + fclose (read_fp); + } + if (dupe_check) { - int in_max = MIN(IN_LEN_MAX, pw_max); - - for (int pw_len = IN_LEN_MIN; pw_len <= in_max; pw_len++) + int in_max = MIN(IN_LEN_MAX, pw_max); + + for (int pw_len = IN_LEN_MIN; pw_len <= in_max; pw_len++) { db_entry_t *db_entry = &db_entries[pw_len];