Skip to content

Commit

Permalink
Print position when stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteube committed Feb 3, 2015
1 parent e0c87dd commit f662d8d
Showing 1 changed file with 87 additions and 40 deletions.
127 changes: 87 additions & 40 deletions src/pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <signal.h>

#include "mpz_int128.h"

Expand All @@ -32,6 +33,8 @@
#define WL_DIST_LEN 0
#define CASE_PERMUTE 0
#define DUPE_CHECK 1
#define SAVE_POS 1
#define SAVE_FILE "pp.save"

#define VERSION_BIN 21

Expand Down Expand Up @@ -191,6 +194,7 @@ static const char *USAGE_BIG[] =
" --elem-cnt-max=NUM Maximum number of elements per chain",
" --wl-dist-len Calculate output length distribution from wordlist",
" -c, --dupe-check-disable Disable dupes check for faster inital load",
" --save-pos-disable Save the position for later resume with -s",
"",
"* Resources:",
"",
Expand Down Expand Up @@ -652,6 +656,23 @@ static void add_uniq (db_entry_t *db_entry, char *input_buf, int input_len)
uniq->index++;
}

mpz_t save;

static void catch_int ()
{
FILE *fp = fopen (SAVE_FILE, "w");

if (fp == NULL) fp = stderr;

mpz_out_str (fp, 10, save);

fprintf (fp, "\n");

fclose (fp);

exit (0);
}

int main (int argc, char *argv[])
{
mpz_t pw_ks_pos[OUT_LEN_MAX + 1];
Expand All @@ -675,37 +696,40 @@ int main (int argc, char *argv[])
int wl_dist_len = WL_DIST_LEN;
int case_permute = CASE_PERMUTE;
int dupe_check = DUPE_CHECK;
int save_pos = SAVE_POS;
char *output_file = NULL;

#define IDX_VERSION 'V'
#define IDX_USAGE 'h'
#define IDX_PW_MIN 0x1000
#define IDX_PW_MAX 0x2000
#define IDX_ELEM_CNT_MIN 0x3000
#define IDX_ELEM_CNT_MAX 0x4000
#define IDX_KEYSPACE 0x5000
#define IDX_WL_DIST_LEN 0x6000
#define IDX_CASE_PERMUTE 0x7000
#define IDX_DUPE_CHECK_DISABLE 'c'
#define IDX_SKIP 's'
#define IDX_LIMIT 'l'
#define IDX_OUTPUT_FILE 'o'
#define IDX_VERSION 'V'
#define IDX_USAGE 'h'
#define IDX_PW_MIN 0x1000
#define IDX_PW_MAX 0x2000
#define IDX_ELEM_CNT_MIN 0x3000
#define IDX_ELEM_CNT_MAX 0x4000
#define IDX_KEYSPACE 0x5000
#define IDX_WL_DIST_LEN 0x6000
#define IDX_CASE_PERMUTE 0x7000
#define IDX_SAVE_POS_DISABLE 0x8000
#define IDX_DUPE_CHECK_DISABLE 'c'
#define IDX_SKIP 's'
#define IDX_LIMIT 'l'
#define IDX_OUTPUT_FILE 'o'

struct option long_options[] =
{
{"version", no_argument, 0, IDX_VERSION},
{"help", no_argument, 0, IDX_USAGE},
{"keyspace", no_argument, 0, IDX_KEYSPACE},
{"pw-min", required_argument, 0, IDX_PW_MIN},
{"pw-max", required_argument, 0, IDX_PW_MAX},
{"elem-cnt-min", required_argument, 0, IDX_ELEM_CNT_MIN},
{"elem-cnt-max", required_argument, 0, IDX_ELEM_CNT_MAX},
{"wl-dist-len", no_argument, 0, IDX_WL_DIST_LEN},
{"case-permute", no_argument, 0, IDX_CASE_PERMUTE},
{"dupe-check-disable", no_argument, 0, IDX_DUPE_CHECK_DISABLE},
{"skip", required_argument, 0, IDX_SKIP},
{"limit", required_argument, 0, IDX_LIMIT},
{"output-file", required_argument, 0, IDX_OUTPUT_FILE},
{"version", no_argument, 0, IDX_VERSION},
{"help", no_argument, 0, IDX_USAGE},
{"keyspace", no_argument, 0, IDX_KEYSPACE},
{"pw-min", required_argument, 0, IDX_PW_MIN},
{"pw-max", required_argument, 0, IDX_PW_MAX},
{"elem-cnt-min", required_argument, 0, IDX_ELEM_CNT_MIN},
{"elem-cnt-max", required_argument, 0, IDX_ELEM_CNT_MAX},
{"wl-dist-len", no_argument, 0, IDX_WL_DIST_LEN},
{"case-permute", no_argument, 0, IDX_CASE_PERMUTE},
{"dupe-check-disable", no_argument, 0, IDX_DUPE_CHECK_DISABLE},
{"save-pos-disable", no_argument, 0, IDX_SAVE_POS_DISABLE},
{"skip", required_argument, 0, IDX_SKIP},
{"limit", required_argument, 0, IDX_LIMIT},
{"output-file", required_argument, 0, IDX_OUTPUT_FILE},
{0, 0, 0, 0}
};

Expand All @@ -719,20 +743,21 @@ int main (int argc, char *argv[])
{
switch (c)
{
case IDX_VERSION: version = 1; break;
case IDX_USAGE: usage = 1; break;
case IDX_KEYSPACE: keyspace = 1; break;
case IDX_PW_MIN: pw_min = atoi (optarg); break;
case IDX_PW_MAX: pw_max = atoi (optarg); break;
case IDX_ELEM_CNT_MIN: elem_cnt_min = atoi (optarg); break;
case IDX_ELEM_CNT_MAX: elem_cnt_max = atoi (optarg);
elem_cnt_max_chgd = 1; break;
case IDX_WL_DIST_LEN: wl_dist_len = 1; break;
case IDX_CASE_PERMUTE: case_permute = 1; break;
case IDX_DUPE_CHECK_DISABLE: dupe_check = 0; break;
case IDX_SKIP: mpz_set_str (skip, optarg, 0); break;
case IDX_LIMIT: mpz_set_str (limit, optarg, 0); break;
case IDX_OUTPUT_FILE: output_file = optarg; break;
case IDX_VERSION: version = 1; break;
case IDX_USAGE: usage = 1; break;
case IDX_KEYSPACE: keyspace = 1; break;
case IDX_PW_MIN: pw_min = atoi (optarg); break;
case IDX_PW_MAX: pw_max = atoi (optarg); break;
case IDX_ELEM_CNT_MIN: elem_cnt_min = atoi (optarg); break;
case IDX_ELEM_CNT_MAX: elem_cnt_max = atoi (optarg);
elem_cnt_max_chgd = 1; break;
case IDX_WL_DIST_LEN: wl_dist_len = 1; break;
case IDX_CASE_PERMUTE: case_permute = 1; break;
case IDX_DUPE_CHECK_DISABLE: dupe_check = 0; break;
case IDX_SAVE_POS_DISABLE: save_pos = 0; break;
case IDX_SKIP: mpz_set_str (skip, optarg, 0); break;
case IDX_LIMIT: mpz_set_str (limit, optarg, 0); break;
case IDX_OUTPUT_FILE: output_file = optarg; break;

default: return (-1);
}
Expand Down Expand Up @@ -889,6 +914,16 @@ int main (int argc, char *argv[])
}
}


