mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 08:08:10 +00:00
Add remaining --outfile-json code
This commit is contained in:
parent
e6715fbd89
commit
37175f5067
@ -503,6 +503,7 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx)
|
||||
outfile_ctx->filename = user_options->outfile;
|
||||
outfile_ctx->outfile_format = user_options->outfile_format;
|
||||
outfile_ctx->outfile_autohex = user_options->outfile_autohex;
|
||||
outfile_ctx->outfile_json = user_options->outfile_json;
|
||||
outfile_ctx->is_fifo = hc_path_is_fifo (outfile_ctx->filename);
|
||||
|
||||
return 0;
|
||||
@ -570,14 +571,80 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx)
|
||||
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, const bool print_eol, char *tmp_buf)
|
||||
{
|
||||
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
||||
const hashes_t *hashes = hashcat_ctx->hashes;
|
||||
const user_options_t *user_options = hashcat_ctx->user_options;
|
||||
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
||||
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||
|
||||
const u32 outfile_format = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_HEXIFY) ? 5 : outfile_ctx->outfile_format;
|
||||
|
||||
int tmp_len = 0;
|
||||
|
||||
if (outfile_ctx->outfile_json == true)
|
||||
{
|
||||
tmp_buf[0] = '{'; tmp_len += 1;
|
||||
|
||||
if (user_len > 0)
|
||||
{
|
||||
if (username != NULL)
|
||||
{
|
||||
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "\"username_hex\": ");
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_len += hex_encode ((const u8 *) username, user_len, (u8 *) tmp_buf + tmp_len);
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_buf[tmp_len] = ','; tmp_len += 1;
|
||||
tmp_buf[tmp_len] = ' '; tmp_len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hashes->hashlist_mode == HL_MODE_FILE_BINARY)
|
||||
{
|
||||
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "\"filename_hex\": ");
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_len += hex_encode ((const u8 *) hashes->hashfile, strlen (hashes->hashfile), (u8 *) tmp_buf + tmp_len);
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_buf[tmp_len] = ','; tmp_len += 1;
|
||||
tmp_buf[tmp_len] = ' '; tmp_len += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "\"hash_hex\": ");
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_len += hex_encode ((const u8 *) out_buf, out_len, (u8 *) tmp_buf + tmp_len);
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_buf[tmp_len] = ','; tmp_len += 1;
|
||||
tmp_buf[tmp_len] = ' '; tmp_len += 1;
|
||||
}
|
||||
|
||||
if (1) // plain
|
||||
{
|
||||
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "\"password_hex\": ");
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
|
||||
tmp_len += hex_encode ((const u8 *) plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len);
|
||||
|
||||
tmp_buf[tmp_len] = '"'; tmp_len += 1;
|
||||
}
|
||||
|
||||
tmp_buf[tmp_len] = '}';
|
||||
|
||||
tmp_len += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const u32 outfile_format = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_HEXIFY) ? 5 : outfile_ctx->outfile_format;
|
||||
|
||||
if (user_len > 0)
|
||||
{
|
||||
if (username != NULL)
|
||||
@ -711,6 +778,7 @@ int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int ou
|
||||
{
|
||||
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "%" PRIu64, crackpos);
|
||||
}
|
||||
}
|
||||
|
||||
tmp_buf[tmp_len] = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user