From 7f91924acf21a011de6d6fcc33f6ad4b86cb3c68 Mon Sep 17 00:00:00 2001
From: magnum <magnum>
Date: Sat, 24 Sep 2011 17:53:15 +0200
Subject: [PATCH] j7: Fix "john -enc:list" again after 0004 broke it rev 2

---
 src/options.c |    6 ++++++
 src/unicode.c |   31 ++++++++++++++++++-------------
 src/unicode.h |    1 +
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/options.c b/src/options.c
index 11469af..71cdf8e 100644
--- a/src/options.c
+++ b/src/options.c
@@ -21,6 +21,7 @@
 #include "options.h"
 #include "bench.h"
 #include "md5_gen.h"
+#include "unicode.h"
 #ifdef HAVE_MPI
 #include "john-mpi.h"
 #ifdef _OPENMP
@@ -328,6 +329,11 @@ void opt_init(char *name, int argc, char **argv)
 
 	if (options.flags & FLG_STDOUT) options.flags &= ~FLG_PWD_REQ;
 
+	if (options.encoding && !strcasecmp(options.encoding, "list")) {
+		listEncodings();
+		exit(0);
+	}
+
 	if ((options.flags & (FLG_PASSWD | FLG_PWD_REQ)) == FLG_PWD_REQ) {
 #ifdef HAVE_MPI
 		if (mpi_id == 0)
diff --git a/src/unicode.c b/src/unicode.c
index 315bb83..32fef1b 100644
--- a/src/unicode.c
+++ b/src/unicode.c
@@ -753,6 +753,22 @@ UTF8 *utf16_to_enc_r (UTF8 *dst, int dst_len, const UTF16 *source) {
 	return dst;
 }
 
+void listEncodings(void) {
+	fprintf(stderr, "Supported encodings within john are:\nutf-8, iso-8859-1 (or ansi)"
+	        ", iso-8859-7"
+	        ", iso-8859-15"
+	        ", koi8-r"
+	        ",\ncp437"
+	        ", cp737"
+	        ", cp850"
+	        ", cp858"
+	        ", cp866"
+	        ", cp1251"
+	        ", cp1252"
+	        ", cp1253"
+	        "\n");
+}
+
 /* Load the 'case-conversion' tables, and other translation table. */
 int initUnicode(int type) {
 	unsigned i;
@@ -827,19 +843,8 @@ int initUnicode(int type) {
 			options.encodingStr = "CP1253";
 		} else
 		if (strcasecmp(options.encoding, "raw") && strcasecmp(options.encoding, "ascii") && strcasecmp(options.encoding, "default")) {
-			fprintf (stderr, "Supported encodings within john are: raw, utf-8, iso-8859-1 (or ansi)"
-					",\niso-8859-7"
-					", iso-8859-15"
-					", koi8-r"
-					", cp437"
-					", cp737"
-					", cp850"
-					", cp858"
-					", cp866"
-					",\ncp1251"
-					", cp1252"
-					", cp1253"
-					"\n");
+			fprintf (stderr, "Invalid encoding. ");
+			listEncodings();
 			error();
 		}
 	}
diff --git a/src/unicode.h b/src/unicode.h
index 171c8ca..e94b1d5 100644
--- a/src/unicode.h
+++ b/src/unicode.h
@@ -104,6 +104,7 @@ extern int E_md4hash(const UTF8 * passwd, unsigned int len, unsigned char *p16);
 #define UNICODE_MS_NEW	2
 #define UNICODE_UNICODE	3
 
+extern void listEncodings(void);
 extern int initUnicode(int type);
 extern UTF16 ucs2_upcase[0x10000];   /* NOTE, for multi-char converts, we put a 1 into these */
 extern UTF16 ucs2_downcase[0x10000]; /* array. The 1 is not valid, just an indicator to check the multi-char */
-- 
1.7.4.1

