1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-13 19:28:56 +00:00
hashcat/src/logfile.c
2019-06-26 19:06:46 +02:00

111 lines
2.4 KiB
C

/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "memory.h"
#include "event.h"
#include "locking.h"
#include "shared.h"
#include "logfile.h"
void logfile_generate_topid (hashcat_ctx_t *hashcat_ctx)
{
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
if (logfile_ctx->enabled == false) return;
struct timeval v;
gettimeofday (&v, NULL);
snprintf (logfile_ctx->topid, 40, "TOP.%08x.%08x", (u32) v.tv_sec, (u32) v.tv_usec);
}
void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx)
{
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
if (logfile_ctx->enabled == false) return;
struct timeval v;
gettimeofday (&v, NULL);
snprintf (logfile_ctx->subid, 40, "SUB.%08x.%08x", (u32) v.tv_sec, (u32) v.tv_usec);
}
void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
{
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
if (logfile_ctx->enabled == false) return;
// FILE *fp = fopen (logfile_ctx->logfile, "ab");
HCFILE fp;
// if (fp == NULL)
if (hc_fopen (&fp, logfile_ctx->logfile, "ab") == false)
{
event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno));
return;
}
fp.is_gzip = 0;
// lock_file (fp);
lock_file (fp.f.fp);
va_list ap;
va_start (ap, fmt);
// vfprintf (fp, fmt, ap);
hc_vfprintf (&fp, fmt, ap);
va_end (ap);
// hc_fwrite (EOL, strlen (EOL), 1, fp);
hc_fwrite_compress (EOL, strlen (EOL), 1, &fp);
// fflush (fp);
hc_fflush (&fp);
// fclose (fp);
hc_fclose (&fp);
}
int logfile_init (hashcat_ctx_t *hashcat_ctx)
{
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;
if (user_options->logfile_disable == true) return 0;
hc_asprintf (&logfile_ctx->logfile, "%s/%s.log", folder_config->session_dir, user_options->session);
logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY);
logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY);
logfile_ctx->enabled = true;
return 0;
}
void logfile_destroy (hashcat_ctx_t *hashcat_ctx)
{
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
if (logfile_ctx->enabled == false) return;
hcfree (logfile_ctx->logfile);
hcfree (logfile_ctx->topid);
hcfree (logfile_ctx->subid);
memset (logfile_ctx, 0, sizeof (logfile_ctx_t));
}