2016-09-06 11:16:38 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-06 11:16:38 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-06 17:44:27 +00:00
|
|
|
#include "types.h"
|
2016-09-06 11:16:38 +00:00
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-11-05 10:33:29 +00:00
|
|
|
#include "locking.h"
|
2016-12-23 23:40:40 +00:00
|
|
|
#include "shared.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "logfile.h"
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-10-06 14:25:24 +00:00
|
|
|
void logfile_generate_topid (hashcat_ctx_t *hashcat_ctx)
|
2016-09-06 11:16:38 +00:00
|
|
|
{
|
2016-10-06 14:25:24 +00:00
|
|
|
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
if (logfile_ctx->enabled == false) return;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
struct timeval v;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
gettimeofday (&v, NULL);
|
2017-02-15 11:09:14 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
snprintf (logfile_ctx->topid, 40, "TOP.%08x.%08x", (u32) v.tv_sec, (u32) v.tv_usec);
|
2016-09-06 11:16:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:25:24 +00:00
|
|
|
void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx)
|
2016-09-06 11:16:38 +00:00
|
|
|
{
|
2016-10-06 14:25:24 +00:00
|
|
|
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
if (logfile_ctx->enabled == false) return;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
struct timeval v;
|
2017-02-15 11:09:14 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
gettimeofday (&v, NULL);
|
2016-09-23 19:41:05 +00:00
|
|
|
|
2017-11-05 06:33:06 +00:00
|
|
|
snprintf (logfile_ctx->subid, 40, "SUB.%08x.%08x", (u32) v.tv_sec, (u32) v.tv_usec);
|
2016-09-06 11:16:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:25:24 +00:00
|
|
|
void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
|
2016-09-06 11:16:38 +00:00
|
|
|
{
|
2016-10-06 14:25:24 +00:00
|
|
|
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
if (logfile_ctx->enabled == false) return;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
FILE *fp = fopen (logfile_ctx->logfile, "ab");
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-11-20 19:58:56 +00:00
|
|
|
if (fp == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno));
|
2016-11-20 19:58:56 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-05 10:33:29 +00:00
|
|
|
lock_file (fp);
|
|
|
|
|
2016-09-06 11:16:38 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
|
|
|
|
vfprintf (fp, fmt, ap);
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
|
2017-07-06 08:35:25 +00:00
|
|
|
hc_fwrite (EOL, strlen (EOL), 1, fp);
|
2016-09-06 11:16:38 +00:00
|
|
|
|
|
|
|
fflush (fp);
|
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
fclose (fp);
|
2016-09-06 11:16:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
int logfile_init (hashcat_ctx_t *hashcat_ctx)
|
2016-09-06 11:16:38 +00:00
|
|
|
{
|
2016-10-06 14:25:24 +00:00
|
|
|
folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
if (user_options->logfile_disable == true) return 0;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&logfile_ctx->logfile, "%s/%s.log", folder_config->session_dir, user_options->session);
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY);
|
|
|
|
logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-09-23 19:41:05 +00:00
|
|
|
logfile_ctx->enabled = true;
|
2016-10-06 15:26:15 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-06 11:16:38 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:25:24 +00:00
|
|
|
void logfile_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-06 11:16:38 +00:00
|
|
|
{
|
2016-10-06 14:25:24 +00:00
|
|
|
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
|
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
if (logfile_ctx->enabled == false) return;
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (logfile_ctx->logfile);
|
|
|
|
hcfree (logfile_ctx->topid);
|
|
|
|
hcfree (logfile_ctx->subid);
|
2016-09-06 11:16:38 +00:00
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
memset (logfile_ctx, 0, sizeof (logfile_ctx_t));
|
2016-09-06 11:16:38 +00:00
|
|
|
}
|