mirror of
https://github.com/hashcat/hashcat
synced 2024-12-27 05:13:45 +01:00
Move out words_cur from restore_ctx to status_ctx and let the dispatcher update it
This commit is contained in:
parent
5b26567cb6
commit
761e3f0d96
@ -23,8 +23,6 @@
|
||||
#define RESTORE_VERSION_MIN 320
|
||||
#define RESTORE_VERSION_CUR 320
|
||||
|
||||
u64 get_lowest_words_done (const hashcat_ctx_t *hashcat_ctx);
|
||||
|
||||
int cycle_restore (hashcat_ctx_t *hashcat_ctx);
|
||||
|
||||
void unlink_restore (hashcat_ctx_t *hashcat_ctx);
|
||||
|
@ -1370,9 +1370,11 @@ typedef struct status_ctx
|
||||
* workload
|
||||
*/
|
||||
|
||||
u64 words_cnt;
|
||||
u64 words_cur;
|
||||
u64 words_base;
|
||||
u64 words_off; // used by dispatcher; get_work () as offset; attention: needs to be redone on in restore case!
|
||||
u64 words_cur; // used by dispatcher; the different to words_cur_next is that this counter guarantees that the work from zero to this counter has been actually computed
|
||||
// has been finished actually, can be used for restore point therefore
|
||||
u64 words_base; // the unamplified max keyspace
|
||||
u64 words_cnt; // the amplified max keyspace
|
||||
|
||||
/**
|
||||
* progress
|
||||
|
@ -34,6 +34,33 @@
|
||||
#include "event.h"
|
||||
#include "dispatch.h"
|
||||
|
||||
static u64 get_lowest_words_done (const hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
||||
|
||||
u64 words_cur = 0xffffffffffffffff;
|
||||
|
||||
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
|
||||
{
|
||||
hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id];
|
||||
|
||||
if (device_param->skipped) continue;
|
||||
|
||||
const u64 words_done = device_param->words_done;
|
||||
|
||||
if (words_done < words_cur) words_cur = words_done;
|
||||
}
|
||||
|
||||
// It's possible that a device's workload isn't finished right after a restore-case.
|
||||
// In that case, this function would return 0 and overwrite the real restore point
|
||||
|
||||
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||
|
||||
if (words_cur < status_ctx->words_cur) words_cur = status_ctx->words_cur;
|
||||
|
||||
return words_cur;
|
||||
}
|
||||
|
||||
static int set_kernel_power_final (hashcat_ctx_t *hashcat_ctx, const u32 kernel_power_final)
|
||||
{
|
||||
EVENT (EVENT_SET_KERNEL_POWER_FINAL);
|
||||
@ -65,7 +92,7 @@ static u32 get_power (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param)
|
||||
return device_param->kernel_power;
|
||||
}
|
||||
|
||||
static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 max)
|
||||
static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 max)
|
||||
{
|
||||
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
||||
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||
@ -73,14 +100,14 @@ static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
|
||||
|
||||
hc_thread_mutex_lock (status_ctx->mux_dispatcher);
|
||||
|
||||
const u64 words_cur = status_ctx->words_cur;
|
||||
const u64 words_off = status_ctx->words_off;
|
||||
const u64 words_base = (user_options->limit == 0) ? status_ctx->words_base : MIN (user_options->limit, status_ctx->words_base);
|
||||
|
||||
device_param->words_off = words_cur;
|
||||
device_param->words_off = words_off;
|
||||
|
||||
const u64 kernel_power_all = opencl_ctx->kernel_power_all;
|
||||
|
||||
const u64 words_left = words_base - words_cur;
|
||||
const u64 words_left = words_base - words_off;
|
||||
|
||||
if (words_left < kernel_power_all)
|
||||
{
|
||||
@ -96,7 +123,7 @@ static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param
|
||||
|
||||
work = MIN (work, max);
|
||||
|
||||
status_ctx->words_cur += work;
|
||||
status_ctx->words_off += work;
|
||||
|
||||
hc_thread_mutex_unlock (status_ctx->mux_dispatcher);
|
||||
|
||||
@ -127,9 +154,9 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
|
||||
break;
|
||||
}
|
||||
|
||||
u32 words_cur = 0;
|
||||
u32 words_buffered = 0;
|
||||
|
||||
while (words_cur < device_param->kernel_power)
|
||||
while (words_buffered < device_param->kernel_power)
|
||||
{
|
||||
char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, stdin);
|
||||
|
||||
@ -184,7 +211,7 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
|
||||
|
||||
pw_add (device_param, (u8 *) line_buf, (int) line_len);
|
||||
|
||||
words_cur++;
|
||||
words_buffered++;
|
||||
|
||||
while (status_ctx->run_thread_level1 == false) break;
|
||||
}
|
||||
@ -303,11 +330,13 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
||||
device_param->pws_cnt = 0;
|
||||
}
|
||||
|
||||
if (status_ctx->run_thread_level1 == false) break;
|
||||
|
||||
if (user_options->speed_only == true) break;
|
||||
|
||||
device_param->words_done = words_fin;
|
||||
|
||||
status_ctx->words_cur = get_lowest_words_done (hashcat_ctx);
|
||||
|
||||
if (status_ctx->run_thread_level1 == false) break;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -418,15 +447,15 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
||||
u64 words_off = 0;
|
||||
u64 words_fin = 0;
|
||||
|
||||
u64 max = -1llu;
|
||||
u32 words_extra = -1u;
|
||||
|
||||
while (max)
|
||||
while (words_extra)
|
||||
{
|
||||
const u32 work = get_work (hashcat_ctx, device_param, max);
|
||||
const u32 work = get_work (hashcat_ctx, device_param, words_extra);
|
||||
|
||||
if (work == 0) break;
|
||||
|
||||
max = 0;
|
||||
words_extra = 0;
|
||||
|
||||
words_off = device_param->words_off;
|
||||
words_fin = words_off + work;
|
||||
@ -465,7 +494,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
||||
{
|
||||
if ((line_len < hashconfig->pw_min) || (line_len > hashconfig->pw_max))
|
||||
{
|
||||
max++;
|
||||
words_extra++;
|
||||
|
||||
hc_thread_mutex_lock (status_ctx->mux_counter);
|
||||
|
||||
@ -486,7 +515,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
||||
|
||||
if (line_len > hashconfig->pw_max)
|
||||
{
|
||||
max++;
|
||||
words_extra++;
|
||||
|
||||
hc_thread_mutex_lock (status_ctx->mux_counter);
|
||||
|
||||
@ -550,11 +579,13 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
|
||||
|
||||
if (user_options->speed_only == true) break;
|
||||
|
||||
device_param->words_done = words_fin;
|
||||
|
||||
status_ctx->words_cur = get_lowest_words_done (hashcat_ctx);
|
||||
|
||||
if (status_ctx->run_thread_level1 == false) break;
|
||||
|
||||
if (words_fin == 0) break;
|
||||
|
||||
device_param->words_done = words_fin;
|
||||
}
|
||||
|
||||
if (attack_mode == ATTACK_MODE_COMBI)
|
||||
|
@ -82,20 +82,25 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
status_progress_reset (hashcat_ctx);
|
||||
|
||||
status_ctx->words_off = 0;
|
||||
status_ctx->words_cur = 0;
|
||||
|
||||
restore_data_t *rd = restore_ctx->rd;
|
||||
|
||||
if (rd->words_cur)
|
||||
{
|
||||
status_ctx->words_cur = rd->words_cur;
|
||||
status_ctx->words_off = rd->words_cur;
|
||||
status_ctx->words_cur = status_ctx->words_off;
|
||||
|
||||
rd->words_cur = 0;
|
||||
|
||||
user_options->skip = 0;
|
||||
}
|
||||
|
||||
if (user_options->skip)
|
||||
{
|
||||
status_ctx->words_cur = user_options->skip;
|
||||
status_ctx->words_off = user_options->skip;
|
||||
status_ctx->words_cur = status_ctx->words_off;
|
||||
|
||||
user_options->skip = 0;
|
||||
}
|
||||
@ -128,21 +133,18 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
// restore stuff
|
||||
|
||||
if (status_ctx->words_cur > status_ctx->words_base)
|
||||
if (status_ctx->words_off > status_ctx->words_base)
|
||||
{
|
||||
event_log_error (hashcat_ctx, "Restore value greater keyspace");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (status_ctx->words_cur)
|
||||
{
|
||||
const u64 progress_restored = status_ctx->words_cur * user_options_extra_amplifier (hashcat_ctx);
|
||||
const u64 progress_restored = status_ctx->words_off * user_options_extra_amplifier (hashcat_ctx);
|
||||
|
||||
for (u32 i = 0; i < hashes->salts_cnt; i++)
|
||||
{
|
||||
status_ctx->words_progress_restored[i] = progress_restored;
|
||||
}
|
||||
for (u32 i = 0; i < hashes->salts_cnt; i++)
|
||||
{
|
||||
status_ctx->words_progress_restored[i] = progress_restored;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,13 +264,6 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
EVENT (EVENT_CRACKER_FINISHED);
|
||||
|
||||
// no more skip and restore from here
|
||||
|
||||
if (status_ctx->devices_status == STATUS_EXHAUSTED)
|
||||
{
|
||||
rd->words_cur = 0;
|
||||
}
|
||||
|
||||
// mark sub logfile
|
||||
|
||||
logfile_sub_var_uint ("status-after-work", status_ctx->devices_status);
|
||||
|
@ -19,39 +19,6 @@ static void fsync (int fd)
|
||||
}
|
||||
#endif
|
||||
|
||||
u64 get_lowest_words_done (const hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
|
||||
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
|
||||
|
||||
if (restore_ctx->enabled == false) return 0;
|
||||
|
||||
restore_data_t *rd = restore_ctx->rd;
|
||||
|
||||
u64 words_cur = 0xffffffffffffffff;
|
||||
|
||||
for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++)
|
||||
{
|
||||
hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id];
|
||||
|
||||
if (device_param->skipped) continue;
|
||||
|
||||
const u64 words_done = device_param->words_done;
|
||||
|
||||
if (words_done < words_cur) words_cur = words_done;
|
||||
}
|
||||
|
||||
// It's possible that a device's workload isn't finished right after a restore-case.
|
||||
// In that case, this function would return 0 and overwrite the real restore point
|
||||
// There's also status_ctx->words_cur which is set to rd->words_cur but it changes while
|
||||
// the attack is running therefore we should stick to rd->words_cur.
|
||||
// Note that -s influences rd->words_cur we should keep a close look on that.
|
||||
|
||||
if (words_cur < rd->words_cur) words_cur = rd->words_cur;
|
||||
|
||||
return words_cur;
|
||||
}
|
||||
|
||||
static int check_running_process (hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
|
||||
@ -255,14 +222,13 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx)
|
||||
static int write_restore (hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
|
||||
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||
|
||||
if (restore_ctx->enabled == false) return 0;
|
||||
|
||||
const u64 words_cur = get_lowest_words_done (hashcat_ctx);
|
||||
|
||||
restore_data_t *rd = restore_ctx->rd;
|
||||
|
||||
rd->words_cur = words_cur;
|
||||
rd->words_cur = status_ctx->words_cur;
|
||||
|
||||
char *new_restore_file = restore_ctx->new_restore_file;
|
||||
|
||||
@ -357,6 +323,20 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
|
||||
|
||||
restore_ctx->enabled = false;
|
||||
|
||||
if (user_options->benchmark == true) return 0;
|
||||
if (user_options->keyspace == true) return 0;
|
||||
if (user_options->left == true) return 0;
|
||||
if (user_options->opencl_info == true) return 0;
|
||||
if (user_options->show == true) return 0;
|
||||
if (user_options->stdout_flag == true) return 0;
|
||||
if (user_options->speed_only == true) return 0;
|
||||
if (user_options->usage == true) return 0;
|
||||
if (user_options->version == true) return 0;
|
||||
if (user_options->restore_disable == true) return 0;
|
||||
|
||||
if (argc == 0) return 0;
|
||||
if (argv == NULL) return 0;
|
||||
|
||||
char *eff_restore_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (eff_restore_file);
|
||||
char *new_restore_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (new_restore_file);
|
||||
|
||||
@ -373,20 +353,6 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
|
||||
|
||||
if (rc_init_restore == -1) return -1;
|
||||
|
||||
if (argc == 0) return 0;
|
||||
if (argv == NULL) return 0;
|
||||
|
||||
if (user_options->benchmark == true) return 0;
|
||||
if (user_options->keyspace == true) return 0;
|
||||
if (user_options->left == true) return 0;
|
||||
if (user_options->opencl_info == true) return 0;
|
||||
if (user_options->show == true) return 0;
|
||||
if (user_options->stdout_flag == true) return 0;
|
||||
if (user_options->speed_only == true) return 0;
|
||||
if (user_options->usage == true) return 0;
|
||||
if (user_options->version == true) return 0;
|
||||
if (user_options->restore_disable == true) return 0;
|
||||
|
||||
restore_ctx->enabled = true;
|
||||
|
||||
if (user_options->restore == true)
|
||||
@ -424,12 +390,12 @@ void restore_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
|
||||
|
||||
if (restore_ctx->enabled == false) return;
|
||||
|
||||
hcfree (restore_ctx->eff_restore_file);
|
||||
hcfree (restore_ctx->new_restore_file);
|
||||
|
||||
hcfree (restore_ctx->rd);
|
||||
|
||||
if (restore_ctx->enabled == false) return;
|
||||
|
||||
memset (restore_ctx, 0, sizeof (restore_ctx_t));
|
||||
}
|
||||
|
@ -858,7 +858,9 @@ char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
u64 status_get_restore_point (const hashcat_ctx_t *hashcat_ctx)
|
||||
{
|
||||
const u64 restore_point = get_lowest_words_done (hashcat_ctx);
|
||||
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||
|
||||
const u64 restore_point = status_ctx->words_cur;
|
||||
|
||||
return restore_point;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user