You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hashcat/src/logfile.c

109 lines
1.7 KiB

/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "interface.h"
#include "timer.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "memory.h"
#include "rp_cpu.h"
#include "mpsp.h"
#include "tuningdb.h"
#include "thread.h"
#include "opencl.h"
#include "hwmon.h"
#include "restore.h"
#include "hash_management.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "logfile.h"
extern hc_global_data_t data;
static FILE *logfile_open (char *logfile)
{
FILE *fp = fopen (logfile, "ab");
if (fp == NULL)
{
fp = stdout;
}
return fp;
}
static void logfile_close (FILE *fp)
{
if (fp == stdout) return;
fclose (fp);
}
void logfile_append (const user_options_t *user_options, const char *fmt, ...)
{
if (user_options->logfile_disable == true) return;
FILE *fp = logfile_open (data.logfile);
va_list ap;
va_start (ap, fmt);
vfprintf (fp, fmt, ap);
va_end (ap);
fputc ('\n', fp);
fflush (fp);
logfile_close (fp);
}
static int logfile_generate_id ()
{
const int n = rand ();
time_t t;
time (&t);
return t + n;
}
char *logfile_generate_topid ()
{
const int id = logfile_generate_id ();
char *topid = (char *) mymalloc (1 + 16 + 1);
snprintf (topid, 1 + 16, "TOP%08x", id);
return topid;
}
char *logfile_generate_subid ()
{
const int id = logfile_generate_id ();
char *subid = (char *) mymalloc (1 + 16 + 1);
snprintf (subid, 1 + 16, "SUB%08x", id);
return subid;
}