mirror of
https://github.com/hashcat/hashcat.git
synced 2025-05-22 08:48:49 +00:00
JSON-escape example_hash in hash info
This commit is contained in:
parent
bd3aca92f9
commit
c430942676
@ -634,6 +634,37 @@ void compress_terminal_line_length (char *out_buf, const size_t keep_from_beginn
|
|||||||
*ptr1 = 0;
|
*ptr1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void json_encode (char *text, char *escaped)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Based on https://www.freeformatter.com/json-escape.html, below these 7 different chars
|
||||||
|
* are getting escaped before being printed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
size_t len = strlen (text);
|
||||||
|
unsigned long i, j;
|
||||||
|
|
||||||
|
for (i = 0, j = 0; i < len; i++, j++)
|
||||||
|
{
|
||||||
|
char c = text[i];
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '\b': c = 'b'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '\t': c = 't'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '\n': c = 'n'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '\f': c = 'f'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '\r': c = 'r'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '\\': c = '\\'; escaped[j] = '\\'; j++; break;
|
||||||
|
case '"': c = '"'; escaped[j] = '\\'; j++; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
escaped[j] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
escaped[j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void hash_info_single_json (hashcat_ctx_t *hashcat_ctx, user_options_extra_t *user_options_extra)
|
void hash_info_single_json (hashcat_ctx_t *hashcat_ctx, user_options_extra_t *user_options_extra)
|
||||||
{
|
{
|
||||||
if (hashconfig_init (hashcat_ctx) == 0)
|
if (hashconfig_init (hashcat_ctx) == 0)
|
||||||
@ -692,14 +723,20 @@ void hash_info_single_json (hashcat_ctx_t *hashcat_ctx, user_options_extra_t *us
|
|||||||
{
|
{
|
||||||
printf ("\"example_hash_format\": \"%s\", ", "hex-encoded (binary file only)");
|
printf ("\"example_hash_format\": \"%s\", ", "hex-encoded (binary file only)");
|
||||||
}
|
}
|
||||||
printf ("\"example_hash\": \"%s\", ", hashconfig->st_hash);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf ("\"example_hash_format\": \"%s\", ", "plain");
|
printf ("\"example_hash_format\": \"%s\", ", "plain");
|
||||||
printf ("\"example_hash\": \"%s\", ", hashconfig->st_hash);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *example_hash_json_encoded = (char *) hcmalloc (strlen (hashconfig->st_hash) * 2);
|
||||||
|
|
||||||
|
json_encode ((char *)hashconfig->st_hash, example_hash_json_encoded);
|
||||||
|
|
||||||
|
printf ("\"example_hash\": \"%s\", ", example_hash_json_encoded);
|
||||||
|
|
||||||
|
hcfree (example_hash_json_encoded);
|
||||||
|
|
||||||
if (need_hexify ((const u8 *) hashconfig->st_pass, strlen (hashconfig->st_pass), user_options_extra->separator, false))
|
if (need_hexify ((const u8 *) hashconfig->st_pass, strlen (hashconfig->st_pass), user_options_extra->separator, false))
|
||||||
{
|
{
|
||||||
char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
char *tmp_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
||||||
@ -1760,37 +1797,6 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx)
|
|||||||
hcfree (hashcat_status);
|
hcfree (hashcat_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void json_encode (char *text, char *escaped)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Based on https://www.freeformatter.com/json-escape.html, below these 7 different chars
|
|
||||||
* are getting escaped before being printed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
size_t len = strlen (text);
|
|
||||||
unsigned long i, j;
|
|
||||||
|
|
||||||
for (i = 0, j = 0; i < len; i++, j++)
|
|
||||||
{
|
|
||||||
char c = text[i];
|
|
||||||
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '\b': c = 'b'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '\t': c = 't'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '\n': c = 'n'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '\f': c = 'f'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '\r': c = 'r'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '\\': c = '\\'; escaped[j] = '\\'; j++; break;
|
|
||||||
case '"': c = '"'; escaped[j] = '\\'; j++; break;
|
|
||||||
}
|
|
||||||
|
|
||||||
escaped[j] = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
escaped[j] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void status_display_status_json (hashcat_ctx_t *hashcat_ctx)
|
void status_display_status_json (hashcat_ctx_t *hashcat_ctx)
|
||||||
{
|
{
|
||||||
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
const status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
||||||
|
Loading…
Reference in New Issue
Block a user