Skip to content

Commit

Permalink
Allow wordlist as fileparameter
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteube committed Feb 3, 2015
1 parent f662d8d commit 1612419
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
49 changes: 37 additions & 12 deletions src/pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ 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
};

static const char *USAGE_BIG[] =
{
"Usage: %s [options] < wordlist",
"Usage: %s [options] [<] wordlist",
"",
"* Startup:",
"",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -914,7 +921,6 @@ int main (int argc, char *argv[])
}
}


/*
* catch signal user interrupt
*/
Expand All @@ -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;

Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 1612419

Please sign in to comment.