1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-01-03 12:21:07 +00:00

Make it possible to access error messages without using an event

This commit is contained in:
jsteube 2016-10-13 19:16:24 +02:00
parent fc2d242f50
commit 8de576f5e9
4 changed files with 83 additions and 78 deletions

View File

@ -1400,7 +1400,11 @@ typedef struct hashcat_user
typedef struct event_ctx
{
int last_len;
char msg_buf[HCBUFSIZ_TINY];
int msg_len;
bool msg_newline;
int prev_len;
hc_thread_mutex_t mux_event;

View File

@ -47,15 +47,19 @@ size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
event_call (EVENT_LOG_INFO, hashcat_ctx, buf, len);
event_ctx->msg_newline = false;
return len;
event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0);
return event_ctx->msg_len;
}
size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
@ -64,15 +68,19 @@ size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
event_call (EVENT_LOG_WARNING, hashcat_ctx, buf, len);
event_ctx->msg_newline = false;
return len;
event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0);
return event_ctx->msg_len;
}
size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
@ -81,15 +89,19 @@ size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
event_call (EVENT_LOG_ERROR, hashcat_ctx, buf, len);
event_ctx->msg_newline = false;
return len;
event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0);
return event_ctx->msg_len;
}
size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
@ -98,28 +110,19 @@ size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
#if defined (_WIN)
event_ctx->msg_newline = true;
buf[len + 0] = '\r';
buf[len + 1] = '\n';
event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0);
event_call (EVENT_LOG_INFO, hashcat_ctx, buf, len + 2);
#else
buf[len] = '\n';
event_call (EVENT_LOG_INFO, hashcat_ctx, buf, len + 1);
#endif
return len;
return event_ctx->msg_len;
}
size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
@ -128,28 +131,19 @@ size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
#if defined (_WIN)
event_ctx->msg_newline = true;
buf[len + 0] = '\r';
buf[len + 1] = '\n';
event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0);
event_call (EVENT_LOG_WARNING, hashcat_ctx, buf, len + 2);
#else
buf[len] = '\n';
event_call (EVENT_LOG_WARNING, hashcat_ctx, buf, len + 1);
#endif
return len;
return event_ctx->msg_len;
}
size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
@ -158,28 +152,19 @@ size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
va_start (ap, fmt);
char buf[BUFSIZ];
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const size_t len = event_log (fmt, ap, buf, sizeof (buf));
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
event_ctx->msg_buf[event_ctx->msg_len] = 0;
va_end (ap);
#if defined (_WIN)
event_ctx->msg_newline = true;
buf[len + 0] = '\r';
buf[len + 1] = '\n';
event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0);
event_call (EVENT_LOG_ERROR, hashcat_ctx, buf, len + 2);
#else
buf[len] = '\n';
event_call (EVENT_LOG_ERROR, hashcat_ctx, buf, len + 1);
#endif
return len;
return event_ctx->msg_len;
}
int event_ctx_init (hashcat_ctx_t *hashcat_ctx)
@ -188,7 +173,7 @@ int event_ctx_init (hashcat_ctx_t *hashcat_ctx)
hc_thread_mutex_init (event_ctx->mux_event);
event_ctx->last_len = 0;
event_ctx->msg_len = 0;
return 0;
}
@ -199,5 +184,5 @@ void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
hc_thread_mutex_delete (event_ctx->mux_event);
event_ctx->last_len = 0;
event_ctx->msg_len = 0;
}

View File

@ -19,19 +19,23 @@
#include "interface.h"
#include "event.h"
static void main_log (hashcat_ctx_t *hashcat_ctx, const char *buf, const size_t len, FILE *fp)
static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp)
{
if (len == 0) return;
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const char *msg_buf = event_ctx->msg_buf;
const int msg_len = event_ctx->msg_len;
const bool msg_newline = event_ctx->msg_newline;
// handle last_len
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
const int prev_len = event_ctx->prev_len;
if (event_ctx->last_len)
if (prev_len)
{
fputc ('\r', fp);
for (int i = 0; i < event_ctx->last_len; i++)
for (int i = 0; i < prev_len; i++)
{
fputc (' ', fp);
}
@ -39,25 +43,30 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, const char *buf, const size_t
fputc ('\r', fp);
}
if (buf[len - 1] == '\n')
if (msg_newline == true)
{
event_ctx->last_len = 0;
event_ctx->prev_len = 0;
}
else
{
event_ctx->last_len = len;
event_ctx->prev_len = msg_len;
}
// finally, print
fwrite (buf, len, 1, fp);
fwrite (msg_buf, msg_len, 1, fp);
if (msg_newline == true)
{
fwrite (EOL, sizeof (EOL), 1, fp);
}
fflush (fp);
}
static void main_log_info (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
main_log (hashcat_ctx, buf, len, stdout);
main_log (hashcat_ctx, stdout);
}
static void main_log_warning (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
@ -66,7 +75,7 @@ static void main_log_warning (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNU
fwrite (PREFIX_WARNING, sizeof (PREFIX_WARNING), 1, stdout);
main_log (hashcat_ctx, buf, len, stdout);
main_log (hashcat_ctx, stdout);
}
static void main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
@ -75,7 +84,7 @@ static void main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSE
fwrite (PREFIX_ERROR, sizeof (PREFIX_ERROR), 1, stderr);
main_log (hashcat_ctx, buf, len, stderr);
main_log (hashcat_ctx, stderr);
}
static void main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)

View File

@ -4,12 +4,11 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "common.h"
#include "types.h"
#include "memory.h"
#include "event.h"
#include "user_options.h"
#include "hashcat.h"
@ -35,7 +34,9 @@ int main ()
{
// hashcat main context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx);
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t));
assert (hashcat_ctx);
const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event);
@ -74,6 +75,12 @@ int main ()
{
puts ("YAY, all hashes cracked!!");
}
else if (rc_hashcat == -1)
{
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
fprintf (stderr, "%s\n", event_ctx->msg_buf);
}
hashcat_ctx_destroy (hashcat_ctx);