Skip to content

Commit c030024

Browse files
committed
jtrts: added -internal mode. Fixed issue where dynamic_n was a valid type
1 parent 21be576 commit c030024

File tree

3 files changed

+91
-4
lines changed

3 files changed

+91
-4
lines changed

JtrTestSuite.Manifest

+5-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@
155155
# made -no-prelims the default, so now if you WANT prelims, you have to use -prelims
156156
# v1.12.18 (oct 31, 2014) Return from script will not be 0 if there are any failures. It will be number
157157
# number of failed test, or tests which jtr returned non-zero.
158-
# Todo (1.13)
158+
#
159+
# v1.13 (dec 18, 2014) added -internal test mode, to test 'test' strings from inside formats.
160+
# This allows testing formats which do not yet have test suite input files.
161+
# Did a 'major' version, since this is fully new behavior.
162+
# Todo (1.14)
159163
# Add tests for -pipe, files with \r\n \n \r and \r\r\n, which are 'real'
160164
# file formats seen in the wild. These tests are in -w= and -pipe modes
161165
# http://www.openwall.com/lists/john-dev/2012/06/29/39

jtrts.pl

+82-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use jtrts_inc;
55
use Digest::MD5;
66

7-
my $VERSION = "1.12.18";
8-
my $RELEASE_DATE = "Oct 31, 2014";
7+
my $VERSION = "1.13";
8+
my $RELEASE_DATE = "Dec 21, 2014";
99
# how to do alpha character left, so next 'alpha', or beta release will be easy.
1010
#use utf8;
1111
#my $VERSION = "1.10-\x{3B1}2"; # alpha-2
@@ -33,7 +33,7 @@
3333
my @validFormats=();
3434
my @tstdata;
3535
my $showtypes=0, my $basepath=""; my $prelims=0, my $stop_on_error=0, my $show_stderr=0;
36-
my $last_line_len=0;
36+
my $last_line_len=0; my $internal_testing;
3737
my $error_cnt = 0, my $error_cnt_pot = 0; my $done_cnt = 0; my $ret_val_non_zero_cnt = 0;
3838
my @startingTime;
3939

