From 6dc72ebcc570ba15df808a42c43d98f8fe3199e4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 3 Aug 2019 19:09:07 -0700 Subject: [PATCH] Run through Clang's readability-else-after-return There's no need for a return statement in an else path. Just take it out. Simplifies the code slightly. --- src/backend.c | 64 +++++++++---------- src/benchmark.c | 26 ++++---- src/brain.c | 144 ++++++++++++++++++++--------------------- src/potfile.c | 10 ++- src/status.c | 155 ++++++++++++++++----------------------------- src/user_options.c | 30 ++++----- 6 files changed, 182 insertions(+), 247 deletions(-) diff --git a/src/backend.c b/src/backend.c index c3d0d1ec2..8b50941e8 100644 --- a/src/backend.c +++ b/src/backend.c @@ -4532,44 +4532,42 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co break; } + + double total_msec = device_param->speed_msec[0]; + + for (u32 speed_pos = 1; speed_pos < device_param->speed_pos; speed_pos++) + { + total_msec += device_param->speed_msec[speed_pos]; + } + + if (user_options->slow_candidates == true) + { + if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1)) + { + const u32 speed_pos = device_param->speed_pos; + + if (speed_pos) + { + device_param->speed_cnt[0] = device_param->speed_cnt[speed_pos - 1]; + device_param->speed_msec[0] = device_param->speed_msec[speed_pos - 1]; + } + + device_param->speed_pos = 0; + + device_param->speed_only_finish = true; + + break; + } + } else { - double total_msec = device_param->speed_msec[0]; + // it's unclear if 4s is enough to turn on boost mode for all backend device - for (u32 speed_pos = 1; speed_pos < device_param->speed_pos; speed_pos++) + if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1)) { - total_msec += device_param->speed_msec[speed_pos]; - } + device_param->speed_only_finish = true; - if (user_options->slow_candidates == true) - { - if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1)) - { - const u32 speed_pos = device_param->speed_pos; - - if (speed_pos) - { - device_param->speed_cnt[0] = device_param->speed_cnt[speed_pos - 1]; - device_param->speed_msec[0] = device_param->speed_msec[speed_pos - 1]; - } - - device_param->speed_pos = 0; - - device_param->speed_only_finish = true; - - break; - } - } - else - { - // it's unclear if 4s is enough to turn on boost mode for all backend device - - if ((total_msec > 4000) || (device_param->speed_pos == SPEED_CACHE - 1)) - { - device_param->speed_only_finish = true; - - break; - } + break; } } } diff --git a/src/benchmark.c b/src/benchmark.c index 78f7d9f08..05f0c35a6 100644 --- a/src/benchmark.c +++ b/src/benchmark.c @@ -57,28 +57,26 @@ int benchmark_next (hashcat_ctx_t *hashcat_ctx) return hash_mode; } - else + + char *modulefile = (char *) hcmalloc (HCBUFSIZ_TINY); + + for (int i = cur; i < MODULE_HASH_MODES_MAXIMUM; i++) { - char *modulefile = (char *) hcmalloc (HCBUFSIZ_TINY); + module_filename (folder_config, i, modulefile, HCBUFSIZ_TINY); - for (int i = cur; i < MODULE_HASH_MODES_MAXIMUM; i++) + if (hc_path_exist (modulefile) == true) { - module_filename (folder_config, i, modulefile, HCBUFSIZ_TINY); + const int hash_mode = i; - if (hc_path_exist (modulefile) == true) - { - const int hash_mode = i; + cur = hash_mode + 1; - cur = hash_mode + 1; + hcfree (modulefile); - hcfree (modulefile); - - return hash_mode; - } + return hash_mode; } - - hcfree (modulefile); } + hcfree (modulefile); + return -1; } diff --git a/src/brain.c b/src/brain.c index 02c20b78e..d67170cd4 100644 --- a/src/brain.c +++ b/src/brain.c @@ -1589,36 +1589,34 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash, return false; } - else + + i64 temp_cnt = (u64) sb.st_size / sizeof (brain_server_hash_long_t); + + if (brain_server_db_hash_realloc (brain_server_db_hash, temp_cnt) == false) { - i64 temp_cnt = (u64) sb.st_size / sizeof (brain_server_hash_long_t); - - if (brain_server_db_hash_realloc (brain_server_db_hash, temp_cnt) == false) - { - brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); - - hc_fclose (&fp); - - return false; - } - - const size_t nread = hc_fread (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), temp_cnt, &fp); - - if (nread != (size_t) temp_cnt) - { - brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_hash_long_t)); - - hc_fclose (&fp); - - return false; - } - - brain_server_db_hash->long_cnt = temp_cnt; - brain_server_db_hash->write_hashes = false; + brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); hc_fclose (&fp); + + return false; } + const size_t nread = hc_fread (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), temp_cnt, &fp); + + if (nread != (size_t) temp_cnt) + { + brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_hash_long_t)); + + hc_fclose (&fp); + + return false; + } + + brain_server_db_hash->long_cnt = temp_cnt; + brain_server_db_hash->write_hashes = false; + + hc_fclose (&fp); + const double ms = hc_timer_get (timer_dump); brain_logging (stdout, 0, "Read %" PRIu64 " bytes from session 0x%08x in %.2f ms\n", (u64) sb.st_size, brain_server_db_hash->brain_session, ms); @@ -1644,24 +1642,22 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash, return false; } - else + + const size_t nwrite = hc_fwrite (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), brain_server_db_hash->long_cnt, &fp); + + if (nwrite != (size_t) brain_server_db_hash->long_cnt) { - const size_t nwrite = hc_fwrite (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), brain_server_db_hash->long_cnt, &fp); - - if (nwrite != (size_t) brain_server_db_hash->long_cnt) - { - brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_hash_long_t)); - - hc_fclose (&fp); - - return false; - } + brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_hash_long_t)); hc_fclose (&fp); - brain_server_db_hash->write_hashes = false; + return false; } + hc_fclose (&fp); + + brain_server_db_hash->write_hashes = false; + // stats const double ms = hc_timer_get (timer_dump); @@ -1790,36 +1786,34 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at return false; } - else + + i64 temp_cnt = (u64) sb.st_size / sizeof (brain_server_attack_long_t); + + if (brain_server_db_attack_realloc (brain_server_db_attack, temp_cnt, 0) == false) { - i64 temp_cnt = (u64) sb.st_size / sizeof (brain_server_attack_long_t); - - if (brain_server_db_attack_realloc (brain_server_db_attack, temp_cnt, 0) == false) - { - brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); - - hc_fclose (&fp); - - return false; - } - - const size_t nread = hc_fread (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), temp_cnt, &fp); - - if (nread != (size_t) temp_cnt) - { - brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_attack_long_t)); - - hc_fclose (&fp); - - return false; - } - - brain_server_db_attack->long_cnt = temp_cnt; - brain_server_db_attack->write_attacks = false; + brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); hc_fclose (&fp); + + return false; } + const size_t nread = hc_fread (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), temp_cnt, &fp); + + if (nread != (size_t) temp_cnt) + { + brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_attack_long_t)); + + hc_fclose (&fp); + + return false; + } + + brain_server_db_attack->long_cnt = temp_cnt; + brain_server_db_attack->write_attacks = false; + + hc_fclose (&fp); + const double ms = hc_timer_get (timer_dump); brain_logging (stdout, 0, "Read %" PRIu64 " bytes from attack 0x%08x in %.2f ms\n", (u64) sb.st_size, brain_server_db_attack->brain_attack, ms); @@ -1845,26 +1839,24 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a return false; } - else + + // storing should not include reserved attacks only finished + + const size_t nwrite = hc_fwrite (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), brain_server_db_attack->long_cnt, &fp); + + if (nwrite != (size_t) brain_server_db_attack->long_cnt) { - // storing should not include reserved attacks only finished - - const size_t nwrite = hc_fwrite (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), brain_server_db_attack->long_cnt, &fp); - - if (nwrite != (size_t) brain_server_db_attack->long_cnt) - { - brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_attack_long_t)); - - hc_fclose (&fp); - - return false; - } + brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_attack_long_t)); hc_fclose (&fp); - brain_server_db_attack->write_attacks = false; + return false; } + hc_fclose (&fp); + + brain_server_db_attack->write_attacks = false; + // stats const double ms = hc_timer_get (timer_dump); diff --git a/src/potfile.c b/src/potfile.c index b0726107a..866548bff 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -576,12 +576,10 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) continue; } - else - { - // should be rejected? - //const int parser_status = module_ctx->module_hash_decode_potfile (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info, line_hash_buf, line_hash_len, NULL); - //if (parser_status != PARSER_OK) continue; - } + + // should be rejected? + //const int parser_status = module_ctx->module_hash_decode_potfile (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info, line_hash_buf, line_hash_len, NULL); + //if (parser_status != PARSER_OK) continue; } else { diff --git a/src/status.c b/src/status.c index 8ece2d694..c8b95a809 100644 --- a/src/status.c +++ b/src/status.c @@ -327,34 +327,28 @@ char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx) return tmp_buf2; } - else + + if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) { - if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) - { - return hcstrdup (hashes->hashfile); - } - else - { - char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - - const int tmp_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0); - - tmp_buf[tmp_len] = 0; - - compress_terminal_line_length (tmp_buf, 19, 6); // 19 = strlen ("Hash.Target......: ") - - char *tmp_buf2 = strdup (tmp_buf); - - free (tmp_buf); - - return tmp_buf2; - } + return hcstrdup (hashes->hashfile); } + + char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); + + const int tmp_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0); + + tmp_buf[tmp_len] = 0; + + compress_terminal_line_length (tmp_buf, 19, 6); // 19 = strlen ("Hash.Target......: ") + + char *tmp_buf2 = strdup (tmp_buf); + + free (tmp_buf); + + return tmp_buf2; } - else - { - return hcstrdup (hashes->hashfile); - } + + return hcstrdup (hashes->hashfile); } int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) @@ -389,30 +383,21 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) { return GUESS_MODE_STRAIGHT_FILE_RULES_FILE; } - else if (has_rule_gen == true) + if (has_rule_gen == true) { return GUESS_MODE_STRAIGHT_FILE_RULES_GEN; } - else - { - return GUESS_MODE_STRAIGHT_FILE; - } + return GUESS_MODE_STRAIGHT_FILE; } - else + if (has_rule_file == true) { - if (has_rule_file == true) - { - return GUESS_MODE_STRAIGHT_STDIN_RULES_FILE; - } - else if (has_rule_gen == true) - { - return GUESS_MODE_STRAIGHT_STDIN_RULES_GEN; - } - else - { - return GUESS_MODE_STRAIGHT_STDIN; - } + return GUESS_MODE_STRAIGHT_STDIN_RULES_FILE; } + if (has_rule_gen == true) + { + return GUESS_MODE_STRAIGHT_STDIN_RULES_GEN; + } + return GUESS_MODE_STRAIGHT_STDIN; } if (user_options->attack_mode == ATTACK_MODE_COMBI) @@ -421,10 +406,7 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) { return GUESS_MODE_COMBINATOR_BASE_LEFT; } - else - { - return GUESS_MODE_COMBINATOR_BASE_RIGHT; - } + return GUESS_MODE_COMBINATOR_BASE_RIGHT; } if (user_options->attack_mode == ATTACK_MODE_BF) @@ -433,10 +415,7 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) { return GUESS_MODE_MASK_CS; } - else - { - return GUESS_MODE_MASK; - } + return GUESS_MODE_MASK; } if (user_options->attack_mode == ATTACK_MODE_HYBRID1) @@ -445,10 +424,7 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) { return GUESS_MODE_HYBRID1_CS; } - else - { - return GUESS_MODE_HYBRID1; - } + return GUESS_MODE_HYBRID1; } if (user_options->attack_mode == ATTACK_MODE_HYBRID2) @@ -457,10 +433,7 @@ int status_get_guess_mode (const hashcat_ctx_t *hashcat_ctx) { return GUESS_MODE_HYBRID2_CS; } - else - { - return GUESS_MODE_HYBRID2; - } + return GUESS_MODE_HYBRID2; } return GUESS_MODE_NONE; @@ -490,10 +463,7 @@ char *status_get_guess_base (const hashcat_ctx_t *hashcat_ctx) { return strdup (combinator_ctx->dict1); } - else - { - return strdup (combinator_ctx->dict2); - } + return strdup (combinator_ctx->dict2); } if (user_options->attack_mode == ATTACK_MODE_BF) @@ -518,14 +488,11 @@ char *status_get_guess_base (const hashcat_ctx_t *hashcat_ctx) return strdup (mask_ctx->mask); } - else - { - const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - return strdup (straight_ctx->dict); - } + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return strdup (straight_ctx->dict); } - return NULL; } @@ -568,12 +535,10 @@ int status_get_guess_base_offset (const hashcat_ctx_t *hashcat_ctx) return mask_ctx->masks_pos + 1; } - else - { - const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - return straight_ctx->dicts_pos + 1; - } + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return straight_ctx->dicts_pos + 1; } return 0; @@ -618,12 +583,10 @@ int status_get_guess_base_count (const hashcat_ctx_t *hashcat_ctx) return mask_ctx->masks_cnt; } - else - { - const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - return straight_ctx->dicts_cnt; - } + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return straight_ctx->dicts_cnt; } return 0; @@ -657,10 +620,7 @@ char *status_get_guess_mod (const hashcat_ctx_t *hashcat_ctx) { return strdup (combinator_ctx->dict2); } - else - { - return strdup (combinator_ctx->dict1); - } + return strdup (combinator_ctx->dict1); } if (user_options->attack_mode == ATTACK_MODE_BF) @@ -683,12 +643,10 @@ char *status_get_guess_mod (const hashcat_ctx_t *hashcat_ctx) return strdup (straight_ctx->dict); } - else - { - const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - return strdup (mask_ctx->mask); - } + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return strdup (mask_ctx->mask); } return NULL; @@ -729,12 +687,10 @@ int status_get_guess_mod_offset (const hashcat_ctx_t *hashcat_ctx) return straight_ctx->dicts_pos + 1; } - else - { - const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - return mask_ctx->masks_pos + 1; - } + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return mask_ctx->masks_pos + 1; } return 0; @@ -775,12 +731,10 @@ int status_get_guess_mod_count (const hashcat_ctx_t *hashcat_ctx) return straight_ctx->dicts_cnt; } - else - { - const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - return mask_ctx->masks_cnt; - } + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return mask_ctx->masks_cnt; } return 0; @@ -1196,10 +1150,7 @@ int status_get_progress_mode (const hashcat_ctx_t *hashcat_ctx) { return PROGRESS_MODE_KEYSPACE_KNOWN; } - else - { - return PROGRESS_MODE_KEYSPACE_UNKNOWN; - } + return PROGRESS_MODE_KEYSPACE_UNKNOWN; } double status_get_progress_finished_percent (const hashcat_ctx_t *hashcat_ctx) diff --git a/src/user_options.c b/src/user_options.c index 89a4b14b2..81078d074 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -1909,28 +1909,26 @@ u64 user_options_extra_amplifier (hashcat_ctx_t *hashcat_ctx) { return 1; } - else + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) + if (straight_ctx->kernel_rules_cnt) { - if (straight_ctx->kernel_rules_cnt) - { - return straight_ctx->kernel_rules_cnt; - } + return straight_ctx->kernel_rules_cnt; } - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) + } + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) + { + if (combinator_ctx->combs_cnt) { - if (combinator_ctx->combs_cnt) - { - return combinator_ctx->combs_cnt; - } + return combinator_ctx->combs_cnt; } - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) + } + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) + { + if (mask_ctx->bfs_cnt) { - if (mask_ctx->bfs_cnt) - { - return mask_ctx->bfs_cnt; - } + return mask_ctx->bfs_cnt; } }