2016-09-06 17:44:27 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-06 17:44:27 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-09-06 17:44:27 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "filehandling.h"
|
2016-12-23 23:40:40 +00:00
|
|
|
#include "shared.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "tuningdb.h"
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
int sort_by_tuning_db_alias (const void *v1, const void *v2)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
|
|
|
const tuning_db_alias_t *t1 = (const tuning_db_alias_t *) v1;
|
|
|
|
const tuning_db_alias_t *t2 = (const tuning_db_alias_t *) v2;
|
|
|
|
|
|
|
|
const int res1 = strcmp (t1->device_name, t2->device_name);
|
|
|
|
|
|
|
|
if (res1 != 0) return (res1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
int sort_by_tuning_db_entry (const void *v1, const void *v2)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
|
|
|
const tuning_db_entry_t *t1 = (const tuning_db_entry_t *) v1;
|
|
|
|
const tuning_db_entry_t *t2 = (const tuning_db_entry_t *) v2;
|
|
|
|
|
|
|
|
const int res1 = strcmp (t1->device_name, t2->device_name);
|
|
|
|
|
|
|
|
if (res1 != 0) return (res1);
|
|
|
|
|
|
|
|
const int res2 = t1->attack_mode
|
|
|
|
- t2->attack_mode;
|
|
|
|
|
|
|
|
if (res2 != 0) return (res2);
|
|
|
|
|
2019-02-12 14:30:42 +00:00
|
|
|
const int res3 = t1->hash_mode
|
|
|
|
- t2->hash_mode;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (res3 != 0) return (res3);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 14:51:01 +00:00
|
|
|
int tuning_db_init (hashcat_ctx_t *hashcat_ctx)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
2021-08-01 14:25:37 +00:00
|
|
|
folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
tuning_db_t *tuning_db = hashcat_ctx->tuning_db;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-06 14:51:01 +00:00
|
|
|
|
2016-09-30 10:58:06 +00:00
|
|
|
tuning_db->enabled = false;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-06-12 08:47:48 +00:00
|
|
|
if (user_options->hash_info == true) return 0;
|
|
|
|
if (user_options->keyspace == true) return 0;
|
|
|
|
if (user_options->left == true) return 0;
|
|
|
|
if (user_options->backend_info == true) return 0;
|
|
|
|
if (user_options->show == true) return 0;
|
|
|
|
if (user_options->usage == true) return 0;
|
|
|
|
if (user_options->version == true) return 0;
|
|
|
|
if (user_options->identify == true) return 0;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2016-09-30 10:58:06 +00:00
|
|
|
tuning_db->enabled = true;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2016-12-20 00:46:30 +00:00
|
|
|
char *tuning_db_file;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&tuning_db_file, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2019-06-26 17:06:46 +00:00
|
|
|
HCFILE fp;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2019-07-01 15:27:08 +00:00
|
|
|
if (hc_fopen (&fp, tuning_db_file, "rb") == false)
|
2016-09-30 10:58:06 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", tuning_db_file, strerror (errno));
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2016-09-30 10:58:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (tuning_db_file);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
int line_num = 0;
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2019-06-26 17:06:46 +00:00
|
|
|
while (!hc_feof (&fp))
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
2019-06-26 17:06:46 +00:00
|
|
|
char *line_buf = hc_fgets (buf, HCBUFSIZ_LARGE - 1, &fp);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (line_buf == NULL) break;
|
|
|
|
|
|
|
|
line_num++;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const size_t line_len = in_superchop (line_buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (line_len == 0) continue;
|
|
|
|
|
|
|
|
if (line_buf[0] == '#') continue;
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
tuning_db_process_line (hashcat_ctx, line_buf, line_num);
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hc_fclose (&fp);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
// todo: print loaded 'cnt' message
|
2016-11-16 09:35:01 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
// sort the database
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
qsort (tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
|
|
|
|
qsort (tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
void tuning_db_destroy (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
tuning_db_t *tuning_db = hashcat_ctx->tuning_db;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (tuning_db->enabled == false) return;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
int i;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
for (i = 0; i < tuning_db->alias_cnt; i++)
|
|
|
|
{
|
|
|
|
tuning_db_alias_t *alias = &tuning_db->alias_buf[i];
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (alias->device_name);
|
|
|
|
hcfree (alias->alias_name);
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
for (i = 0; i < tuning_db->entry_cnt; i++)
|
|
|
|
{
|
|
|
|
tuning_db_entry_t *entry = &tuning_db->entry_buf[i];
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree ((void *)entry->device_name);
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (tuning_db->alias_buf);
|
|
|
|
hcfree (tuning_db->entry_buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
memset (tuning_db, 0, sizeof (tuning_db_t));
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
bool tuning_db_process_line (hashcat_ctx_t *hashcat_ctx, const char *line_buf, const int line_num)
|
|
|
|
{
|
|
|
|
tuning_db_t *tuning_db = hashcat_ctx->tuning_db;
|
|
|
|
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
#define ADD_DB_ENTRIES 1
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (tuning_db->alias_cnt == tuning_db->alias_alloc)
|
|
|
|
{
|
|
|
|
tuning_db->alias_buf = (tuning_db_alias_t *) hcrealloc (tuning_db->alias_buf, tuning_db->alias_alloc * sizeof (tuning_db_alias_t), ADD_DB_ENTRIES * sizeof (tuning_db_alias_t));
|
|
|
|
tuning_db->alias_alloc += ADD_DB_ENTRIES;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (tuning_db->entry_cnt == tuning_db->entry_alloc)
|
|
|
|
{
|
|
|
|
tuning_db->entry_buf = (tuning_db_entry_t *) hcrealloc (tuning_db->entry_buf, tuning_db->entry_alloc * sizeof (tuning_db_entry_t), ADD_DB_ENTRIES * sizeof (tuning_db_entry_t));
|
|
|
|
tuning_db->entry_alloc += ADD_DB_ENTRIES;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
char *buf = hcstrdup (line_buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
char *token_ptr[7] = { NULL };
|
2017-08-23 10:43:59 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
int token_cnt = 0;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
char *saveptr = NULL;
|
2017-08-23 10:43:59 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
char *next = strtok_r (buf, "\t ", &saveptr);
|
2017-08-23 10:43:59 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
token_ptr[token_cnt] = next;
|
2017-08-23 10:43:59 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
token_cnt++;
|
2017-11-05 06:39:03 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
while ((next = strtok_r ((char *) NULL, "\t ", &saveptr)) != NULL)
|
|
|
|
{
|
|
|
|
token_ptr[token_cnt] = next;
|
2017-08-23 10:43:59 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
token_cnt++;
|
|
|
|
}
|
2017-11-05 06:39:03 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (token_cnt == 2)
|
|
|
|
{
|
|
|
|
char *device_name = token_ptr[0];
|
|
|
|
char *alias_name = token_ptr[1];
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
tuning_db_alias_t *alias = &tuning_db->alias_buf[tuning_db->alias_cnt];
|
|
|
|
|
|
|
|
alias->device_name = hcstrdup (device_name);
|
|
|
|
alias->alias_name = hcstrdup (alias_name);
|
|
|
|
|
|
|
|
tuning_db->alias_cnt++;
|
|
|
|
}
|
|
|
|
else if (token_cnt == 6)
|
|
|
|
{
|
|
|
|
if ((token_ptr[1][0] != '0') &&
|
|
|
|
(token_ptr[1][0] != '1') &&
|
|
|
|
(token_ptr[1][0] != '3') &&
|
|
|
|
(token_ptr[1][0] != '9') &&
|
|
|
|
(token_ptr[1][0] != '*'))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid attack_mode '%c' in Line '%d'", token_ptr[1][0], line_num);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((token_ptr[3][0] != '1') &&
|
|
|
|
(token_ptr[3][0] != '2') &&
|
|
|
|
(token_ptr[3][0] != '4') &&
|
|
|
|
(token_ptr[3][0] != '8') &&
|
|
|
|
(token_ptr[3][0] != 'N'))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid vector_width '%c' in Line '%d'", token_ptr[3][0], line_num);
|
|
|
|
|
|
|
|
hcfree (buf);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *device_name = token_ptr[0];
|
|
|
|
|
|
|
|
int attack_mode = -1;
|
|
|
|
int hash_mode = -1;
|
|
|
|
int vector_width = -1;
|
|
|
|
int kernel_accel = -1;
|
|
|
|
int kernel_loops = -1;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (token_ptr[1][0] != '*') attack_mode = (int) strtol (token_ptr[1], NULL, 10);
|
|
|
|
if (token_ptr[2][0] != '*') hash_mode = (int) strtol (token_ptr[2], NULL, 10);
|
|
|
|
if (token_ptr[3][0] != 'N') vector_width = (int) strtol (token_ptr[3], NULL, 10);
|
|
|
|
|
|
|
|
if (token_ptr[4][0] == 'A')
|
|
|
|
{
|
|
|
|
kernel_accel = 0;
|
|
|
|
}
|
|
|
|
else if (token_ptr[4][0] == 'M')
|
|
|
|
{
|
|
|
|
kernel_accel = 1024;
|
|
|
|
}
|
|
|
|
else if (token_ptr[4][0] == 'N')
|
|
|
|
{
|
|
|
|
kernel_accel = -1;
|
2016-09-06 17:44:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-01 14:25:37 +00:00
|
|
|
kernel_accel = (int) strtol (token_ptr[4], NULL, 10);
|
|
|
|
|
|
|
|
if ((kernel_accel < 1) || (kernel_accel > 1024))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_accel '%d' in Line '%d'", kernel_accel, line_num);
|
|
|
|
|
|
|
|
hcfree (buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (token_ptr[5][0] == 'A')
|
|
|
|
{
|
|
|
|
kernel_loops = 0;
|
|
|
|
}
|
|
|
|
else if (token_ptr[5][0] == 'M')
|
|
|
|
{
|
|
|
|
if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
|
|
|
|
{
|
|
|
|
kernel_loops = KERNEL_RULES;
|
|
|
|
}
|
|
|
|
else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
|
|
|
|
{
|
|
|
|
kernel_loops = KERNEL_COMBS;
|
|
|
|
}
|
|
|
|
else if (user_options_extra->attack_kern == ATTACK_KERN_BF)
|
|
|
|
{
|
|
|
|
kernel_loops = KERNEL_BFS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kernel_loops = (int) strtol (token_ptr[5], NULL, 10);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (kernel_loops < 1)
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%d'", kernel_loops, line_num);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if ((user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) && (kernel_loops > KERNEL_RULES))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%d'", kernel_loops, line_num);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-06 14:51:01 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if ((user_options_extra->attack_kern == ATTACK_KERN_COMBI) && (kernel_loops > KERNEL_COMBS))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%d'", kernel_loops, line_num);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if ((user_options_extra->attack_kern == ATTACK_KERN_BF) && (kernel_loops > KERNEL_BFS))
|
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%d'", kernel_loops, line_num);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tuning_db_entry_t *entry = &tuning_db->entry_buf[tuning_db->entry_cnt];
|
|
|
|
|
|
|
|
entry->device_name = hcstrdup (device_name);
|
|
|
|
entry->attack_mode = attack_mode;
|
|
|
|
entry->hash_mode = hash_mode;
|
|
|
|
entry->vector_width = vector_width;
|
|
|
|
entry->kernel_accel = kernel_accel;
|
|
|
|
entry->kernel_loops = kernel_loops;
|
|
|
|
|
|
|
|
tuning_db->entry_cnt++;
|
|
|
|
}
|
|
|
|
else
|
2016-09-30 10:58:06 +00:00
|
|
|
{
|
2021-08-01 14:25:37 +00:00
|
|
|
event_log_warning (hashcat_ctx, "Tuning-db: Invalid number of token in Line '%d'", line_num);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
|
|
|
|
|
|
|
return false;
|
2016-09-30 10:58:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
hcfree (buf);
|
2016-09-30 10:58:06 +00:00
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
return true;
|
2016-09-06 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
2021-04-16 19:48:16 +00:00
|
|
|
tuning_db_entry_t *tuning_db_search_real (hashcat_ctx_t *hashcat_ctx, const char *device_name, const cl_device_type device_type, int attack_mode, const int hash_mode)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
2016-10-06 14:51:01 +00:00
|
|
|
tuning_db_t *tuning_db = hashcat_ctx->tuning_db;
|
|
|
|
|
2016-09-06 17:44:27 +00:00
|
|
|
static tuning_db_entry_t s;
|
|
|
|
|
|
|
|
// first we need to convert all spaces in the device_name to underscore
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *device_name_nospace = hcstrdup (device_name);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const size_t device_name_length = strlen (device_name_nospace);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
size_t i;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
for (i = 0; i < device_name_length; i++)
|
|
|
|
{
|
|
|
|
if (device_name_nospace[i] == ' ') device_name_nospace[i] = '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
// find out if there's an alias configured
|
|
|
|
|
2021-04-23 18:53:48 +00:00
|
|
|
char *device_name_nospace2 = hcstrdup (device_name_nospace);
|
|
|
|
|
2016-09-06 17:44:27 +00:00
|
|
|
tuning_db_alias_t a;
|
|
|
|
|
2021-04-23 18:53:48 +00:00
|
|
|
a.device_name = device_name_nospace2;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2017-10-26 23:01:07 +00:00
|
|
|
char *alias_name = NULL;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2017-10-26 23:28:55 +00:00
|
|
|
for (i = device_name_length; i >= 1; i--)
|
2017-10-26 23:01:07 +00:00
|
|
|
{
|
2021-04-23 18:53:48 +00:00
|
|
|
device_name_nospace2[i] = 0;
|
2017-10-26 23:01:07 +00:00
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
tuning_db_alias_t *alias = (tuning_db_alias_t *) bsearch (&a, tuning_db->alias_buf, tuning_db->alias_cnt, sizeof (tuning_db_alias_t), sort_by_tuning_db_alias);
|
2017-10-26 23:01:07 +00:00
|
|
|
|
|
|
|
if (alias == NULL) continue;
|
|
|
|
|
|
|
|
alias_name = alias->alias_name;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2021-04-23 18:53:48 +00:00
|
|
|
hcfree (device_name_nospace2);
|
|
|
|
|
2016-09-06 17:44:27 +00:00
|
|
|
// attack-mode 6 and 7 are attack-mode 1 basically
|
|
|
|
|
|
|
|
if (attack_mode == 6) attack_mode = 1;
|
|
|
|
if (attack_mode == 7) attack_mode = 1;
|
|
|
|
|
|
|
|
// bsearch is not ideal but fast enough
|
|
|
|
|
|
|
|
s.device_name = device_name_nospace;
|
|
|
|
s.attack_mode = attack_mode;
|
2019-02-12 14:30:42 +00:00
|
|
|
s.hash_mode = hash_mode;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
tuning_db_entry_t *entry = NULL;
|
|
|
|
|
|
|
|
// this will produce all 2^3 combinations required
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
s.device_name = (i & 1) ? "*" : device_name_nospace;
|
|
|
|
s.attack_mode = (i & 2) ? -1 : attack_mode;
|
2019-02-12 14:30:42 +00:00
|
|
|
s.hash_mode = (i & 4) ? -1 : hash_mode;
|
2016-09-06 17:44:27 +00:00
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
entry = (tuning_db_entry_t *) bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (entry != NULL) break;
|
|
|
|
|
|
|
|
// in non-wildcard mode do some additional checks:
|
|
|
|
|
|
|
|
if ((i & 1) == 0)
|
|
|
|
{
|
|
|
|
// in case we have an alias-name
|
|
|
|
|
|
|
|
if (alias_name != NULL)
|
|
|
|
{
|
|
|
|
s.device_name = alias_name;
|
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
entry = (tuning_db_entry_t *) bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (entry != NULL) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// or by device type
|
|
|
|
|
2016-09-15 14:02:52 +00:00
|
|
|
if (device_type & CL_DEVICE_TYPE_CPU)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
|
|
|
s.device_name = "DEVICE_TYPE_CPU";
|
|
|
|
}
|
2016-09-15 14:02:52 +00:00
|
|
|
else if (device_type & CL_DEVICE_TYPE_GPU)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
|
|
|
s.device_name = "DEVICE_TYPE_GPU";
|
|
|
|
}
|
2016-09-15 14:02:52 +00:00
|
|
|
else if (device_type & CL_DEVICE_TYPE_ACCELERATOR)
|
2016-09-06 17:44:27 +00:00
|
|
|
{
|
|
|
|
s.device_name = "DEVICE_TYPE_ACCELERATOR";
|
|
|
|
}
|
|
|
|
|
2019-09-12 01:05:01 +00:00
|
|
|
entry = (tuning_db_entry_t *) bsearch (&s, tuning_db->entry_buf, tuning_db->entry_cnt, sizeof (tuning_db_entry_t), sort_by_tuning_db_entry);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
if (entry != NULL) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// free converted device_name
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (device_name_nospace);
|
2016-09-06 17:44:27 +00:00
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
2021-04-16 19:48:16 +00:00
|
|
|
|
|
|
|
tuning_db_entry_t *tuning_db_search (hashcat_ctx_t *hashcat_ctx, const char *device_name, const cl_device_type device_type, int attack_mode, const int hash_mode)
|
|
|
|
{
|
|
|
|
tuning_db_entry_t *entry;
|
|
|
|
|
|
|
|
const char *NV_prefix = (const char *) "NVIDIA ";
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
if (strncmp (device_name, NV_prefix, strlen (NV_prefix)) == 0)
|
2021-04-16 19:48:16 +00:00
|
|
|
{
|
|
|
|
entry = tuning_db_search_real (hashcat_ctx, device_name + strlen (NV_prefix), device_type, attack_mode, hash_mode);
|
|
|
|
|
|
|
|
if (entry) return entry;
|
|
|
|
}
|
|
|
|
|
2021-08-01 14:25:37 +00:00
|
|
|
const char *AMD_prefix = (const char *) "AMD ";
|
|
|
|
|
|
|
|
if (strncmp (device_name, AMD_prefix, strlen (AMD_prefix)) == 0)
|
|
|
|
{
|
|
|
|
entry = tuning_db_search_real (hashcat_ctx, device_name + strlen (AMD_prefix), device_type, attack_mode, hash_mode);
|
|
|
|
|
|
|
|
if (entry) return entry;
|
|
|
|
}
|
|
|
|
|
2021-04-16 19:48:16 +00:00
|
|
|
entry = tuning_db_search_real (hashcat_ctx, device_name, device_type, attack_mode, hash_mode);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|