mirror of https://github.com/hashcat/hashcat.git
parent
eb5e192df5
commit
5dd5c15966
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
char *logfile_generate_topid (void);
|
||||
char *logfile_generate_subid (void);
|
||||
|
||||
void logfile_append (const char *fmt, ...);
|
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef _POSIX
|
||||
#include <termios.h>
|
||||
#endif // _POSIX
|
||||
|
||||
#ifdef _WIN
|
||||
#include <windows.h>
|
||||
#endif // _WIN
|
||||
|
||||
int tty_break();
|
||||
int tty_getchar();
|
||||
int tty_fix();
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types_int.h"
|
||||
#include "ext_OpenCL.h"
|
||||
#include "ext_ADL.h"
|
||||
#include "ext_nvapi.h"
|
||||
#include "ext_nvml.h"
|
||||
#include "ext_xnvctrl.h"
|
||||
#include "timer.h"
|
||||
#include "types.h"
|
||||
#include "memory.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 char *fmt, ...)
|
||||
{
|
||||
if (data.logfile_disable == 1) 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;
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "terminal.h"
|
||||
|
||||
#ifdef __linux__
|
||||
static struct termios savemodes;
|
||||
static int havemodes = 0;
|
||||
|
||||
int tty_break()
|
||||
{
|
||||
struct termios modmodes;
|
||||
|
||||
if (tcgetattr (fileno (stdin), &savemodes) < 0) return -1;
|
||||
|
||||
havemodes = 1;
|
||||
|
||||
modmodes = savemodes;
|
||||
modmodes.c_lflag &= ~ICANON;
|
||||
modmodes.c_cc[VMIN] = 1;
|
||||
modmodes.c_cc[VTIME] = 0;
|
||||
|
||||
return tcsetattr (fileno (stdin), TCSANOW, &modmodes);
|
||||
}
|
||||
|
||||
int tty_getchar()
|
||||
{
|
||||
fd_set rfds;
|
||||
|
||||
FD_ZERO (&rfds);
|
||||
|
||||
FD_SET (fileno (stdin), &rfds);
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
int retval = select (1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
if (retval == 0) return 0;
|
||||
if (retval == -1) return -1;
|
||||
|
||||
return getchar();
|
||||
}
|
||||
|
||||
int tty_fix()
|
||||
{
|
||||
if (!havemodes) return 0;
|
||||
|
||||
return tcsetattr (fileno (stdin), TCSADRAIN, &savemodes);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
static struct termios savemodes;
|
||||
static int havemodes = 0;
|
||||
|
||||
int tty_break()
|
||||
{
|
||||
struct termios modmodes;
|
||||
|
||||
if (ioctl (fileno (stdin), TIOCGETA, &savemodes) < 0) return -1;
|
||||
|
||||
havemodes = 1;
|
||||
|
||||
modmodes = savemodes;
|
||||
modmodes.c_lflag &= ~ICANON;
|
||||
modmodes.c_cc[VMIN] = 1;
|
||||
modmodes.c_cc[VTIME] = 0;
|
||||
|
||||
return ioctl (fileno (stdin), TIOCSETAW, &modmodes);
|
||||
}
|
||||
|
||||
int tty_getchar()
|
||||
{
|
||||
fd_set rfds;
|
||||
|
||||
FD_ZERO (&rfds);
|
||||
|
||||
FD_SET (fileno (stdin), &rfds);
|
||||
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
int retval = select (1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
if (retval == 0) return 0;
|
||||
if (retval == -1) return -1;
|
||||
|
||||
return getchar();
|
||||
}
|
||||
|
||||
int tty_fix()
|
||||
{
|
||||
if (!havemodes) return 0;
|
||||
|
||||
return ioctl (fileno (stdin), TIOCSETAW, &savemodes);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WIN
|
||||
static DWORD saveMode = 0;
|
||||
|
||||
int tty_break()
|
||||
{
|
||||
HANDLE stdinHandle = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
||||
GetConsoleMode (stdinHandle, &saveMode);
|
||||
SetConsoleMode (stdinHandle, ENABLE_PROCESSED_INPUT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tty_getchar()
|
||||
{
|
||||
HANDLE stdinHandle = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
||||
DWORD rc = WaitForSingleObject (stdinHandle, 1000);
|
||||
|
||||
if (rc == WAIT_TIMEOUT) return 0;
|
||||
if (rc == WAIT_ABANDONED) return -1;
|
||||
if (rc == WAIT_FAILED) return -1;
|
||||
|
||||
// The whole ReadConsoleInput () part is a workaround.
|
||||
// For some unknown reason, maybe a mingw bug, a random signal
|
||||
// is sent to stdin which unblocks WaitForSingleObject () and sets rc 0.
|
||||
// Then it wants to read with getche () a keyboard input
|
||||
// which has never been made.
|
||||
|
||||
INPUT_RECORD buf[100];
|
||||
|
||||
DWORD num = 0;
|
||||
|
||||
memset (buf, 0, sizeof (buf));
|
||||
|
||||
ReadConsoleInput (stdinHandle, buf, 100, &num);
|
||||
|
||||
FlushConsoleInputBuffer (stdinHandle);
|
||||
|
||||
for (DWORD i = 0; i < num; i++)
|
||||
{
|
||||
if (buf[i].EventType != KEY_EVENT) continue;
|
||||
|
||||
KEY_EVENT_RECORD KeyEvent = buf[i].Event.KeyEvent;
|
||||
|
||||
if (KeyEvent.bKeyDown != TRUE) continue;
|
||||
|
||||
return KeyEvent.uChar.AsciiChar;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tty_fix()
|
||||
{
|
||||
HANDLE stdinHandle = GetStdHandle (STD_INPUT_HANDLE);
|
||||
|
||||
SetConsoleMode (stdinHandle, saveMode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
Loading…
Reference in new issue