1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-01-22 05:31:11 +00:00

Fix use of select() on stdin on windows

Fixes #1705
This commit is contained in:
Jens Steube 2018-10-18 11:20:01 +02:00
parent ab46265f5f
commit 4a9171ca5d
3 changed files with 52 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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