Fix use of select() on stdin on windows

Fixes #1705
pull/1721/head
Jens Steube 6 years ago
parent ab46265f5f
commit 4a9171ca5d

@ -83,4 +83,6 @@ float get_entropy (const u8 *buf, const int len);
int select_read_timeout (int sockfd, const int sec);
int select_write_timeout (int sockfd, const int sec);
int select_read_timeout_console (const int sec);
#endif // _SHARED_H

@ -171,7 +171,7 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
while (device_param->pws_pre_cnt < device_param->kernel_power)
{
const int rc_select = select_read_timeout (fileno (stdin), 1);
const int rc_select = select_read_timeout_console (1);
if (rc_select == -1) break;
@ -339,7 +339,7 @@ static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par
while (device_param->pws_cnt < device_param->kernel_power)
{
const int rc_select = select_read_timeout (fileno (stdin), 1);
const int rc_select = select_read_timeout_console (1);
if (rc_select == -1) break;

@ -739,3 +739,51 @@ int select_write_timeout (int sockfd, const int sec)
return select (sockfd + 1, NULL, &fds, NULL, &tv);
}
#if defined (_WIN)
int select_read_timeout_console (const int sec)
{
const HANDLE hStdIn = GetStdHandle (STD_INPUT_HANDLE);
const DWORD rc = WaitForSingleObject (hStdIn, sec * 1000);
if (rc == WAIT_OBJECT_0)
{
DWORD dwRead;
INPUT_RECORD inRecords;
PeekConsoleInput (hStdIn, &inRecords, 1, &dwRead);
if (inRecords.EventType == KEY_EVENT)
{
// those are good ones
return 1;
}
else
{
// but we don't want that stuff like windows focus etc. in our stream
ReadConsoleInput (hStdIn, &inRecords, 1, &dwRead);
}
return select_read_timeout_console (sec);
}
else if (rc == WAIT_TIMEOUT)
{
return 0;
}
return -1;
}
#else
int select_read_timeout_console (const int sec)
{
return select_read_timeout (fileno (stdin), sec);
}
#endif

Loading…
Cancel
Save