1 /**
2 * Author......: See docs/credits.txt
3 * License.....: MIT
4 */
5
6 #include "common.h"
7 #include "types.h"
8 #include "memory.h"
9 #include "convert.h"
10 #include "thread.h"
11 #include "timer.h"
12 #include "hashes.h"
13 #include "hwmon.h"
14 #include "outfile.h"
15 #include "monitor.h"
16 #include "mpsp.h"
17 #include "terminal.h"
18 #include "shared.h"
19 #include "status.h"
20
21 static const char *const ST_0000 = "Initializing";
22 static const char *const ST_0001 = "Autotuning";
23 static const char *const ST_0002 = "Selftest";
24 static const char *const ST_0003 = "Running";
25 static const char *const ST_0004 = "Paused";
26 static const char *const ST_0005 = "Exhausted";
27 static const char *const ST_0006 = "Cracked";
28 static const char *const ST_0007 = "Aborted";
29 static const char *const ST_0008 = "Quit";
30 static const char *const ST_0009 = "Bypass";
31 static const char *const ST_0010 = "Aborted (Checkpoint)";
32 static const char *const ST_0011 = "Aborted (Runtime)";
33 static const char *const ST_0012 = "Running (Checkpoint Quit requested)";
34 static const char *const ST_0013 = "Error";
35 static const char *const ST_0014 = "Aborted (Finish)";
36 static const char *const ST_0015 = "Running (Quit after attack requested)";
37 static const char *const ST_0016 = "Autodetect";
38 static const char *const ST_9999 = "Unknown! Bug!";
39
40 static const char UNITS[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' };
41
42 static const char *const ETA_ABSOLUTE_MAX_EXCEEDED = "Next Big Bang"; // in honor of ighashgpu
43 static const char *const ETA_RELATIVE_MAX_EXCEEDED = "> 10 years";
44
status_get_rules_file(const hashcat_ctx_t * hashcat_ctx)45 static char *status_get_rules_file (const hashcat_ctx_t *hashcat_ctx)
46 {
47 const user_options_t *user_options = hashcat_ctx->user_options;
48
49 if (user_options->rp_files_cnt > 0)
50 {
51 char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_TINY);
52
53 int tmp_len = 0;
54
55 u32 i;
56
57 for (i = 0; i < user_options->rp_files_cnt - 1; i++)
58 {
59 tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len, "%s, ", user_options->rp_files[i]);
60 }
61
62 tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len, "%s", user_options->rp_files[i]);
63
64 tmp_buf[tmp_len] = 0;
65
66 return tmp_buf; // yes, user need to free()
67 }
68
69 return NULL;
70 }
71
format_timer_display(struct tm * tm,char * buf,size_t len)72 void format_timer_display (struct tm *tm, char *buf, size_t len)
73 {
74 const char *const time_entities_s[] = { "year", "day", "hour", "min", "sec" };
75 const char *const time_entities_m[] = { "years", "days", "hours", "mins", "secs" };
76
77 if (tm->tm_year - 70)
78 {
79 const char *time_entity1 = ((tm->tm_year - 70) == 1) ? time_entities_s[0] : time_entities_m[0];
80 const char *time_entity2 = ( tm->tm_yday == 1) ? time_entities_s[1] : time_entities_m[1];
81
82 snprintf (buf, len, "%d %s, %d %s", tm->tm_year - 70, time_entity1, tm->tm_yday, time_entity2);
83 }
84 else if (tm->tm_yday)
85 {
86 const char *time_entity1 = (tm->tm_yday == 1) ? time_entities_s[1] : time_entities_m[1];
87 const char *time_entity2 = (tm->tm_hour == 1) ? time_entities_s[2] : time_entities_m[2];
88
89 snprintf (buf, len, "%d %s, %d %s", tm->tm_yday, time_entity1, tm->tm_hour, time_entity2);
90 }
91 else if (tm->tm_hour)
92 {
93 const char *time_entity1 = (tm->tm_hour == 1) ? time_entities_s[2] : time_entities_m[2];
94 const char *time_entity2 = (tm->tm_min == 1) ? time_entities_s[3] : time_entities_m[3];
95
96 snprintf (buf, len, "%d %s, %d %s", tm->tm_hour, time_entity1, tm->tm_min, time_entity2);
97 }
98 else if (tm->tm_min)
99 {
100 const char *time_entity1 = (tm->tm_min == 1) ? time_entities_s[3] : time_entities_m[3];
101 const char *time_entity2 = (tm->tm_sec == 1) ? time_entities_s[4] : time_entities_m[4];
102
103 snprintf (buf, len, "%d %s, %d %s", tm->tm_min, time_entity1, tm->tm_sec, time_entity2);
104 }
105 else
106 {
107 const char *time_entity1 = (tm->tm_sec == 1) ? time_entities_s[4] : time_entities_m[4];
108
109 snprintf (buf, len, "%d %s", tm->tm_sec, time_entity1);
110 }
111 }
112
format_speed_display(double val,char * buf,size_t len)113 void format_speed_display (double val, char *buf, size_t len)
114 {
115 if (val <= 0)
116 {
117 buf[0] = '0';
118 buf[1] = ' ';
119 buf[2] = 0;
120
121 return;
122 }
123
124 u32 level = 0;
125
126 while (val > 99999)
127 {
128 val /= 1000;
129
130 level++;
131 }
132
133 /* generate output */
134
135 if (level == 0)
136 {
137 snprintf (buf, len, "%.0f ", val);
138 }
139 else
140 {
141 snprintf (buf, len, "%.1f %c", val, UNITS[level]);
142 }
143 }
144
format_speed_display_1k(double val,char * buf,size_t len)145 void format_speed_display_1k (double val, char *buf, size_t len)
146 {
147 if (val <= 0)
148 {
149 buf[0] = '0';
150 buf[1] = ' ';
151 buf[2] = 0;
152
153 return;
154 }
155
156 u32 level = 0;
157
158 while (val > 999)
159 {
160 val /= 1000;
161
162 level++;
163 }
164
165 /* generate output */
166
167 if (level == 0)
168 {
169 snprintf (buf, len, "%.0f ", val);
170 }
171 else
172 {
173 snprintf (buf, len, "%.1f %c", val, UNITS[level]);
174 }
175 }
176
get_avg_exec_time(hc_device_param_t * device_param,const int last_num_entries)177 double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries)
178 {
179 int exec_pos = (int) device_param->exec_pos - last_num_entries;
180
181 if (exec_pos < 0) exec_pos += EXEC_CACHE;
182
183 double exec_msec_sum = 0;
184
185 int exec_msec_cnt = 0;
186
187 for (int i = 0; i < last_num_entries; i++)
188 {
189 double exec_msec = device_param->exec_msec[(exec_pos + i) % EXEC_CACHE];
190
191 if (exec_msec > 0)
192 {
193 exec_msec_sum += exec_msec;
194
195 exec_msec_cnt++;
196 }
197 }
198
199 if (exec_msec_cnt == 0) return 0;
200
201 return exec_msec_sum / exec_msec_cnt;
202 }
203
status_get_device_info_cnt(const hashcat_ctx_t * hashcat_ctx)204 int status_get_device_info_cnt (const hashcat_ctx_t *hashcat_ctx)
205 {
206 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
207
208 return backend_ctx->backend_devices_cnt;
209 }
210
status_get_device_info_active(const hashcat_ctx_t * hashcat_ctx)211 int status_get_device_info_active (const hashcat_ctx_t *hashcat_ctx)
212 {
213 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
214
215 return backend_ctx->backend_devices_active;
216 }
217
status_get_skipped_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)218 bool status_get_skipped_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
219 {
220 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
221
222 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
223
224 return device_param->skipped;
225 }
226
status_get_skipped_warning_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)227 bool status_get_skipped_warning_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
228 {
229 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
230
231 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
232
233 return device_param->skipped_warning;
234 }
235
status_get_session(const hashcat_ctx_t * hashcat_ctx)236 char *status_get_session (const hashcat_ctx_t *hashcat_ctx)
237 {
238 const user_options_t *user_options = hashcat_ctx->user_options;
239
240 return strdup (user_options->session);
241 }
242
243 #ifdef WITH_BRAIN
status_get_brain_session(const hashcat_ctx_t * hashcat_ctx)244 int status_get_brain_session (const hashcat_ctx_t *hashcat_ctx)
245 {
246 const user_options_t *user_options = hashcat_ctx->user_options;
247
248 return user_options->brain_session;
249 }
250
status_get_brain_attack(const hashcat_ctx_t * hashcat_ctx)251 int status_get_brain_attack (const hashcat_ctx_t *hashcat_ctx)
252 {
253 const user_options_t *user_options = hashcat_ctx->user_options;
254
255 return user_options->brain_attack;
256 }
257 #endif
258
status_get_status_string(const hashcat_ctx_t * hashcat_ctx)259 const char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx)
260 {
261 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
262
263 const int devices_status = status_ctx->devices_status;
264
265 // special case: running but checkpoint quit requested
266
267 if (devices_status == STATUS_RUNNING)
268 {
269 if (status_ctx->checkpoint_shutdown == true)
270 {
271 return ST_0012;
272 }
273
274 if (status_ctx->finish_shutdown == true)
275 {
276 return ST_0015;
277 }
278 }
279
280 switch (devices_status)
281 {
282 case STATUS_INIT: return ST_0000;
283 case STATUS_AUTOTUNE: return ST_0001;
284 case STATUS_SELFTEST: return ST_0002;
285 case STATUS_RUNNING: return ST_0003;
286 case STATUS_PAUSED: return ST_0004;
287 case STATUS_EXHAUSTED: return ST_0005;
288 case STATUS_CRACKED: return ST_0006;
289 case STATUS_ABORTED: return ST_0007;
290 case STATUS_QUIT: return ST_0008;
291 case STATUS_BYPASS: return ST_0009;
292 case STATUS_ABORTED_CHECKPOINT: return ST_0010;
293 case STATUS_ABORTED_RUNTIME: return ST_0011;
294 case STATUS_ERROR: return ST_0013;
295 case STATUS_ABORTED_FINISH: return ST_0014;
296 case STATUS_AUTODETECT: return ST_0016;
297 }
298
299 return ST_9999;
300 }
301
status_get_status_number(const hashcat_ctx_t * hashcat_ctx)302 int status_get_status_number (const hashcat_ctx_t *hashcat_ctx)
303 {
304 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
305
306 return status_ctx->devices_status;
307 }
308
status_get_hash_name(const hashcat_ctx_t * hashcat_ctx)309 char *status_get_hash_name (const hashcat_ctx_t *hashcat_ctx)
310 {
311 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
312
313 return hcstrdup (hashconfig->hash_name);
314 }
315
status_get_hash_target(const hashcat_ctx_t * hashcat_ctx)316 char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx)
317 {
318 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
319 const hashes_t *hashes = hashcat_ctx->hashes;
320 const module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
321
322 if ((hashes->digests_cnt == 1) || (hashes->hashfile == NULL))
323 {
324 if (module_ctx->module_hash_encode_status != MODULE_DEFAULT)
325 {
326 char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
327
328 const int tmp_len = module_ctx->module_hash_encode_status (hashconfig, hashes->digests_buf, hashes->salts_buf, hashes->esalts_buf, hashes->hook_salts_buf, NULL, tmp_buf, HCBUFSIZ_LARGE);
329
330 char *tmp_buf2 = (char *) hcmalloc (tmp_len + 1);
331
332 memcpy (tmp_buf2, tmp_buf, tmp_len);
333
334 tmp_buf2[tmp_len] = 0;
335
336 hcfree (tmp_buf);
337
338 return tmp_buf2;
339 }
340
341 if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE)
342 {
343 if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE_OPTIONAL)
344 {
345 if (hashes->hashfile)
346 {
347 return hcstrdup (hashes->hashfile);
348 }
349 }
350 else
351 {
352 return hcstrdup (hashes->hashfile);
353 }
354 }
355
356 char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
357
358 const int tmp_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0);
359
360 tmp_buf[tmp_len] = 0;
361
362 compress_terminal_line_length (tmp_buf, 19, 6); // 19 = strlen ("Hash.Target......: ")
363
364 char *tmp_buf2 = strdup (tmp_buf);
365
366 hcfree (tmp_buf);
367
368 return tmp_buf2;
369 }
370
371 return hcstrdup (hashes->hashfile);
372 }
373
status_get_guess_mode(const hashcat_ctx_t * hashcat_ctx)374 int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx)
375 {
376 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
377 const user_options_t *user_options = hashcat_ctx->user_options;
378 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
379
380 bool has_wordlist = false;
381 bool has_rule_file = false;
382 bool has_rule_gen = false;
383 bool has_base_left = false;
384 bool has_mask_cs = false;
385
386 if (user_options_extra->wordlist_mode == WL_MODE_FILE) has_wordlist = true;
387
388 if (user_options->rp_files_cnt > 0) has_rule_file = true;
389 if (user_options->rp_gen > 0) has_rule_gen = true;
390
391 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT) has_base_left = true;
392
393 if (user_options->custom_charset_1) has_mask_cs = true;
394 if (user_options->custom_charset_2) has_mask_cs = true;
395 if (user_options->custom_charset_3) has_mask_cs = true;
396 if (user_options->custom_charset_4) has_mask_cs = true;
397
398 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
399 {
400 if (has_wordlist == true)
401 {
402 if (has_rule_file == true)
403 {
404 return GUESS_MODE_STRAIGHT_FILE_RULES_FILE;
405 }
406 if (has_rule_gen == true)
407 {
408 return GUESS_MODE_STRAIGHT_FILE_RULES_GEN;
409 }
410 return GUESS_MODE_STRAIGHT_FILE;
411 }
412 if (has_rule_file == true)
413 {
414 return GUESS_MODE_STRAIGHT_STDIN_RULES_FILE;
415 }
416 if (has_rule_gen == true)
417 {
418 return GUESS_MODE_STRAIGHT_STDIN_RULES_GEN;
419 }
420 return GUESS_MODE_STRAIGHT_STDIN;
421 }
422
423 if (user_options->attack_mode == ATTACK_MODE_COMBI)
424 {
425 if (has_base_left == true)
426 {
427 return GUESS_MODE_COMBINATOR_BASE_LEFT;
428 }
429 return GUESS_MODE_COMBINATOR_BASE_RIGHT;
430 }
431
432 if (user_options->attack_mode == ATTACK_MODE_BF)
433 {
434 if (has_mask_cs == true)
435 {
436 return GUESS_MODE_MASK_CS;
437 }
438 return GUESS_MODE_MASK;
439 }
440
441 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
442 {
443 if (has_mask_cs == true)
444 {
445 return GUESS_MODE_HYBRID1_CS;
446 }
447 return GUESS_MODE_HYBRID1;
448 }
449
450 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
451 {
452 if (has_mask_cs == true)
453 {
454 return GUESS_MODE_HYBRID2_CS;
455 }
456 return GUESS_MODE_HYBRID2;
457 }
458
459 return GUESS_MODE_NONE;
460 }
461
status_get_guess_base(const hashcat_ctx_t * hashcat_ctx)462 char *status_get_guess_base (const hashcat_ctx_t *hashcat_ctx)
463 {
464 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
465 const user_options_t *user_options = hashcat_ctx->user_options;
466 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
467
468 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
469 {
470 if (user_options_extra->wordlist_mode == WL_MODE_FILE)
471 {
472 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
473
474 return strdup (straight_ctx->dict);
475 }
476 }
477
478 if (user_options->attack_mode == ATTACK_MODE_COMBI)
479 {
480 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
481
482 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
483 {
484 return strdup (combinator_ctx->dict1);
485 }
486 return strdup (combinator_ctx->dict2);
487 }
488
489 if (user_options->attack_mode == ATTACK_MODE_BF)
490 {
491 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
492
493 return strdup (mask_ctx->mask);
494 }
495
496 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
497 {
498 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
499
500 return strdup (straight_ctx->dict);
501 }
502
503 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
504 {
505 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
506 {
507 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
508
509 return strdup (mask_ctx->mask);
510 }
511
512 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
513
514 return strdup (straight_ctx->dict);
515 }
516 return NULL;
517 }
518
status_get_guess_base_offset(const hashcat_ctx_t * hashcat_ctx)519 int status_get_guess_base_offset (const hashcat_ctx_t *hashcat_ctx)
520 {
521 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
522 const user_options_t *user_options = hashcat_ctx->user_options;
523
524 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
525 {
526 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
527
528 return straight_ctx->dicts_pos + 1;
529 }
530
531 if (user_options->attack_mode == ATTACK_MODE_COMBI)
532 {
533 return 1;
534 }
535
536 if (user_options->attack_mode == ATTACK_MODE_BF)
537 {
538 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
539
540 return mask_ctx->masks_pos + 1;
541 }
542
543 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
544 {
545 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
546
547 return straight_ctx->dicts_pos + 1;
548 }
549
550 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
551 {
552 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
553 {
554 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
555
556 return mask_ctx->masks_pos + 1;
557 }
558
559 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
560
561 return straight_ctx->dicts_pos + 1;
562 }
563
564 return 0;
565 }
566
status_get_guess_base_count(const hashcat_ctx_t * hashcat_ctx)567 int status_get_guess_base_count (const hashcat_ctx_t *hashcat_ctx)
568 {
569 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
570 const user_options_t *user_options = hashcat_ctx->user_options;
571
572 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
573 {
574 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
575
576 return straight_ctx->dicts_cnt;
577 }
578
579 if (user_options->attack_mode == ATTACK_MODE_COMBI)
580 {
581 return 1;
582 }
583
584 if (user_options->attack_mode == ATTACK_MODE_BF)
585 {
586 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
587
588 return mask_ctx->masks_cnt;
589 }
590
591 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
592 {
593 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
594
595 return straight_ctx->dicts_cnt;
596 }
597
598 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
599 {
600 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
601 {
602 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
603
604 return mask_ctx->masks_cnt;
605 }
606
607 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
608
609 return straight_ctx->dicts_cnt;
610 }
611
612 return 0;
613 }
614
status_get_guess_base_percent(const hashcat_ctx_t * hashcat_ctx)615 double status_get_guess_base_percent (const hashcat_ctx_t *hashcat_ctx)
616 {
617 const int guess_base_offset = status_get_guess_base_offset (hashcat_ctx);
618 const int guess_base_count = status_get_guess_base_count (hashcat_ctx);
619
620 if (guess_base_count == 0) return 0;
621
622 return ((double) guess_base_offset / (double) guess_base_count) * 100;
623 }
624
status_get_guess_mod(const hashcat_ctx_t * hashcat_ctx)625 char *status_get_guess_mod (const hashcat_ctx_t *hashcat_ctx)
626 {
627 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
628 const user_options_t *user_options = hashcat_ctx->user_options;
629
630 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
631 {
632 return status_get_rules_file (hashcat_ctx);
633 }
634
635 if (user_options->attack_mode == ATTACK_MODE_COMBI)
636 {
637 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
638
639 if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
640 {
641 return strdup (combinator_ctx->dict2);
642 }
643 return strdup (combinator_ctx->dict1);
644 }
645
646 if (user_options->attack_mode == ATTACK_MODE_BF)
647 {
648
649 }
650
651 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
652 {
653 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
654
655 return strdup (mask_ctx->mask);
656 }
657
658 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
659 {
660 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
661 {
662 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
663
664 return strdup (straight_ctx->dict);
665 }
666
667 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
668
669 return strdup (mask_ctx->mask);
670 }
671
672 return NULL;
673 }
674
status_get_guess_mod_offset(const hashcat_ctx_t * hashcat_ctx)675 int status_get_guess_mod_offset (const hashcat_ctx_t *hashcat_ctx)
676 {
677 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
678 const user_options_t *user_options = hashcat_ctx->user_options;
679
680 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
681 {
682 return 1;
683 }
684
685 if (user_options->attack_mode == ATTACK_MODE_COMBI)
686 {
687 return 1;
688 }
689
690 if (user_options->attack_mode == ATTACK_MODE_BF)
691 {
692 return 1;
693 }
694
695 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
696 {
697 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
698
699 return mask_ctx->masks_pos + 1;
700 }
701
702 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
703 {
704 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
705 {
706 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
707
708 return straight_ctx->dicts_pos + 1;
709 }
710
711 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
712
713 return mask_ctx->masks_pos + 1;
714 }
715
716 return 0;
717 }
718
status_get_guess_mod_count(const hashcat_ctx_t * hashcat_ctx)719 int status_get_guess_mod_count (const hashcat_ctx_t *hashcat_ctx)
720 {
721 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
722 const user_options_t *user_options = hashcat_ctx->user_options;
723
724 if ((user_options->attack_mode == ATTACK_MODE_STRAIGHT) || (user_options->attack_mode == ATTACK_MODE_ASSOCIATION))
725 {
726 return 1;
727 }
728
729 if (user_options->attack_mode == ATTACK_MODE_COMBI)
730 {
731 return 1;
732 }
733
734 if (user_options->attack_mode == ATTACK_MODE_BF)
735 {
736 return 1;
737 }
738
739 if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
740 {
741 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
742
743 return mask_ctx->masks_cnt;
744 }
745
746 if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
747 {
748 if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
749 {
750 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
751
752 return straight_ctx->dicts_cnt;
753 }
754
755 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
756
757 return mask_ctx->masks_cnt;
758 }
759
760 return 0;
761 }
762
status_get_guess_mod_percent(const hashcat_ctx_t * hashcat_ctx)763 double status_get_guess_mod_percent (const hashcat_ctx_t *hashcat_ctx)
764 {
765 const int guess_mod_offset = status_get_guess_mod_offset (hashcat_ctx);
766 const int guess_mod_count = status_get_guess_mod_count (hashcat_ctx);
767
768 if (guess_mod_count == 0) return 0;
769
770 return ((double) guess_mod_offset / (double) guess_mod_count) * 100;
771 }
772
status_get_guess_charset(const hashcat_ctx_t * hashcat_ctx)773 char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx)
774 {
775 const user_options_t *user_options = hashcat_ctx->user_options;
776
777 const char *custom_charset_1 = user_options->custom_charset_1;
778 const char *custom_charset_2 = user_options->custom_charset_2;
779 const char *custom_charset_3 = user_options->custom_charset_3;
780 const char *custom_charset_4 = user_options->custom_charset_4;
781
782 if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL))
783 {
784 char *tmp_buf;
785
786 if (custom_charset_1 == NULL) custom_charset_1 = "Undefined";
787 if (custom_charset_2 == NULL) custom_charset_2 = "Undefined";
788 if (custom_charset_3 == NULL) custom_charset_3 = "Undefined";
789 if (custom_charset_4 == NULL) custom_charset_4 = "Undefined";
790
791 hc_asprintf (&tmp_buf, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4);
792
793 return tmp_buf;
794 }
795
796 return NULL;
797 }
798
status_get_guess_mask_length(const hashcat_ctx_t * hashcat_ctx)799 int status_get_guess_mask_length (const hashcat_ctx_t *hashcat_ctx)
800 {
801 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
802 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
803
804 if (mask_ctx == NULL) return -1;
805
806 if (mask_ctx->mask == NULL) return -1;
807
808 return mp_get_length (mask_ctx->mask, hashconfig->opts_type);
809 }
810
status_get_guess_candidates_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)811 char *status_get_guess_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
812 {
813 const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
814 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
815 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
816 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
817
818 if (status_ctx->accessible == false) return NULL;
819
820 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
821
822 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
823
824 if ((device_param->skipped == true) || (device_param->skipped_warning == true))
825 {
826 snprintf (display, HCBUFSIZ_TINY, "[Skipped]");
827
828 return display;
829 }
830
831 if (user_options_extra->attack_kern == ATTACK_KERN_BF)
832 {
833 snprintf (display, HCBUFSIZ_TINY, "[Generating]");
834 }
835 else
836 {
837 snprintf (display, HCBUFSIZ_TINY, "[Copying]");
838 }
839
840 if ((device_param->outerloop_left == 0) || (device_param->innerloop_left == 0)) return display;
841
842 const u64 outerloop_first = 0;
843 const u64 outerloop_last = device_param->outerloop_left - 1;
844
845 const u32 innerloop_first = 0;
846 const u32 innerloop_last = device_param->innerloop_left - 1;
847
848 plain_t plain1 = { outerloop_first, innerloop_first, 0, 0, 0, 0, 0 };
849 plain_t plain2 = { outerloop_last, innerloop_last, 0, 0, 0, 0, 0 };
850
851 u32 plain_buf1[(64 * 2) + 2] = { 0 };
852 u32 plain_buf2[(64 * 2) + 2] = { 0 };
853
854 u8 *plain_ptr1 = (u8 *) plain_buf1;
855 u8 *plain_ptr2 = (u8 *) plain_buf2;
856
857 int plain_len1 = 0;
858 int plain_len2 = 0;
859
860 build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1);
861 build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2);
862
863 const bool always_ascii = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
864
865 const bool need_hex1 = need_hexify (plain_ptr1, plain_len1, 0, always_ascii);
866 const bool need_hex2 = need_hexify (plain_ptr2, plain_len2, 0, always_ascii);
867
868 if ((need_hex1 == true) || (need_hex2 == true))
869 {
870 exec_hexify (plain_ptr1, plain_len1, plain_ptr1);
871 exec_hexify (plain_ptr2, plain_len2, plain_ptr2);
872
873 plain_ptr1[plain_len1 * 2] = 0;
874 plain_ptr2[plain_len2 * 2] = 0;
875
876 snprintf (display, HCBUFSIZ_TINY, "$HEX[%s] -> $HEX[%s]", plain_ptr1, plain_ptr2);
877 }
878 else
879 {
880 plain_ptr1[plain_len1] = 0;
881 plain_ptr2[plain_len2] = 0;
882
883 snprintf (display, HCBUFSIZ_TINY, "%s -> %s", plain_ptr1, plain_ptr2);
884 }
885
886 return display;
887 }
888
status_get_digests_done(const hashcat_ctx_t * hashcat_ctx)889 int status_get_digests_done (const hashcat_ctx_t *hashcat_ctx)
890 {
891 const hashes_t *hashes = hashcat_ctx->hashes;
892
893 return hashes->digests_done;
894 }
895
status_get_digests_cnt(const hashcat_ctx_t * hashcat_ctx)896 int status_get_digests_cnt (const hashcat_ctx_t *hashcat_ctx)
897 {
898 const hashes_t *hashes = hashcat_ctx->hashes;
899
900 return hashes->digests_cnt;
901 }
902
status_get_digests_percent(const hashcat_ctx_t * hashcat_ctx)903 double status_get_digests_percent (const hashcat_ctx_t *hashcat_ctx)
904 {
905 const hashes_t *hashes = hashcat_ctx->hashes;
906
907 if (hashes->digests_cnt == 0) return 0;
908
909 return ((double) hashes->digests_done / (double) hashes->digests_cnt) * 100;
910 }
911
status_get_salts_done(const hashcat_ctx_t * hashcat_ctx)912 int status_get_salts_done (const hashcat_ctx_t *hashcat_ctx)
913 {
914 const hashes_t *hashes = hashcat_ctx->hashes;
915
916 return hashes->salts_done;
917 }
918
status_get_salts_cnt(const hashcat_ctx_t * hashcat_ctx)919 int status_get_salts_cnt (const hashcat_ctx_t *hashcat_ctx)
920 {
921 const hashes_t *hashes = hashcat_ctx->hashes;
922
923 return hashes->salts_cnt;
924 }
925
status_get_salts_percent(const hashcat_ctx_t * hashcat_ctx)926 double status_get_salts_percent (const hashcat_ctx_t *hashcat_ctx)
927 {
928 const hashes_t *hashes = hashcat_ctx->hashes;
929
930 if (hashes->salts_cnt == 0) return 0;
931
932 return ((double) hashes->salts_done / (double) hashes->salts_cnt) * 100;
933 }
934
status_get_msec_running(const hashcat_ctx_t * hashcat_ctx)935 double status_get_msec_running (const hashcat_ctx_t *hashcat_ctx)
936 {
937 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
938
939 double msec_running = hc_timer_get (status_ctx->timer_running);
940
941 return msec_running;
942 }
943
status_get_msec_paused(const hashcat_ctx_t * hashcat_ctx)944 double status_get_msec_paused (const hashcat_ctx_t *hashcat_ctx)
945 {
946 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
947
948 double msec_paused = status_ctx->msec_paused;
949
950 if (status_ctx->devices_status == STATUS_PAUSED)
951 {
952 double msec_paused_tmp = hc_timer_get (status_ctx->timer_paused);
953
954 msec_paused += msec_paused_tmp;
955 }
956
957 return msec_paused;
958 }
959
status_get_msec_real(const hashcat_ctx_t * hashcat_ctx)960 double status_get_msec_real (const hashcat_ctx_t *hashcat_ctx)
961 {
962 const double msec_running = status_get_msec_running (hashcat_ctx);
963 const double msec_paused = status_get_msec_paused (hashcat_ctx);
964
965 const double msec_real = msec_running - msec_paused;
966
967 return msec_real;
968 }
969
status_get_time_started_absolute(const hashcat_ctx_t * hashcat_ctx)970 char *status_get_time_started_absolute (const hashcat_ctx_t *hashcat_ctx)
971 {
972 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
973
974 const time_t time_start = status_ctx->runtime_start;
975
976 char buf[32] = { 0 };
977
978 char *start = ctime_r (&time_start, buf);
979
980 const size_t start_len = strlen (start);
981
982 if (start[start_len - 1] == '\n') start[start_len - 1] = 0;
983 if (start[start_len - 2] == '\r') start[start_len - 2] = 0;
984
985 return strdup (start);
986 }
987
status_get_time_started_relative(const hashcat_ctx_t * hashcat_ctx)988 char *status_get_time_started_relative (const hashcat_ctx_t *hashcat_ctx)
989 {
990 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
991
992 time_t time_now;
993
994 time (&time_now);
995
996 const time_t time_start = status_ctx->runtime_start;
997
998 time_t sec_run = time_now - time_start;
999
1000 struct tm *tmp;
1001 struct tm tm;
1002
1003 tmp = gmtime_r (&sec_run, &tm);
1004
1005 char *display_run = (char *) hcmalloc (HCBUFSIZ_TINY);
1006
1007 format_timer_display (tmp, display_run, HCBUFSIZ_TINY);
1008
1009 return display_run;
1010 }
1011
status_get_sec_etc(const hashcat_ctx_t * hashcat_ctx)1012 time_t status_get_sec_etc (const hashcat_ctx_t *hashcat_ctx)
1013 {
1014 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1015 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
1016
1017 time_t sec_etc = 0;
1018
1019 if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK))
1020 {
1021 if (status_ctx->devices_status != STATUS_CRACKED)
1022 {
1023 const u64 progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx);
1024 const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx);
1025
1026 const u64 progress_ignore = status_get_progress_ignore (hashcat_ctx);
1027
1028 const double hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx);
1029
1030 if (hashes_msec_all > 0)
1031 {
1032 const u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip;
1033
1034 u64 msec_left = (u64) ((progress_left_relative_skip - progress_ignore) / hashes_msec_all);
1035
1036 sec_etc = msec_left / 1000;
1037 }
1038 }
1039 }
1040
1041 return sec_etc;
1042 }
1043
status_get_time_estimated_absolute(const hashcat_ctx_t * hashcat_ctx)1044 char *status_get_time_estimated_absolute (const hashcat_ctx_t *hashcat_ctx)
1045 {
1046 time_t sec_etc = status_get_sec_etc (hashcat_ctx);
1047
1048 time_t now;
1049 time (&now);
1050
1051 char buf[32] = { 0 };
1052
1053 char *etc;
1054
1055 if (overflow_check_u64_add (now, sec_etc) == false)
1056 {
1057 etc = (char *) ETA_ABSOLUTE_MAX_EXCEEDED;
1058 }
1059 else
1060 {
1061 time_t end = now + sec_etc;
1062
1063 etc = ctime_r (&end, buf);
1064
1065 if (etc == NULL) etc = (char *) ETA_ABSOLUTE_MAX_EXCEEDED;
1066 }
1067
1068 const size_t etc_len = strlen (etc);
1069
1070 if (etc[etc_len - 1] == '\n') etc[etc_len - 1] = 0;
1071 if (etc[etc_len - 2] == '\r') etc[etc_len - 2] = 0;
1072
1073 return strdup (etc);
1074 }
1075
status_get_time_estimated_relative(const hashcat_ctx_t * hashcat_ctx)1076 char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx)
1077 {
1078 const user_options_t *user_options = hashcat_ctx->user_options;
1079
1080 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1081
1082 time_t sec_etc = status_get_sec_etc (hashcat_ctx);
1083
1084 struct tm *tmp;
1085 struct tm tm;
1086
1087 tmp = gmtime_r (&sec_etc, &tm);
1088
1089 if (tmp == NULL)
1090 {
1091 snprintf (display, HCBUFSIZ_TINY, "%s", ETA_RELATIVE_MAX_EXCEEDED);
1092 }
1093 else
1094 {
1095 format_timer_display (tmp, display, HCBUFSIZ_TINY);
1096 }
1097
1098 if (user_options->runtime > 0)
1099 {
1100 const int runtime_left = get_runtime_left (hashcat_ctx);
1101
1102 char *tmp_display = strdup (display);
1103
1104 if (runtime_left > 0)
1105 {
1106 time_t sec_left = runtime_left;
1107
1108 struct tm *tmp_left;
1109 struct tm tm_left;
1110
1111 tmp_left = gmtime_r (&sec_left, &tm_left);
1112
1113 char *display_left = (char *) hcmalloc (HCBUFSIZ_TINY);
1114
1115 format_timer_display (tmp_left, display_left, HCBUFSIZ_TINY);
1116
1117 snprintf (display, HCBUFSIZ_TINY, "%s; Runtime limited: %s", tmp_display, display_left);
1118
1119 hcfree (display_left);
1120 }
1121 else
1122 {
1123 snprintf (display, HCBUFSIZ_TINY, "%s; Runtime limit exceeded", tmp_display);
1124 }
1125
1126 hcfree (tmp_display);
1127 }
1128
1129 return display;
1130 }
1131
status_get_restore_point(const hashcat_ctx_t * hashcat_ctx)1132 u64 status_get_restore_point (const hashcat_ctx_t *hashcat_ctx)
1133 {
1134 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1135
1136 const u64 restore_point = status_ctx->words_cur;
1137
1138 return restore_point;
1139 }
1140
status_get_restore_total(const hashcat_ctx_t * hashcat_ctx)1141 u64 status_get_restore_total (const hashcat_ctx_t *hashcat_ctx)
1142 {
1143 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1144
1145 const u64 restore_total = status_ctx->words_base;
1146
1147 return restore_total;
1148 }
1149
status_get_restore_percent(const hashcat_ctx_t * hashcat_ctx)1150 double status_get_restore_percent (const hashcat_ctx_t *hashcat_ctx)
1151 {
1152 double restore_percent = 0;
1153
1154 const u64 restore_point = status_get_restore_point (hashcat_ctx);
1155 const u64 restore_total = status_get_restore_total (hashcat_ctx);
1156
1157 if (restore_total > 0)
1158 {
1159 restore_percent = ((double) restore_point / (double) restore_total) * 100;
1160 }
1161
1162 return restore_percent;
1163 }
1164
status_get_progress_mode(const hashcat_ctx_t * hashcat_ctx)1165 int status_get_progress_mode (const hashcat_ctx_t *hashcat_ctx)
1166 {
1167 const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx);
1168
1169 if (progress_end_relative_skip > 0)
1170 {
1171 return PROGRESS_MODE_KEYSPACE_KNOWN;
1172 }
1173 return PROGRESS_MODE_KEYSPACE_UNKNOWN;
1174 }
1175
status_get_progress_finished_percent(const hashcat_ctx_t * hashcat_ctx)1176 double status_get_progress_finished_percent (const hashcat_ctx_t *hashcat_ctx)
1177 {
1178 const u64 progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx);
1179 const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx);
1180
1181 double progress_finished_percent = 0;
1182
1183 if (progress_end_relative_skip > 0)
1184 {
1185 progress_finished_percent = ((double) progress_cur_relative_skip / (double) progress_end_relative_skip) * 100;
1186 }
1187
1188 return progress_finished_percent;
1189 }
1190
status_get_progress_done(const hashcat_ctx_t * hashcat_ctx)1191 u64 status_get_progress_done (const hashcat_ctx_t *hashcat_ctx)
1192 {
1193 const hashes_t *hashes = hashcat_ctx->hashes;
1194 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1195
1196 u64 progress_done = 0;
1197
1198 for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
1199 {
1200 progress_done += status_ctx->words_progress_done[salt_pos];
1201 }
1202
1203 return progress_done;
1204 }
1205
status_get_progress_rejected(const hashcat_ctx_t * hashcat_ctx)1206 u64 status_get_progress_rejected (const hashcat_ctx_t *hashcat_ctx)
1207 {
1208 const hashes_t *hashes = hashcat_ctx->hashes;
1209 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1210
1211 u64 progress_rejected = 0;
1212
1213 for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
1214 {
1215 progress_rejected += status_ctx->words_progress_rejected[salt_pos];
1216 }
1217
1218 return progress_rejected;
1219 }
1220
status_get_progress_rejected_percent(const hashcat_ctx_t * hashcat_ctx)1221 double status_get_progress_rejected_percent (const hashcat_ctx_t *hashcat_ctx)
1222 {
1223 const u64 progress_cur = status_get_progress_cur (hashcat_ctx);
1224 const u64 progress_rejected = status_get_progress_rejected (hashcat_ctx);
1225
1226 double percent_rejected = 0;
1227
1228 if (progress_cur)
1229 {
1230 percent_rejected = ((double) (progress_rejected) / (double) progress_cur) * 100;
1231 }
1232
1233 return percent_rejected;
1234 }
1235
status_get_progress_restored(const hashcat_ctx_t * hashcat_ctx)1236 u64 status_get_progress_restored (const hashcat_ctx_t *hashcat_ctx)
1237 {
1238 const hashes_t *hashes = hashcat_ctx->hashes;
1239 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1240
1241 u64 progress_restored = 0;
1242
1243 for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
1244 {
1245 progress_restored += status_ctx->words_progress_restored[salt_pos];
1246 }
1247
1248 return progress_restored;
1249 }
1250
status_get_progress_cur(const hashcat_ctx_t * hashcat_ctx)1251 u64 status_get_progress_cur (const hashcat_ctx_t *hashcat_ctx)
1252 {
1253 const u64 progress_done = status_get_progress_done (hashcat_ctx);
1254 const u64 progress_rejected = status_get_progress_rejected (hashcat_ctx);
1255 const u64 progress_restored = status_get_progress_restored (hashcat_ctx);
1256
1257 const u64 progress_cur = progress_done + progress_rejected + progress_restored;
1258
1259 return progress_cur;
1260 }
1261
status_get_progress_ignore(const hashcat_ctx_t * hashcat_ctx)1262 u64 status_get_progress_ignore (const hashcat_ctx_t *hashcat_ctx)
1263 {
1264 const hashes_t *hashes = hashcat_ctx->hashes;
1265 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1266 const user_options_t *user_options = hashcat_ctx->user_options;
1267 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
1268
1269 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1270 {
1271 // we have no salt based skips in this attack mode
1272 // ?? words_progress_restored[]
1273
1274 return 0;
1275 }
1276
1277 u64 words_cnt = status_ctx->words_cnt;
1278
1279 if (user_options->limit)
1280 {
1281 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
1282 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
1283 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
1284
1285 words_cnt = MIN (user_options->limit, status_ctx->words_base);
1286
1287 if (user_options->slow_candidates == true)
1288 {
1289 // nothing to do
1290 }
1291 else
1292 {
1293 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) words_cnt *= straight_ctx->kernel_rules_cnt;
1294 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) words_cnt *= combinator_ctx->combs_cnt;
1295 else if (user_options_extra->attack_kern == ATTACK_KERN_BF) words_cnt *= mask_ctx->bfs_cnt;
1296 }
1297 }
1298 // Important for ETA only
1299
1300 u64 progress_ignore = 0;
1301
1302 for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++)
1303 {
1304 if (hashes->salts_shown[salt_pos] == 1)
1305 {
1306 const u64 all = status_ctx->words_progress_done[salt_pos]
1307 + status_ctx->words_progress_rejected[salt_pos]
1308 + status_ctx->words_progress_restored[salt_pos];
1309
1310 const u64 left = words_cnt - all;
1311
1312 progress_ignore += left;
1313 }
1314 }
1315
1316 return progress_ignore;
1317 }
1318
status_get_progress_end(const hashcat_ctx_t * hashcat_ctx)1319 u64 status_get_progress_end (const hashcat_ctx_t *hashcat_ctx)
1320 {
1321 const hashes_t *hashes = hashcat_ctx->hashes;
1322 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1323 const user_options_t *user_options = hashcat_ctx->user_options;
1324 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
1325
1326 u64 progress_end = status_ctx->words_cnt;
1327
1328 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1329 {
1330 // nothing to do
1331 }
1332 else
1333 {
1334 progress_end *= hashes->salts_cnt;
1335 }
1336
1337 if (user_options->limit)
1338 {
1339 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
1340 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
1341 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
1342
1343 progress_end = MIN (user_options->limit, status_ctx->words_base);
1344
1345 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1346 {
1347 // nothing to do
1348 }
1349 else
1350 {
1351 progress_end *= hashes->salts_cnt;
1352 }
1353
1354 if (user_options->slow_candidates == true)
1355 {
1356 // nothing to do
1357 }
1358 else
1359 {
1360 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt;
1361 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt;
1362 else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt;
1363 }
1364 }
1365
1366 return progress_end;
1367 }
1368
status_get_progress_skip(const hashcat_ctx_t * hashcat_ctx)1369 u64 status_get_progress_skip (const hashcat_ctx_t *hashcat_ctx)
1370 {
1371 const hashes_t *hashes = hashcat_ctx->hashes;
1372 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1373 const user_options_t *user_options = hashcat_ctx->user_options;
1374 const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
1375
1376 u64 progress_skip = 0;
1377
1378 if (user_options->skip)
1379 {
1380 const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
1381 const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
1382 const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
1383
1384 progress_skip = MIN (user_options->skip, status_ctx->words_base);
1385
1386 if (user_options->attack_mode == ATTACK_MODE_ASSOCIATION)
1387 {
1388 // nothing to do
1389 }
1390 else
1391 {
1392 progress_skip *= hashes->salts_cnt;
1393 }
1394
1395 if (user_options->slow_candidates == true)
1396 {
1397 // nothing to do
1398 }
1399 else
1400 {
1401 if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt;
1402 else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt;
1403 else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt;
1404 }
1405 }
1406
1407 return progress_skip;
1408 }
1409
status_get_progress_cur_relative_skip(const hashcat_ctx_t * hashcat_ctx)1410 u64 status_get_progress_cur_relative_skip (const hashcat_ctx_t *hashcat_ctx)
1411 {
1412 const u64 progress_skip = status_get_progress_skip (hashcat_ctx);
1413 const u64 progress_cur = status_get_progress_cur (hashcat_ctx);
1414
1415 u64 progress_cur_relative_skip = 0;
1416
1417 if (progress_cur > 0)
1418 {
1419 progress_cur_relative_skip = progress_cur - progress_skip;
1420 }
1421
1422 return progress_cur_relative_skip;
1423 }
1424
status_get_progress_end_relative_skip(const hashcat_ctx_t * hashcat_ctx)1425 u64 status_get_progress_end_relative_skip (const hashcat_ctx_t *hashcat_ctx)
1426 {
1427 const u64 progress_skip = status_get_progress_skip (hashcat_ctx);
1428 const u64 progress_end = status_get_progress_end (hashcat_ctx);
1429
1430 u64 progress_end_relative_skip = 0;
1431
1432 if (progress_end > 0)
1433 {
1434 progress_end_relative_skip = progress_end - progress_skip;
1435 }
1436
1437 return progress_end_relative_skip;
1438 }
1439
status_get_hashes_msec_all(const hashcat_ctx_t * hashcat_ctx)1440 double status_get_hashes_msec_all (const hashcat_ctx_t *hashcat_ctx)
1441 {
1442 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1443
1444 double hashes_all_msec = 0;
1445
1446 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
1447 {
1448 hashes_all_msec += status_get_hashes_msec_dev (hashcat_ctx, backend_devices_idx);
1449 }
1450
1451 return hashes_all_msec;
1452 }
1453
status_get_hashes_msec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1454 double status_get_hashes_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1455 {
1456 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1457
1458 u64 speed_cnt = 0;
1459 double speed_msec = 0;
1460
1461 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1462
1463 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1464 {
1465 const u32 speed_pos = MAX (device_param->speed_pos, 1);
1466
1467 for (u32 i = 0; i < speed_pos; i++)
1468 {
1469 speed_cnt += device_param->speed_cnt[i];
1470 speed_msec += device_param->speed_msec[i];
1471 }
1472
1473 speed_cnt /= speed_pos;
1474 speed_msec /= speed_pos;
1475 }
1476
1477 double hashes_dev_msec = 0;
1478
1479 if (speed_msec > 0)
1480 {
1481 hashes_dev_msec = (double) speed_cnt / speed_msec;
1482 }
1483
1484 return hashes_dev_msec;
1485 }
1486
status_get_hashes_msec_dev_benchmark(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1487 double status_get_hashes_msec_dev_benchmark (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1488 {
1489 // this function increases accuracy for benchmark modes
1490
1491 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1492
1493 u64 speed_cnt = 0;
1494 double speed_msec = 0;
1495
1496 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1497
1498 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1499 {
1500 const u32 speed_pos = MAX (device_param->speed_pos, 1);
1501
1502 speed_cnt += device_param->speed_cnt[speed_pos - 1];
1503 speed_msec += device_param->speed_msec[speed_pos - 1];
1504 }
1505
1506 double hashes_dev_msec = 0;
1507
1508 if (speed_msec > 0)
1509 {
1510 hashes_dev_msec = (double) speed_cnt / speed_msec;
1511 }
1512
1513 return hashes_dev_msec;
1514 }
1515
status_get_exec_msec_all(const hashcat_ctx_t * hashcat_ctx)1516 double status_get_exec_msec_all (const hashcat_ctx_t *hashcat_ctx)
1517 {
1518 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1519
1520 double exec_all_msec = 0;
1521
1522 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
1523 {
1524 exec_all_msec += status_get_exec_msec_dev (hashcat_ctx, backend_devices_idx);
1525 }
1526
1527 return exec_all_msec;
1528 }
1529
status_get_exec_msec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1530 double status_get_exec_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1531 {
1532 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1533
1534 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1535
1536 double exec_dev_msec = 0;
1537
1538 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1539 {
1540 exec_dev_msec = get_avg_exec_time (device_param, EXEC_CACHE);
1541 }
1542
1543 return exec_dev_msec;
1544 }
1545
status_get_speed_sec_all(const hashcat_ctx_t * hashcat_ctx)1546 char *status_get_speed_sec_all (const hashcat_ctx_t *hashcat_ctx)
1547 {
1548 const double hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx);
1549
1550 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1551
1552 format_speed_display (hashes_msec_all * 1000, display, HCBUFSIZ_TINY);
1553
1554 return display;
1555 }
1556
status_get_speed_sec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1557 char *status_get_speed_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1558 {
1559 const double hashes_msec_dev = status_get_hashes_msec_dev (hashcat_ctx, backend_devices_idx);
1560
1561 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1562
1563 format_speed_display (hashes_msec_dev * 1000, display, HCBUFSIZ_TINY);
1564
1565 return display;
1566 }
1567
status_get_cpt_cur_min(const hashcat_ctx_t * hashcat_ctx)1568 int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx)
1569 {
1570 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1571 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1572
1573 if (status_ctx->accessible == false) return 0;
1574
1575 const time_t now = time (NULL);
1576
1577 int cpt_cur_min = 0;
1578
1579 for (int i = 0; i < CPT_CACHE; i++)
1580 {
1581 const u32 cracked = cpt_ctx->cpt_buf[i].cracked;
1582 const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp;
1583
1584 if ((timestamp + 60) > now)
1585 {
1586 cpt_cur_min += cracked;
1587 }
1588 }
1589
1590 return cpt_cur_min;
1591 }
1592
status_get_cpt_cur_hour(const hashcat_ctx_t * hashcat_ctx)1593 int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx)
1594 {
1595 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1596 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1597
1598 if (status_ctx->accessible == false) return 0;
1599
1600 const time_t now = time (NULL);
1601
1602 int cpt_cur_hour = 0;
1603
1604 for (int i = 0; i < CPT_CACHE; i++)
1605 {
1606 const u32 cracked = cpt_ctx->cpt_buf[i].cracked;
1607 const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp;
1608
1609 if ((timestamp + 3600) > now)
1610 {
1611 cpt_cur_hour += cracked;
1612 }
1613 }
1614
1615 return cpt_cur_hour;
1616 }
1617
status_get_cpt_cur_day(const hashcat_ctx_t * hashcat_ctx)1618 int status_get_cpt_cur_day (const hashcat_ctx_t *hashcat_ctx)
1619 {
1620 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1621 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
1622
1623 if (status_ctx->accessible == false) return 0;
1624
1625 const time_t now = time (NULL);
1626
1627 int cpt_cur_day = 0;
1628
1629 for (int i = 0; i < CPT_CACHE; i++)
1630 {
1631 const u32 cracked = cpt_ctx->cpt_buf[i].cracked;
1632 const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp;
1633
1634 if ((timestamp + 86400) > now)
1635 {
1636 cpt_cur_day += cracked;
1637 }
1638 }
1639
1640 return cpt_cur_day;
1641 }
1642
status_get_cpt_avg_min(const hashcat_ctx_t * hashcat_ctx)1643 double status_get_cpt_avg_min (const hashcat_ctx_t *hashcat_ctx)
1644 {
1645 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1646
1647 const double msec_real = status_get_msec_real (hashcat_ctx);
1648
1649 const double min_real = (msec_real / 1000) / 60;
1650
1651 double cpt_avg_min = 0;
1652
1653 if (min_real > 1)
1654 {
1655 cpt_avg_min = (double) cpt_ctx->cpt_total / min_real;
1656 }
1657
1658 return cpt_avg_min;
1659 }
1660
status_get_cpt_avg_hour(const hashcat_ctx_t * hashcat_ctx)1661 double status_get_cpt_avg_hour (const hashcat_ctx_t *hashcat_ctx)
1662 {
1663 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1664
1665 const double msec_real = status_get_msec_real (hashcat_ctx);
1666
1667 const double hour_real = (msec_real / 1000) / (60 * 60);
1668
1669 double cpt_avg_hour = 0;
1670
1671 if (hour_real > 1)
1672 {
1673 cpt_avg_hour = (double) cpt_ctx->cpt_total / hour_real;
1674 }
1675
1676 return cpt_avg_hour;
1677 }
1678
status_get_cpt_avg_day(const hashcat_ctx_t * hashcat_ctx)1679 double status_get_cpt_avg_day (const hashcat_ctx_t *hashcat_ctx)
1680 {
1681 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1682
1683 const double msec_real = status_get_msec_real (hashcat_ctx);
1684
1685 const double day_real = (msec_real / 1000) / (60 * 60 * 24);
1686
1687 double cpt_avg_day = 0;
1688
1689 if (day_real > 1)
1690 {
1691 cpt_avg_day = (double) cpt_ctx->cpt_total / day_real;
1692 }
1693
1694 return cpt_avg_day;
1695 }
1696
status_get_cpt(const hashcat_ctx_t * hashcat_ctx)1697 char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx)
1698 {
1699 const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx;
1700
1701 const time_t now = time (NULL);
1702
1703 char *cpt;
1704
1705 const int cpt_cur_min = status_get_cpt_cur_min (hashcat_ctx);
1706 const int cpt_cur_hour = status_get_cpt_cur_hour (hashcat_ctx);
1707 const int cpt_cur_day = status_get_cpt_cur_day (hashcat_ctx);
1708
1709 const double cpt_avg_min = status_get_cpt_avg_min (hashcat_ctx);
1710 const double cpt_avg_hour = status_get_cpt_avg_hour (hashcat_ctx);
1711 const double cpt_avg_day = status_get_cpt_avg_day (hashcat_ctx);
1712
1713 if ((cpt_ctx->cpt_start + (60 * 60 * 24)) < now)
1714 {
1715 hc_asprintf (&cpt, "CUR:%d,%d,%d AVG:%.2f,%.2f,%.2f (Min,Hour,Day)",
1716 cpt_cur_min,
1717 cpt_cur_hour,
1718 cpt_cur_day,
1719 cpt_avg_min,
1720 cpt_avg_hour,
1721 cpt_avg_day);
1722 }
1723 else if ((cpt_ctx->cpt_start + (60 * 60)) < now)
1724 {
1725 hc_asprintf (&cpt, "CUR:%d,%d,N/A AVG:%.2f,%.2f,N/a (Min,Hour,Day)",
1726 cpt_cur_min,
1727 cpt_cur_hour,
1728 cpt_avg_min,
1729 cpt_avg_hour);
1730 }
1731 else if ((cpt_ctx->cpt_start + 60) < now)
1732 {
1733 hc_asprintf (&cpt, "CUR:%d,N/A,N/A AVG:%.2f,N/A,N/A (Min,Hour,Day)",
1734 cpt_cur_min,
1735 cpt_avg_min);
1736 }
1737 else
1738 {
1739 hc_asprintf (&cpt, "CUR:N/A,N/A,N/A AVG:N/A,N/A,N/A (Min,Hour,Day)");
1740 }
1741
1742 return cpt;
1743 }
1744
status_get_salt_pos_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1745 int status_get_salt_pos_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1746 {
1747 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1748
1749 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1750
1751 int salt_pos = 0;
1752
1753 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1754 {
1755 salt_pos = (int) device_param->kernel_params_buf32[27];
1756 }
1757
1758 return salt_pos;
1759 }
1760
status_get_innerloop_pos_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1761 int status_get_innerloop_pos_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1762 {
1763 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1764
1765 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1766
1767 int innerloop_pos = 0;
1768
1769 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1770 {
1771 innerloop_pos = (int) device_param->innerloop_pos;
1772 }
1773
1774 return innerloop_pos;
1775 }
1776
status_get_innerloop_left_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1777 int status_get_innerloop_left_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1778 {
1779 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1780
1781 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1782
1783 int innerloop_left = 0;
1784
1785 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1786 {
1787 innerloop_left = (int) device_param->innerloop_left;
1788 }
1789
1790 return innerloop_left;
1791 }
1792
status_get_iteration_pos_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1793 int status_get_iteration_pos_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1794 {
1795 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1796
1797 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1798
1799 int iteration_pos = 0;
1800
1801 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1802 {
1803 iteration_pos = (int) device_param->kernel_params_buf32[28];
1804 }
1805
1806 return iteration_pos;
1807 }
1808
status_get_iteration_left_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1809 int status_get_iteration_left_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1810 {
1811 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1812
1813 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1814
1815 int iteration_left = 0;
1816
1817 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1818 {
1819 iteration_left = (int) device_param->kernel_params_buf32[29];
1820 }
1821
1822 return iteration_left;
1823 }
1824
1825 #ifdef WITH_BRAIN
status_get_brain_link_client_id_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1826 int status_get_brain_link_client_id_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1827 {
1828 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1829
1830 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1831
1832 int brain_client_id = -1;
1833
1834 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1835 {
1836 brain_client_id = device_param->brain_link_client_fd;
1837 }
1838
1839 return brain_client_id;
1840 }
1841
status_get_brain_link_status_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1842 int status_get_brain_link_status_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1843 {
1844 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1845
1846 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1847
1848 int brain_link_status_dev = 0;
1849
1850 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1851 {
1852 if (device_param->brain_link_client_fd != -1) brain_link_status_dev = BRAIN_LINK_STATUS_CONNECTED;
1853 if (device_param->brain_link_recv_active == true) brain_link_status_dev = BRAIN_LINK_STATUS_RECEIVING;
1854 if (device_param->brain_link_send_active == true) brain_link_status_dev = BRAIN_LINK_STATUS_SENDING;
1855 }
1856
1857 return brain_link_status_dev;
1858 }
1859
status_get_brain_link_recv_bytes_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1860 char *status_get_brain_link_recv_bytes_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1861 {
1862 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1863
1864 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1865
1866 u64 brain_link_recv_bytes = 0;
1867
1868 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1869 {
1870 brain_link_recv_bytes = device_param->brain_link_recv_bytes;
1871 }
1872
1873 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1874
1875 format_speed_display_1k (brain_link_recv_bytes, display, HCBUFSIZ_TINY);
1876
1877 return display;
1878 }
1879
status_get_brain_rx_all(const hashcat_ctx_t * hashcat_ctx)1880 char *status_get_brain_rx_all (const hashcat_ctx_t *hashcat_ctx)
1881 {
1882 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1883 double brain_rx_all = 0;
1884
1885 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
1886 {
1887 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1888 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1889 {
1890 brain_rx_all += device_param->brain_link_recv_bytes;
1891 }
1892 }
1893
1894 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1895
1896 format_speed_display_1k (brain_rx_all, display, HCBUFSIZ_TINY);
1897
1898 return display;
1899
1900 }
1901
status_get_brain_link_send_bytes_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1902 char *status_get_brain_link_send_bytes_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1903 {
1904 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1905
1906 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1907
1908 u64 brain_link_send_bytes = 0;
1909
1910 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1911 {
1912 brain_link_send_bytes = device_param->brain_link_send_bytes;
1913 }
1914
1915 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1916
1917 format_speed_display_1k (brain_link_send_bytes, display, HCBUFSIZ_TINY);
1918
1919 return display;
1920 }
1921
status_get_brain_tx_all(const hashcat_ctx_t * hashcat_ctx)1922 char *status_get_brain_tx_all (const hashcat_ctx_t *hashcat_ctx)
1923 {
1924 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1925 double brain_tx_all = 0;
1926
1927 for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)
1928 {
1929 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1930 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1931 {
1932 brain_tx_all += device_param->brain_link_send_bytes;
1933 }
1934 }
1935
1936 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1937
1938 format_speed_display_1k (brain_tx_all, display, HCBUFSIZ_TINY);
1939
1940 return display;
1941
1942 }
1943
status_get_brain_link_recv_bytes_sec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1944 char *status_get_brain_link_recv_bytes_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1945 {
1946 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1947
1948 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1949
1950 u64 brain_link_recv_bytes = 0;
1951
1952 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1953 {
1954 for (int idx = 0; idx < LINK_SPEED_COUNT; idx++)
1955 {
1956 double ms = hc_timer_get (device_param->brain_link_recv_speed.timer[idx]);
1957
1958 if (ms >= 1000) continue;
1959
1960 brain_link_recv_bytes += device_param->brain_link_recv_speed.bytes[idx];
1961 }
1962 }
1963
1964 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1965
1966 snprintf (display, HCBUFSIZ_TINY, "%.2f M", (double) (brain_link_recv_bytes * 8) / 1024 / 1024);
1967
1968 return display;
1969 }
1970
status_get_brain_link_send_bytes_sec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)1971 char *status_get_brain_link_send_bytes_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
1972 {
1973 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
1974
1975 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
1976
1977 u64 brain_link_send_bytes = 0;
1978
1979 if ((device_param->skipped == false) && (device_param->skipped_warning == false))
1980 {
1981 for (int idx = 0; idx < LINK_SPEED_COUNT; idx++)
1982 {
1983 double ms = hc_timer_get (device_param->brain_link_send_speed.timer[idx]);
1984
1985 if (ms >= 1000) continue;
1986
1987 brain_link_send_bytes += device_param->brain_link_send_speed.bytes[idx];
1988 }
1989 }
1990
1991 char *display = (char *) hcmalloc (HCBUFSIZ_TINY);
1992
1993 snprintf (display, HCBUFSIZ_TINY, "%.2f M", (double) (brain_link_send_bytes * 8) / 1024 / 1024);
1994
1995 return display;
1996 }
1997 #endif
1998
1999 #if defined(__APPLE__)
status_get_hwmon_fan_dev(const hashcat_ctx_t * hashcat_ctx)2000 char *status_get_hwmon_fan_dev (const hashcat_ctx_t *hashcat_ctx)
2001 {
2002 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2003
2004 char *fanspeed_str = (char *) hcmalloc (HCBUFSIZ_TINY);
2005
2006 hc_thread_mutex_lock (status_ctx->mux_hwmon);
2007
2008 hm_get_fanspeed_apple ((hashcat_ctx_t *) hashcat_ctx, fanspeed_str);
2009
2010 hc_thread_mutex_unlock (status_ctx->mux_hwmon);
2011
2012 return fanspeed_str;
2013 }
2014 #endif
2015
status_get_hwmon_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2016 char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2017 {
2018 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2019
2020 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2021
2022 char *output_buf = (char *) hcmalloc (HCBUFSIZ_TINY);
2023
2024 snprintf (output_buf, HCBUFSIZ_TINY, "N/A");
2025
2026 if (device_param->skipped == true) return output_buf;
2027
2028 if (device_param->skipped_warning == true) return output_buf;
2029
2030 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2031
2032 hc_thread_mutex_lock (status_ctx->mux_hwmon);
2033
2034 const int num_temperature = hm_get_temperature_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2035 const int num_fanspeed = hm_get_fanspeed_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2036 const int num_utilization = hm_get_utilization_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2037 const int num_corespeed = hm_get_corespeed_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2038 const int num_memoryspeed = hm_get_memoryspeed_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2039 const int num_buslanes = hm_get_buslanes_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2040
2041 int output_len = 0;
2042
2043 if (num_temperature >= 0)
2044 {
2045 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Temp:%3dc ", num_temperature);
2046 }
2047
2048 if (num_fanspeed >= 0)
2049 {
2050 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Fan:%3d%% ", num_fanspeed);
2051 }
2052
2053 if (num_utilization >= 0)
2054 {
2055 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Util:%3d%% ", num_utilization);
2056 }
2057
2058 if (num_corespeed >= 0)
2059 {
2060 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Core:%4dMHz ", num_corespeed);
2061 }
2062
2063 if (num_memoryspeed >= 0)
2064 {
2065 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Mem:%4dMHz ", num_memoryspeed);
2066 }
2067
2068 if (num_buslanes >= 0)
2069 {
2070 output_len += snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Bus:%d ", num_buslanes);
2071 }
2072
2073 if (output_len > 0)
2074 {
2075 // trims the trailing space
2076
2077 output_buf[output_len - 1] = 0;
2078 }
2079 else
2080 {
2081 snprintf (output_buf, HCBUFSIZ_TINY, "N/A");
2082 }
2083
2084 hc_thread_mutex_unlock (status_ctx->mux_hwmon);
2085
2086 return output_buf;
2087 }
2088
status_get_corespeed_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2089 int status_get_corespeed_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2090 {
2091 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2092
2093 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2094
2095 if (device_param->skipped == true) return -1;
2096
2097 if (device_param->skipped_warning == true) return -1;
2098
2099 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2100
2101 hc_thread_mutex_lock (status_ctx->mux_hwmon);
2102
2103 const int num_corespeed = hm_get_corespeed_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2104
2105 hc_thread_mutex_unlock (status_ctx->mux_hwmon);
2106
2107 return num_corespeed;
2108 }
2109
status_get_memoryspeed_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2110 int status_get_memoryspeed_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2111 {
2112 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2113
2114 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2115
2116 if (device_param->skipped == true) return -1;
2117
2118 if (device_param->skipped_warning == true) return -1;
2119
2120 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2121
2122 hc_thread_mutex_lock (status_ctx->mux_hwmon);
2123
2124 const int num_memoryspeed = hm_get_memoryspeed_with_devices_idx ((hashcat_ctx_t *) hashcat_ctx, backend_devices_idx);
2125
2126 hc_thread_mutex_unlock (status_ctx->mux_hwmon);
2127
2128 return num_memoryspeed;
2129 }
2130
status_get_progress_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2131 u64 status_get_progress_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2132 {
2133 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2134
2135 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2136
2137 if (device_param->skipped == true) return 0;
2138
2139 if (device_param->skipped_warning == true) return 0;
2140
2141 return device_param->outerloop_left;
2142 }
2143
status_get_runtime_msec_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2144 double status_get_runtime_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2145 {
2146 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2147
2148 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2149
2150 if (device_param->skipped == true) return 0;
2151
2152 if (device_param->skipped_warning == true) return 0;
2153
2154 return device_param->outerloop_msec;
2155 }
2156
status_get_kernel_accel_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2157 int status_get_kernel_accel_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2158 {
2159 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2160
2161 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2162
2163 if (device_param->skipped == true) return 0;
2164
2165 if (device_param->skipped_warning == true) return 0;
2166
2167 if (device_param->kernel_accel_prev) return device_param->kernel_accel_prev;
2168
2169 return device_param->kernel_accel;
2170 }
2171
status_get_kernel_loops_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2172 int status_get_kernel_loops_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2173 {
2174 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2175
2176 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2177
2178 if (device_param->skipped == true) return 0;
2179
2180 if (device_param->skipped_warning == true) return 0;
2181
2182 if (device_param->kernel_loops_prev) return device_param->kernel_loops_prev;
2183
2184 return device_param->kernel_loops;
2185 }
2186
status_get_kernel_threads_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2187 int status_get_kernel_threads_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2188 {
2189 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2190
2191 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2192
2193 if (device_param->skipped == true) return 0;
2194
2195 if (device_param->skipped_warning == true) return 0;
2196
2197 if (device_param->kernel_threads_prev) return device_param->kernel_threads_prev;
2198
2199 return device_param->kernel_threads;
2200 }
2201
status_get_vector_width_dev(const hashcat_ctx_t * hashcat_ctx,const int backend_devices_idx)2202 int status_get_vector_width_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
2203 {
2204 const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;
2205
2206 hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
2207
2208 if (device_param->skipped == true) return 0;
2209
2210 if (device_param->skipped_warning == true) return 0;
2211
2212 return device_param->vector_width;
2213 }
2214
status_progress_init(hashcat_ctx_t * hashcat_ctx)2215 int status_progress_init (hashcat_ctx_t *hashcat_ctx)
2216 {
2217 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2218 hashes_t *hashes = hashcat_ctx->hashes;
2219
2220 status_ctx->words_progress_done = (u64 *) hccalloc (hashes->salts_cnt, sizeof (u64));
2221 status_ctx->words_progress_rejected = (u64 *) hccalloc (hashes->salts_cnt, sizeof (u64));
2222 status_ctx->words_progress_restored = (u64 *) hccalloc (hashes->salts_cnt, sizeof (u64));
2223
2224 return 0;
2225 }
2226
status_progress_destroy(hashcat_ctx_t * hashcat_ctx)2227 void status_progress_destroy (hashcat_ctx_t *hashcat_ctx)
2228 {
2229 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2230
2231 hcfree (status_ctx->words_progress_done);
2232 hcfree (status_ctx->words_progress_rejected);
2233 hcfree (status_ctx->words_progress_restored);
2234
2235 status_ctx->words_progress_done = NULL;
2236 status_ctx->words_progress_rejected = NULL;
2237 status_ctx->words_progress_restored = NULL;
2238 }
2239
status_progress_reset(hashcat_ctx_t * hashcat_ctx)2240 void status_progress_reset (hashcat_ctx_t *hashcat_ctx)
2241 {
2242 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2243 hashes_t *hashes = hashcat_ctx->hashes;
2244
2245 memset (status_ctx->words_progress_done, 0, hashes->salts_cnt * sizeof (u64));
2246 memset (status_ctx->words_progress_rejected, 0, hashes->salts_cnt * sizeof (u64));
2247 memset (status_ctx->words_progress_restored, 0, hashes->salts_cnt * sizeof (u64));
2248 }
2249
status_ctx_init(hashcat_ctx_t * hashcat_ctx)2250 int status_ctx_init (hashcat_ctx_t *hashcat_ctx)
2251 {
2252 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2253
2254 status_ctx->devices_status = STATUS_INIT;
2255
2256 status_ctx->run_main_level1 = true;
2257 status_ctx->run_main_level2 = true;
2258 status_ctx->run_main_level3 = true;
2259 status_ctx->run_thread_level1 = true;
2260 status_ctx->run_thread_level2 = true;
2261
2262 status_ctx->shutdown_inner = false;
2263 status_ctx->shutdown_outer = false;
2264
2265 status_ctx->checkpoint_shutdown = false;
2266 status_ctx->finish_shutdown = false;
2267
2268 status_ctx->hashcat_status_final = (hashcat_status_t *) hcmalloc (sizeof (hashcat_status_t));
2269
2270 hc_thread_mutex_init (status_ctx->mux_dispatcher);
2271 hc_thread_mutex_init (status_ctx->mux_counter);
2272 hc_thread_mutex_init (status_ctx->mux_display);
2273 hc_thread_mutex_init (status_ctx->mux_hwmon);
2274
2275 return 0;
2276 }
2277
status_ctx_destroy(hashcat_ctx_t * hashcat_ctx)2278 void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
2279 {
2280 status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2281
2282 hc_thread_mutex_delete (status_ctx->mux_dispatcher);
2283 hc_thread_mutex_delete (status_ctx->mux_counter);
2284 hc_thread_mutex_delete (status_ctx->mux_display);
2285 hc_thread_mutex_delete (status_ctx->mux_hwmon);
2286
2287 hcfree (status_ctx->hashcat_status_final);
2288
2289 memset (status_ctx, 0, sizeof (status_ctx_t));
2290 }
2291
status_status_destroy(hashcat_ctx_t * hashcat_ctx,hashcat_status_t * hashcat_status)2292 void status_status_destroy (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status)
2293 {
2294 const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
2295
2296 if (status_ctx == NULL) return;
2297
2298 if (status_ctx->accessible == false) return;
2299
2300 hcfree (hashcat_status->hash_target);
2301 hcfree (hashcat_status->hash_name);
2302 hcfree (hashcat_status->session);
2303 hcfree (hashcat_status->time_estimated_absolute);
2304 hcfree (hashcat_status->time_estimated_relative);
2305 hcfree (hashcat_status->time_started_absolute);
2306 hcfree (hashcat_status->time_started_relative);
2307 hcfree (hashcat_status->speed_sec_all);
2308 hcfree (hashcat_status->guess_base);
2309 hcfree (hashcat_status->guess_mod);
2310 hcfree (hashcat_status->guess_charset);
2311 hcfree (hashcat_status->cpt);
2312 #ifdef WITH_BRAIN
2313 hcfree (hashcat_status->brain_rx_all);
2314 hcfree (hashcat_status->brain_tx_all);
2315 #endif
2316
2317 hashcat_status->hash_target = NULL;
2318 hashcat_status->hash_name = NULL;
2319 hashcat_status->session = NULL;
2320 hashcat_status->time_estimated_absolute = NULL;
2321 hashcat_status->time_estimated_relative = NULL;
2322 hashcat_status->time_started_absolute = NULL;
2323 hashcat_status->time_started_relative = NULL;
2324 hashcat_status->speed_sec_all = NULL;
2325 hashcat_status->guess_base = NULL;
2326 hashcat_status->guess_mod = NULL;
2327 hashcat_status->guess_charset = NULL;
2328 hashcat_status->cpt = NULL;
2329 #ifdef WITH_BRAIN
2330 hashcat_status->brain_rx_all = NULL;
2331 hashcat_status->brain_tx_all = NULL;
2332 #endif
2333
2334 for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++)
2335 {
2336 device_info_t *device_info = hashcat_status->device_info_buf + device_id;
2337
2338 hcfree (device_info->speed_sec_dev);
2339 hcfree (device_info->guess_candidates_dev);
2340 hcfree (device_info->hwmon_dev);
2341 #ifdef WITH_BRAIN
2342 hcfree (device_info->brain_link_recv_bytes_dev);
2343 hcfree (device_info->brain_link_send_bytes_dev);
2344 hcfree (device_info->brain_link_recv_bytes_sec_dev);
2345 hcfree (device_info->brain_link_send_bytes_sec_dev);
2346 #endif
2347
2348 device_info->speed_sec_dev = NULL;
2349 device_info->guess_candidates_dev = NULL;
2350 device_info->hwmon_dev = NULL;
2351 #ifdef WITH_BRAIN
2352 device_info->brain_link_recv_bytes_dev = NULL;
2353 device_info->brain_link_send_bytes_dev = NULL;
2354 device_info->brain_link_recv_bytes_sec_dev = NULL;
2355 device_info->brain_link_send_bytes_sec_dev = NULL;
2356 #endif
2357 }
2358 }
2359