2016-10-08 21:16:40 +00:00
|
|
|
/**
|
|
|
|
* Author......: See docs/credits.txt
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "event.h"
|
|
|
|
|
2016-10-12 09:27:10 +00:00
|
|
|
void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len)
|
2016-10-08 21:16:40 +00:00
|
|
|
{
|
2016-10-23 15:31:22 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
bool is_log = false;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
2016-11-12 14:39:15 +00:00
|
|
|
case EVENT_LOG_INFO: is_log = true; break;
|
|
|
|
case EVENT_LOG_WARNING: is_log = true; break;
|
|
|
|
case EVENT_LOG_ERROR: is_log = true; break;
|
2017-03-25 19:50:37 +00:00
|
|
|
case EVENT_LOG_ADVICE: is_log = true; break;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-23 15:31:22 +00:00
|
|
|
if (is_log == false)
|
2016-10-08 21:16:40 +00:00
|
|
|
{
|
|
|
|
hc_thread_mutex_lock (event_ctx->mux_event);
|
|
|
|
}
|
|
|
|
|
2016-10-12 09:27:10 +00:00
|
|
|
hashcat_ctx->event (id, hashcat_ctx, buf, len);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-23 15:31:22 +00:00
|
|
|
if (is_log == false)
|
2016-10-08 21:16:40 +00:00
|
|
|
{
|
|
|
|
hc_thread_mutex_unlock (event_ctx->mux_event);
|
|
|
|
}
|
2016-10-23 15:31:22 +00:00
|
|
|
|
|
|
|
// add more back logs in case user wants to access them
|
|
|
|
|
|
|
|
if (is_log == false)
|
|
|
|
{
|
|
|
|
for (int i = MAX_OLD_EVENTS - 1; i >= 1; i--)
|
|
|
|
{
|
|
|
|
memcpy (event_ctx->old_buf[i], event_ctx->old_buf[i - 1], event_ctx->old_len[i - 1]);
|
|
|
|
|
|
|
|
event_ctx->old_len[i] = event_ctx->old_len[i - 1];
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
size_t copy_len = 0;
|
2017-11-18 11:18:56 +00:00
|
|
|
|
2016-11-11 14:30:31 +00:00
|
|
|
if (buf)
|
|
|
|
{
|
2017-11-18 11:18:56 +00:00
|
|
|
// truncate the whole buffer if needed (such that it fits into the old_buf):
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const size_t max_buf_len = sizeof (event_ctx->old_buf[0]);
|
2017-11-18 11:18:56 +00:00
|
|
|
|
|
|
|
copy_len = MIN (len, max_buf_len - 1);
|
|
|
|
|
|
|
|
memcpy (event_ctx->old_buf[0], buf, copy_len);
|
2016-11-11 14:30:31 +00:00
|
|
|
}
|
2016-10-23 15:31:22 +00:00
|
|
|
|
2017-11-18 11:18:56 +00:00
|
|
|
event_ctx->old_len[0] = copy_len;
|
2016-10-23 15:31:22 +00:00
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
2016-12-04 00:04:38 +00:00
|
|
|
__attribute__ ((format (printf, 1, 0)))
|
2016-10-08 21:16:40 +00:00
|
|
|
static int event_log (const char *fmt, va_list ap, char *s, const size_t sz)
|
|
|
|
{
|
2017-01-24 12:00:23 +00:00
|
|
|
size_t length;
|
|
|
|
|
|
|
|
length = vsnprintf (s, sz, fmt, ap);
|
|
|
|
length = MIN (length, sz);
|
|
|
|
|
|
|
|
s[length] = 0;
|
|
|
|
|
|
|
|
return (int) length;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:50:37 +00:00
|
|
|
size_t event_log_advice_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
|
|
|
|
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
|
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_ctx->msg_newline = false;
|
|
|
|
|
|
|
|
event_call (EVENT_LOG_ADVICE, hashcat_ctx, NULL, 0);
|
|
|
|
|
|
|
|
return event_ctx->msg_len;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:16:40 +00:00
|
|
|
size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
2016-10-13 17:16:24 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_start (ap, fmt);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = false;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0);
|
|
|
|
|
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
2016-10-13 17:16:24 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = false;
|
|
|
|
|
|
|
|
event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_start (ap, fmt);
|
2016-10-13 17:16:24 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = false;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0);
|
|
|
|
|
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 19:50:37 +00:00
|
|
|
size_t event_log_advice (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
|
|
|
|
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
|
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_ctx->msg_newline = true;
|
|
|
|
|
|
|
|
event_call (EVENT_LOG_ADVICE, hashcat_ctx, NULL, 0);
|
|
|
|
|
|
|
|
return event_ctx->msg_len;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:16:40 +00:00
|
|
|
size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_start (ap, fmt);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = true;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = true;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
|
|
|
{
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
if (fmt == NULL)
|
|
|
|
{
|
|
|
|
event_ctx->msg_buf[0] = 0;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
va_list ap;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_start (ap, fmt);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2017-02-11 10:51:46 +00:00
|
|
|
va_end (ap);
|
|
|
|
}
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_ctx->msg_newline = true;
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-13 17:16:24 +00:00
|
|
|
return event_ctx->msg_len;
|
2016-10-08 21:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int event_ctx_init (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
2016-10-23 15:31:22 +00:00
|
|
|
memset (event_ctx, 0, sizeof (event_ctx_t));
|
2016-10-08 21:16:40 +00:00
|
|
|
|
2016-10-23 15:31:22 +00:00
|
|
|
hc_thread_mutex_init (event_ctx->mux_event);
|
2016-10-08 21:16:40 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
event_ctx_t *event_ctx = hashcat_ctx->event_ctx;
|
|
|
|
|
|
|
|
hc_thread_mutex_delete (event_ctx->mux_event);
|
|
|
|
}
|