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-15 02:21:41 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "logging.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 "mpsp.h"
|
|
|
|
#include "rp_cpu.h"
|
2016-09-15 14:02:52 +00:00
|
|
|
#include "tuningdb.h"
|
2016-09-20 11:18:47 +00:00
|
|
|
#include "thread.h"
|
2016-09-15 02:21:41 +00:00
|
|
|
#include "opencl.h"
|
2016-09-15 14:02:52 +00:00
|
|
|
#include "hwmon.h"
|
|
|
|
#include "restore.h"
|
2016-09-16 15:01:18 +00:00
|
|
|
#include "hash_management.h"
|
2016-09-15 02:21:41 +00:00
|
|
|
#include "outfile.h"
|
|
|
|
#include "potfile.h"
|
|
|
|
#include "debugfile.h"
|
|
|
|
#include "loopback.h"
|
|
|
|
#include "data.h"
|
|
|
|
#include "status.h"
|
2016-09-20 10:32:39 +00:00
|
|
|
#include "shared.h"
|
2016-09-06 11:16:38 +00:00
|
|
|
#include "terminal.h"
|
|
|
|
|
2016-09-15 02:21:41 +00:00
|
|
|
extern hc_global_data_t data;
|
|
|
|
|
|
|
|
extern hc_thread_mutex_t mux_display;
|
|
|
|
|
2016-09-11 08:28:59 +00:00
|
|
|
const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => ";
|
|
|
|
|
2016-09-11 08:39:19 +00:00
|
|
|
void send_prompt ()
|
|
|
|
{
|
|
|
|
fprintf (stdout, "%s", PROMPT);
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_prompt ()
|
|
|
|
{
|
|
|
|
fputc ('\r', stdout);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < strlen (PROMPT); i++)
|
|
|
|
{
|
|
|
|
fputc (' ', stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc ('\r', stdout);
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
|
2016-09-15 02:21:41 +00:00
|
|
|
void *thread_keypress (void *p)
|
|
|
|
{
|
2016-09-15 14:02:52 +00:00
|
|
|
opencl_ctx_t *opencl_ctx = data.opencl_ctx;
|
2016-09-20 10:32:39 +00:00
|
|
|
|
|
|
|
while (opencl_ctx->devices_status == STATUS_INIT) hc_sleep_ms (100);
|
|
|
|
|
2016-09-22 10:45:48 +00:00
|
|
|
user_options_t *user_options = data.user_options;
|
|
|
|
user_options_extra_t *user_options_extra = data.user_options_extra;
|
|
|
|
hashconfig_t *hashconfig = data.hashconfig;
|
|
|
|
hashes_t *hashes = data.hashes;
|
2016-09-24 10:05:56 +00:00
|
|
|
rules_ctx_t *rules_ctx = data.rules_ctx;
|
2016-09-15 14:02:52 +00:00
|
|
|
|
2016-09-22 13:56:32 +00:00
|
|
|
uint quiet = user_options->quiet;
|
2016-09-15 02:21:41 +00:00
|
|
|
|
2016-09-20 10:32:39 +00:00
|
|
|
tty_break ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
while (data.shutdown_outer == 0)
|
|
|
|
{
|
2016-09-20 10:32:39 +00:00
|
|
|
int ch = tty_getchar ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
if (ch == -1) break;
|
|
|
|
|
|
|
|
if (ch == 0) continue;
|
|
|
|
|
|
|
|
//https://github.com/hashcat/hashcat/issues/302
|
|
|
|
//#if defined (_POSIX)
|
|
|
|
//if (ch != '\n')
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
hc_thread_mutex_lock (mux_display);
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-24 10:05:56 +00:00
|
|
|
status_display (opencl_ctx, hashconfig, hashes, user_options, user_options_extra, rules_ctx);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-21 14:07:49 +00:00
|
|
|
if (quiet == false) send_prompt ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-15 14:02:52 +00:00
|
|
|
bypass (opencl_ctx);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-21 14:07:49 +00:00
|
|
|
if (quiet == false) send_prompt ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-15 14:02:52 +00:00
|
|
|
SuspendThreads (opencl_ctx);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-21 14:07:49 +00:00
|
|
|
if (quiet == false) send_prompt ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-15 14:02:52 +00:00
|
|
|
ResumeThreads (opencl_ctx);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-21 14:07:49 +00:00
|
|
|
if (quiet == false) send_prompt ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-22 12:45:00 +00:00
|
|
|
stop_at_checkpoint (opencl_ctx, user_options);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-21 14:07:49 +00:00
|
|
|
if (quiet == false) send_prompt ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
|
|
|
|
log_info ("");
|
|
|
|
|
2016-09-15 14:02:52 +00:00
|
|
|
myabort (opencl_ctx);
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//https://github.com/hashcat/hashcat/issues/302
|
|
|
|
//#if defined (_POSIX)
|
|
|
|
//if (ch != '\n')
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
hc_thread_mutex_unlock (mux_display);
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:32:39 +00:00
|
|
|
tty_fix ();
|
2016-09-15 02:21:41 +00:00
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2016-09-08 07:21:25 +00:00
|
|
|
#if defined (_WIN)
|
|
|
|
void SetConsoleWindowSize (const int x)
|
|
|
|
{
|
|
|
|
HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE) return;
|
|
|
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo (h, &bufferInfo)) return;
|
|
|
|
|
|
|
|
SMALL_RECT *sr = &bufferInfo.srWindow;
|
|
|
|
|
|
|
|
sr->Right = MAX (sr->Right, x - 1);
|
|
|
|
|
|
|
|
COORD co;
|
|
|
|
|
|
|
|
co.X = sr->Right + 1;
|
|
|
|
co.Y = 9999;
|
|
|
|
|
|
|
|
if (!SetConsoleScreenBufferSize (h, co)) return;
|
|
|
|
|
|
|
|
if (!SetConsoleWindowInfo (h, TRUE, sr)) return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (__linux__)
|
2016-09-06 11:16:38 +00:00
|
|
|
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
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (_WIN)
|
2016-09-06 11:16:38 +00:00
|
|
|
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
|