>From 6427e2ef225c0151473fb2d093a56ac6734d3b50 Mon Sep 17 00:00:00 2001 From: Frank Dittrich Date: Mon, 11 Jun 2012 11:08:46 +0200 Subject: [PATCH 1/2] Move markov option handling to mkv.c (do_markov_crack) Doing all parameter validation in one place (mkv.c, do_mkv_crack()) instead of in two places (options.c in opt_init() and in mkv.c in do_mkv_crack()) --- src/john.c | 2 +- src/mkv.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/mkv.h | 2 +- src/options.c | 65 --------------------------------------------------------- src/options.h | 6 ----- 5 files changed, 61 insertions(+), 74 deletions(-) diff --git a/src/john.c b/src/john.c index 64ee6a8..408c12f 100644 --- a/src/john.c +++ b/src/john.c @@ -823,7 +823,7 @@ static void john_run(void) do_incremental_crack(&database, options.charset); else if (options.flags & FLG_MKV_CHK) - do_markov_crack(&database, options.mkv_level, options.mkv_start, options.mkv_end, options.mkv_maxlen, options.mkv_minlevel, options.mkv_minlen); + do_markov_crack(&database, options.mkv_param); else if (options.flags & FLG_EXTERNAL_CHK) do_external_crack(&database); diff --git a/src/mkv.c b/src/mkv.c index f29fac6..ab87da2 100644 --- a/src/mkv.c +++ b/src/mkv.c @@ -238,13 +238,71 @@ static int get_progress(int *hundth_perc) } -void do_markov_crack(struct db_main *db, unsigned int mkv_level, unsigned long long mkv_start, unsigned long long mkv_end, unsigned int mkv_maxlen, unsigned int mkv_minlevel, unsigned int mkv_minlen) +void do_markov_crack(struct db_main *db, char * mkv_param) { char * statfile; + unsigned int mkv_minlevel, mkv_level, mkv_maxlen, mkv_minlen; + unsigned long long mkv_start, mkv_end; #ifdef HAVE_MPI unsigned long long mkv_size; #endif + char * token; + + mkv_level = 0; + mkv_start = 0; + mkv_end = 0; + mkv_maxlen = 0; + mkv_minlevel = 0; + mkv_minlen = 0; + if (mkv_param) + { + token = strtok(mkv_param, ":"); + if(sscanf(token, "%d-%d", &mkv_minlevel, &mkv_level) != 2) + { + mkv_minlevel = 0; + if (sscanf(token, "%d", &mkv_level) != 1) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Could not parse markov parameters\n"); + error(); + } + } + token = strtok(NULL, ":"); + if( (token != NULL) && (sscanf(token, LLd, &mkv_start)==1) ) + { + token = strtok(NULL, ":"); + if( (token != NULL) && (sscanf(token, LLd, &mkv_end)==1) ) + { + token = strtok(NULL, ":"); + if( (token != NULL) && (sscanf(token, "%d-%d", &mkv_minlen, &mkv_maxlen)!=2) ) + { + mkv_minlen = 0; + sscanf(token, "%d", &mkv_maxlen); + } + } + } + } + if(mkv_level mkv_maxlen) + { +#ifdef HAVE_MPI + if (mpi_id == 0) +#endif + fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", mkv_minlen, mkv_maxlen, mkv_maxlen); + mkv_minlen = mkv_maxlen; + } + + if(mkv_level == 0) if( (mkv_level = cfg_get_int("Options", SUBSECTION_MARKOV, "MkvLvl")) == -1 ) { diff --git a/src/mkv.h b/src/mkv.h index 0913eed..fd998b1 100644 --- a/src/mkv.h +++ b/src/mkv.h @@ -12,6 +12,6 @@ /* * Runs the markov mode cracker. */ -extern void do_markov_crack(struct db_main *db, unsigned int mkv_level, unsigned long long mkv_start, unsigned long long mkv_end, unsigned int mkv_maxlen, unsigned int mkv_minlevel, unsigned int mkv_minlen); +extern void do_markov_crack(struct db_main *db, char *mkv_param); #endif diff --git a/src/options.c b/src/options.c index a1ed020..04d6a76 100644 --- a/src/options.c +++ b/src/options.c @@ -48,15 +48,6 @@ extern int gpu_id; struct options_main options; static char *field_sep_char_string; -#if defined (__MINGW32__) || defined (_MSC_VER) -// Later versions of MSVC can handle %lld but some older -// ones can only handle %I64d. Easiest to simply use -// %I64d then all versions of MSVC will handle it just fine -#define LLd "%I64d" -#else -#define LLd "%lld" -#endif - static struct opt_entry opt_list[] = { {"", FLG_PASSWD, 0, 0, 0, OPT_FMT_ADD_LIST, &options.passwd}, {"single", FLG_SINGLE_SET, FLG_CRACKING_CHK, 0, 0, @@ -425,62 +416,6 @@ void opt_init(char *name, int argc, char **argv) error(); } - if (options.flags & FLG_MKV_CHK) { - char * token; - - options.mkv_start = 0; - options.mkv_end = 0; - options.mkv_maxlen = 0; - options.mkv_minlevel = 0; - options.mkv_minlen = 0; - if (options.mkv_param) - { - token = strtok(options.mkv_param, ":"); - if(sscanf(token, "%d-%d", &options.mkv_minlevel, &options.mkv_level) != 2) - { - options.mkv_minlevel = 0; - if (sscanf(token, "%d", &options.mkv_level) != 1) - { -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, "Could not parse markov parameters\n"); - error(); - } - } - token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, LLd, &options.mkv_start)==1) ) - { - token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, LLd, &options.mkv_end)==1) ) - { - token = strtok(NULL, ":"); - if( (token != NULL) && (sscanf(token, "%d-%d", &options.mkv_minlen, &options.mkv_maxlen)!=2) ) - { - options.mkv_minlen = 0; - sscanf(token, "%d", &options.mkv_maxlen); - } - } - } - } - if(options.mkv_level options.mkv_maxlen) - { -#ifdef HAVE_MPI - if (mpi_id == 0) -#endif - fprintf(stderr, "Warning: minimum length(%d) < maximum length(%d), minimum length set to %d\n", options.mkv_minlen, options.mkv_maxlen, options.mkv_maxlen); - options.mkv_minlen = options.mkv_maxlen; - } - } - #ifdef HAVE_MPI if (options.flags & (FLG_STDIN_CHK | FLG_SHOW_CHK | FLG_MAKECHR_CHK ) && (mpi_p > 1)) { if (mpi_id == 0) fprintf(stderr, "Chosen mode not suitable for running on multiple nodes\n"); diff --git a/src/options.h b/src/options.h index 4dfc172..931bdcb 100644 --- a/src/options.h +++ b/src/options.h @@ -138,12 +138,6 @@ struct options_main { /* Markov stuff */ char *mkv_param; - unsigned long long mkv_start; - unsigned long long mkv_end; - unsigned int mkv_level; - unsigned int mkv_maxlen; - unsigned int mkv_minlevel; - unsigned int mkv_minlen; /* Maximum plaintext length for stdout mode */ int length; -- 1.7.7.6