/*
* catch signal user interrupt
*/

if (save_pos)
{
signal (SIGINT, catch_int);
}

/**
* load elems from stdin
*/
Expand Down Expand Up @@ -1180,6 +1215,8 @@ int main (int argc, char *argv[])
mpz_set (total_ks_cnt, tmp);
}

mpz_init_set (save, skip);

/**
* skip to the first main loop that will output a password
*/
Expand Down Expand Up @@ -1357,6 +1394,8 @@ int main (int argc, char *argv[])

chain_set_pwbuf_init (chain_buf, db_entries, db_entry->cur_chain_ks_poses, pw_buf);

const u64 iter_pos_save = iter_max_u64 - iter_pos_u64;

while (iter_pos_u64 < iter_max_u64)
{
out_push (out, pw_buf, pw_len + 1);
Expand All @@ -1365,6 +1404,8 @@ int main (int argc, char *argv[])

iter_pos_u64++;
}

mpz_add_ui (save, save, iter_pos_save);
}
else
{
Expand Down Expand Up @@ -1395,6 +1436,11 @@ int main (int argc, char *argv[])

out_flush (out);

if (save_pos)
{
catch_int ();
}

/**
* cleanup
*/
Expand All @@ -1406,6 +1452,7 @@ int main (int argc, char *argv[])
mpz_clear (skip);
mpz_clear (limit);
mpz_clear (tmp);
mpz_clear (save);

for (int pw_len = pw_min; pw_len <= pw_max; pw_len++)
{
Expand Down

0 comments on commit f662d8d

Please sign in to comment.