1
mirror of https://github.com/hashcat/hashcat synced 2024-12-23 14:13:43 +01:00

Make use of return length from ascii_digest instead of calling strlen()

This commit is contained in:
jsteube 2019-01-11 23:11:56 +01:00
parent 03f315a4ab
commit 26033e5787
7 changed files with 32 additions and 34 deletions

View File

@ -18,6 +18,6 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx);
void outfile_destroy (hashcat_ctx_t *hashcat_ctx);
int outfile_write_open (hashcat_ctx_t *hashcat_ctx);
void outfile_write_close (hashcat_ctx_t *hashcat_ctx);
int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]);
int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]);
#endif // _OUTFILE_H

View File

@ -18,7 +18,7 @@ int potfile_read_open (hashcat_ctx_t *hashcat_ctx);
void potfile_read_close (hashcat_ctx_t *hashcat_ctx);
int potfile_write_open (hashcat_ctx_t *hashcat_ctx);
void potfile_write_close (hashcat_ctx_t *hashcat_ctx);
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len);
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len);
int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx);
void potfile_destroy (hashcat_ctx_t *hashcat_ctx);
int potfile_handle_show (hashcat_ctx_t *hashcat_ctx);

View File

@ -114,7 +114,9 @@ u32 brain_compute_session (hashcat_ctx_t *hashcat_ctx)
for (u32 digest_idx = 0; digest_idx < salt_buf->digests_cnt; digest_idx++)
{
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salts_idx, digest_idx);
const int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salts_idx, digest_idx);
out_buf[out_len] = 0;
out_bufs[out_idx] = hcstrdup ((char *) out_buf);
}

View File

@ -209,9 +209,9 @@ int save_hash (hashcat_ctx_t *hashcat_ctx)
fputc (separator, fp);
}
out_buf[0] = 0;
const int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos);
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos);
out_buf[out_len] = 0;
fprintf (fp, "%s" EOL, out_buf);
}
@ -271,9 +271,9 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
u8 *out_buf = hashes->out_buf;
out_buf[0] = 0;
const int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos);
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos);
out_buf[out_len] = 0;
// plain
@ -316,7 +316,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
// no need for locking, we're in a mutex protected function
potfile_write_append (hashcat_ctx, (char *) out_buf, plain_ptr, plain_len);
potfile_write_append (hashcat_ctx, (char *) out_buf, out_len, plain_ptr, plain_len);
// outfile, can be either to file or stdout
// if an error occurs opening the file, send to stdout as fallback
@ -328,7 +328,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
tmp_buf[0] = 0;
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, plain_ptr, plain_len, crackpos, NULL, 0, (char *) tmp_buf);
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, plain_ptr, plain_len, crackpos, NULL, 0, (char *) tmp_buf);
outfile_write_close (hashcat_ctx);

View File

@ -426,7 +426,7 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx)
fclose (outfile_ctx->fp);
}
int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE])
int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE])
{
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
@ -455,8 +455,6 @@ int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsign
if (outfile_format & OUTFILE_FMT_HASH)
{
const size_t out_len = strlen (out_buf);
memcpy (tmp_buf + tmp_len, out_buf, out_len);
tmp_len += out_len;

View File

@ -238,7 +238,7 @@ void potfile_write_close (hashcat_ctx_t *hashcat_ctx)
fclose (potfile_ctx->fp);
}
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len)
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len)
{
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
@ -254,8 +254,6 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
if (1)
{
const size_t out_len = strlen (out_buf);
memcpy (tmp_buf + tmp_len, out_buf, out_len);
tmp_len += out_len;
@ -664,15 +662,15 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx)
u8 *out_buf = potfile_ctx->out_buf;
out_buf[0] = 0;
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
if (hash2)
{
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
out_len += ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
}
out_buf[out_len] = 0;
// user
unsigned char *username = NULL;
@ -726,7 +724,7 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx)
}
}
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, (u8 *) mixed_buf, mixed_len, 0, username, user_len, (char *) tmp_buf);
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, (u8 *) mixed_buf, mixed_len, 0, username, user_len, (char *) tmp_buf);
EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len);
}
@ -752,9 +750,9 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx)
u8 *out_buf = potfile_ctx->out_buf;
out_buf[0] = 0;
const int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
out_buf[out_len] = 0;
// user
unsigned char *username = NULL;
@ -801,11 +799,11 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx)
const size_t pass_unhexified_len = exec_unhexify ((u8 *) hash->pw_buf, hash->pw_len, pass_unhexified, sizeof (pass_unhexified));
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, pass_unhexified, (u32) pass_unhexified_len, 0, username, user_len, (char *) tmp_buf);
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, pass_unhexified, (u32) pass_unhexified_len, 0, username, user_len, (char *) tmp_buf);
}
else
{
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, (u8 *) hash->pw_buf, hash->pw_len, 0, username, user_len, (char *) tmp_buf);
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, (u8 *) hash->pw_buf, hash->pw_len, 0, username, user_len, (char *) tmp_buf);
}
EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len);
@ -872,15 +870,15 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx)
u8 *out_buf = potfile_ctx->out_buf;
out_buf[0] = 0;
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
if (hash2)
{
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
out_len += ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
}
out_buf[out_len] = 0;
// user
unsigned char *username = NULL;
@ -901,7 +899,7 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx)
tmp_buf[0] = 0;
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, NULL, 0, 0, username, user_len, (char *) tmp_buf);
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, NULL, 0, 0, username, user_len, (char *) tmp_buf);
EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len);
}
@ -925,9 +923,9 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx)
u8 *out_buf = potfile_ctx->out_buf;
out_buf[0] = 0;
const int out_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
out_buf[out_len] = 0;
hash_t *hash = &hashes_buf[hashes_idx];
@ -954,7 +952,7 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx)
tmp_buf[0] = 0;
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, NULL, 0, 0, username, user_len, (char *) tmp_buf);
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, NULL, 0, 0, username, user_len, (char *) tmp_buf);
EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len);
}

View File

@ -324,9 +324,9 @@ const char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx)
{
char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
tmp_buf[0] = 0;
const int tmp_len = ascii_digest (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, tmp_buf, HCBUFSIZ_LARGE, 0, 0);
ascii_digest (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......: ")