35
35
#define UNICODE
36
36
#define _UNICODE
37
37
38
+ #ifdef _MSC_VER
39
+ char * stpcpy (char * dst , const char * src ) {
40
+ strcpy (dst , src );
41
+ return dst + strlen (dst );
42
+ }
43
+ #endif
44
+
38
45
char * rexgen_alphabets [256 ];
46
+ static c_iterator_ptr iter = NULL ;
47
+ static c_regex_ptr regex_ptr = NULL ;
48
+ static char * save_str ;
49
+ static const char * cur_regex , * save_regex ;
50
+ static char * restore_str , * restore_regex ;
51
+ static int save_str_len ;
39
52
40
53
static void fix_state (void )
41
54
{
@@ -50,6 +63,52 @@ static void save_state(FILE *file)
50
63
{
51
64
}
52
65
66
+ int rexgen_restore_state_hybrid (const char * sig , FILE * file )
67
+ {
68
+ if (!strncmp (sig , "rex-v1" , 6 ))
69
+ {
70
+ int len , ret ;
71
+ ret = fscanf (file , "%d\n" , & len );
72
+ if (ret != 1 ) return 1 ;
73
+ restore_regex = mem_alloc_tiny (len + 2 , 8 );
74
+ fgetl (restore_regex , len + 1 , file );
75
+ ret = fscanf (file , "%d\n" , & len );
76
+ if (ret != 1 ) return 1 ;
77
+ restore_str = mem_alloc_tiny (len + 2 , 8 );
78
+ fgetl (restore_str , len + 1 , file );
79
+ log_event ("resuming a regex expr or %s and state of %s\n" , restore_regex , restore_str );
80
+ return 0 ;
81
+ }
82
+ return 1 ;
83
+ }
84
+
85
+ static void save_state_hybrid (FILE * file )
86
+ {
87
+ if (save_str && strlen (save_str )) {
88
+ fprintf (file , "rex-v1\n" );
89
+ fprintf (file , "%d\n" , (int )strlen (save_regex ));
90
+ fprintf (file , "%s\n" , save_regex );
91
+ fprintf (file , "%d\n" , (int )strlen (save_str ));
92
+ fprintf (file , "%s\n" , save_str );
93
+ }
94
+ }
95
+
96
+ static void rex_hybrid_fix_state ()
97
+ {
98
+ char * dstptr = 0 ;
99
+ if (iter )
100
+ c_iterator_get_state (iter , & dstptr );
101
+ if (dstptr ) {
102
+ if (strlen (dstptr ) > save_str_len ) {
103
+ save_str_len = strlen (dstptr )+ 256 ;
104
+ MEM_FREE (save_str );
105
+ save_str = mem_alloc (save_str_len + 1 );
106
+ }
107
+ strcpy (save_str , dstptr );
108
+ save_regex = cur_regex ;
109
+ }
110
+ }
111
+
53
112
static int restore_state (FILE * file )
54
113
{
55
114
return 0 ;
@@ -76,6 +135,7 @@ static void rexgen_setlocale()
76
135
}
77
136
}
78
137
138
+ // Would be nice to have SOME way to be thread safe!!!
79
139
static char BaseWord [1024 ];
80
140
81
141
size_t callback (char * dst , const size_t buffer_size )
@@ -134,24 +194,39 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex,
134
194
const char * base_word , int regex_case , const char * regex_alpha )
135
195
{
136
196
c_simplestring_ptr buffer = c_simplestring_new ();
137
- c_iterator_ptr iter = NULL ;
138
- c_regex_ptr regex_ptr = NULL ;
139
197
char word [PLAINTEXT_BUFFER_SIZE ];
140
198
static int bFirst = 1 ;
141
199
static int bALPHA = 0 ;
142
200
int max_len = db -> format -> params .plaintext_length ;
143
201
int retval ;
144
202
203
+ cur_regex = regex ;
145
204
if (options .req_maxlength )
146
205
max_len = options .req_maxlength ;
147
206
207
+ strcpy (BaseWord , base_word );
148
208
if (bFirst ) {
149
209
bFirst = 0 ;
150
210
rexgen_setlocale ();
151
211
if (regex_alpha && !strncmp (regex_alpha , "alpha" , 5 )) {
152
212
bALPHA = 1 ;
153
213
SetupAlpha (regex_alpha );
154
214
}
215
+ rec_init_hybrid (save_state_hybrid );
216
+ crk_set_hybrid_fix_state_func_ptr (rex_hybrid_fix_state );
217
+
218
+ regex_ptr = c_regex_cb (regex , callback );
219
+ if (!regex_ptr ) {
220
+ c_simplestring_delete (buffer );
221
+ fprintf (stderr ,
222
+ "Error, invalid regex expression. John exiting now base_word=%s Regex= %s\n" ,
223
+ base_word , regex );
224
+ error ();
225
+ }
226
+ iter = c_regex_iterator (regex_ptr );
227
+
228
+ if (restore_str )
229
+ c_iterator_set_state (iter , restore_str );
155
230
}
156
231
157
232
if (bALPHA ) {
@@ -190,7 +265,6 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex,
190
265
}
191
266
}
192
267
193
- strcpy (BaseWord , base_word );
194
268
if (!regex [0 ]) {
195
269
if (options .mask ) {
196
270
if (do_mask_crack (fmt_null_key )) {
@@ -208,15 +282,6 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex,
208
282
goto out ;
209
283
}
210
284
211
- regex_ptr = c_regex_cb (regex , callback );
212
- if (!regex_ptr ) {
213
- c_simplestring_delete (buffer );
214
- fprintf (stderr ,
215
- "Error, invalid regex expression. John exiting now base_word=%s Regex= %s\n" ,
216
- base_word , regex );
217
- error ();
218
- }
219
- iter = c_regex_iterator (regex_ptr );
220
285
while (c_iterator_next (iter )) {
221
286
c_iterator_value (iter , buffer );
222
287
c_simplestring_to_utf8_string (buffer , & word [0 ], sizeof (word ));
@@ -240,38 +305,37 @@ int do_regex_hybrid_crack(struct db_main *db, const char *regex,
240
305
241
306
out :
242
307
c_simplestring_delete (buffer );
243
- c_regex_delete (regex_ptr );
244
- c_iterator_delete (iter );
245
308
return retval ;
246
309
}
247
310
248
311
void do_regex_crack (struct db_main * db , const char * regex )
249
312
{
250
313
c_simplestring_ptr buffer = c_simplestring_new ();
251
- c_iterator_ptr iter = NULL ;
252
- c_regex_ptr regex_ptr = NULL ;
253
314
char word [PLAINTEXT_BUFFER_SIZE ];
254
315
int max_len = db -> format -> params .plaintext_length ;
255
316
256
317
if (options .req_maxlength )
257
318
max_len = options .req_maxlength ;
258
319
259
- if (john_main_process )
260
- fprintf (stderr , "Warning: regex mode currently can't be "
261
- "resumed if aborted\n" );
262
-
320
+ cur_regex = regex ;
263
321
rexgen_setlocale ();
264
322
status_init (& get_progress , 0 );
265
323
rec_restore_mode (restore_state );
266
324
rec_init (db , save_state );
267
325
crk_init (db , fix_state , NULL );
326
+ rec_init_hybrid (save_state_hybrid );
327
+
268
328
regex_ptr = c_regex_cb (regex , callback );
269
329
if (!regex_ptr ) {
270
330
fprintf (stderr ,
271
331
"Error, invalid regex expression. John exiting now\n" );
272
332
error ();
273
333
}
274
334
iter = c_regex_iterator (regex_ptr );
335
+ if (restore_str ) {
336
+ c_iterator_set_state (iter , restore_str );
337
+ restore_str = 0 ;
338
+ }
275
339
while (c_iterator_next (iter )) {
276
340
c_iterator_value (iter , buffer );
277
341
c_simplestring_to_utf8_string (buffer , & word [0 ], sizeof (word ));
0 commit comments