@@ -47,6 +47,7 @@
4747
readData();
4848
if ($showtypes) { showTypeData(); exit 0; }
4949
johnPrelims();
50+
if ($internal_testing) { doInternalMode(); }
5051
filterPatterns();
5152
process();
5253
cleanup();
@@ -97,6 +98,7 @@ sub parseArgs {
9798
'passthru=s' => \@passthru,
9899
'stoponerror!' => \$stop_on_error,
99100
'showstderr!' => \$show_stderr,
101+
'internal!' => \$internal_testing,
100102
);
101103
if ($basepath ne "") {
102104
$JOHN_PATH = $basepath;
@@ -371,6 +373,9 @@ sub loadAllValidFormatTypeStrings {
371373
# Make all format labels listed from JtR lower case.
372374
$fmt_str = lc($fmt_str);
373375

376+
# removed dynamic_n IF it exists
377+
$fmt_str =~ s/\/dynamic_n//g;
378+
374379
# Ok, now if we have 'dynamic's, LOAD them
375380
if (grepUsage("--list=WHAT") || grepUsage("--subformat=LIST")) {
376381
if (grepUsage("--list=WHAT")) {
@@ -592,6 +597,18 @@ sub process {
592597
my $dict_name_ex = "";
593598
my $dict_name = "";
594599
my $line = "";
600+
601+
#my $k = 0;
602+
#foreach my $l(@tstdata) {
603+
# my @ar = split(',', $l);
604+
# print "line=$l\n";
605+
# my $i = 0;
606+
# foreach my $e(@ar) {
607+
# print "ar[$i] = $e\n";
608+
# $i += 1;
609+
# }
610+
# exit(0);
611+
#}
595612

596613
LINE: foreach my $line(@tstdata) {
597614
my @ar = split(',', $line);
@@ -820,4 +837,66 @@ sub cleanup {
820837
unlink ("tst.pot");
821838
unlink ("tst.log");
822839
unlink ("tst.ses");
840+
unlink ("selftest.dic");
841+
unlink ("selftest.in");
842+
}
843+
844+
###############################################################################
845+
# Internal mode. This will generate a file from the format itself
846+
# using:
847+
# john -format=$fmt -list=format-tests | cut -f3 > selftest.in
848+
# john -format=$fmt -list=format-tests | cut -f4 > selftest.dic
849+
# this function does not return, it cleans up, and exits with proper errorlevel.
850+
###############################################################################
851+
sub doInternalMode {
852+
if (grepUsage("--pot=NAME")) {
853+
# we are OK, we run only on jumbo mode.
854+
} else {
855+
ScreenOut("John CORE build detected.\n The -internal mode ONLY works for jumbo build of john.\n");
856+
exit 1;
857+
}
858+
ScreenOutSemi("Running JTRTS in -internal mode\n");
859+
ScreenOutVV("\@validFormats\n");
860+
ScreenOutVV(@validFormats);
861+
ScreenOutVV("\n\n\@types (before fixups)\n");
862+
ScreenOutVV(@types);
863+
if (scalar @types == 3 && $types[0] eq "base" && $types[1] eq "koi8r" && $types[2] eq "utf8") {
864+
@types = @validFormats;
865+
}
866+
# handle finding 'classes' here, such as $types[x] == "dynamic", then find all dynamic
867+
# also handle other wildcard stuff.
868+
869+
ScreenOutVV("\n\n\@types (after fixups)\n");
870+
ScreenOutVV(@types);
871+
ScreenOutVV("\n\n\@nontypes\n");
872+
ScreenOutVV(@nontypes);
873+
874+
# now process the internal stuff.
875+
foreach my $type (@types) {
876+
my $fnd = 0;
877+
foreach my $nontype (@nontypes) {
878+
my $s = $type;
879+
if ($s =~ m/$nontype/) {
880+
$fnd = 1;
881+
}
882+
}
883+
if ($fnd == 0) {
884+
# first, build our dictionary
885+
my $cmd = "$JOHN_EXE -format=$type -list=format-tests 2>&1 | cut -f 4 > selftest.dic";
886+
$cmd = `$cmd`;
887+
# Now build the input file
888+
$cmd = "$JOHN_EXE -format=$type -list=format-tests 2>&1 | cut -f3 > selftest.in";
889+
$cmd = `$cmd`;
890+
my $cnt = `wc -l selftest.in | awk \'{print \$1}\'`;
891+
chomp $cnt;
892+
# build the @tstdata array with 1 element
893+
@tstdata = ("($type),(X),(jumbo),10000,$type,selftest,selftest.in,$type,Y,X,($cnt)(-show$cnt),($cnt)");
894+
ScreenOutVV("Preparing to run internal for type: $type\n");
895+
process();
896+
}
897+
}
898+
899+
cleanup();
900+
displaySummary();
901+
exit $error_cnt+$error_cnt_pot+$ret_val_non_zero_cnt;
823902
}

jtrts_inc.pm

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ usage: $0 [-h|-?] [-option[s]]
5757
-test=0 and tests of any 'requested' encodings is performed.
5858
-no-prelims Do not perform this prelim work. -no-prelim is default.
5959
-passthru <s> Pass this argument straight into john. Can use more than 1.
60+
-internal A special mode, that tests JtR -list-format-tests data
61+
from a john jumbo build. This allows doing 'some' testing
62+
on formats not yet in the TS, by using the internal test
63+
strings from the format itself.
6064
-stoponerror Causes JtRts to stop if any error is seen. The .pot file
6165
and other temp files will be left, AND the command line
6266
that was run is listed. (default is -nostoponerror).

0 commit comments

Comments
 (0)