fuzzer fixes on windows for testing

This commit is contained in:
nhmall
2018-11-21 18:50:02 -05:00
parent 030efe84fa
commit 86637bb4ef
3 changed files with 76 additions and 3 deletions

View File

@@ -688,11 +688,11 @@ tty_delay_output()
clock_t goal;
int k;
goal = 50 + clock();
back_buffer_flip();
if (iflags.debug_fuzzer)
return;
goal = 50 + clock();
back_buffer_flip();
while (goal > clock()) {
k = junk; /* Do nothing */
}

View File

@@ -185,6 +185,8 @@ static const char scanmap[] = {
'b', 'n', 'm', ',', '.', '?' /* ... */
};
#define IDT_FUZZ_TIMER 100
/*
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
@@ -727,6 +729,62 @@ mswin_layout_main_window(HWND changed_child)
SetForegroundWindow(changed_child);
}
VOID CALLBACK FuzzTimerProc(
_In_ HWND hwnd,
_In_ UINT uMsg,
_In_ UINT_PTR idEvent,
_In_ DWORD dwTime
)
{
INPUT input[16];
int i_pos = 0;
int c = randomkey();
SHORT k = VkKeyScanA(c);
BOOL gen_alt = (rn2(50) == 0) && isalpha(c);
if (!iflags.debug_fuzzer) {
KillTimer(hwnd, IDT_FUZZ_TIMER);
return;
}
if (!GetFocus())
return;
ZeroMemory(input, sizeof(input));
if (gen_alt) {
input[i_pos].type = INPUT_KEYBOARD;
input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
input[i_pos].ki.wScan = MapVirtualKey(VK_MENU, 0);
i_pos++;
}
if (HIBYTE(k) & 1) {
input[i_pos].type = INPUT_KEYBOARD;
input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
input[i_pos].ki.wScan = MapVirtualKey(VK_LSHIFT, 0);
i_pos++;
}
input[i_pos].type = INPUT_KEYBOARD;
input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
input[i_pos].ki.wScan = MapVirtualKey(LOBYTE(k), 0);
i_pos++;
if (HIBYTE(k) & 1) {
input[i_pos].type = INPUT_KEYBOARD;
input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
input[i_pos].ki.wScan = MapVirtualKey(VK_LSHIFT, 0);
i_pos++;
}
if (gen_alt) {
input[i_pos].type = INPUT_KEYBOARD;
input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
input[i_pos].ki.wScan = MapVirtualKey(VK_MENU, 0);
i_pos++;
}
SendInput(i_pos, input, sizeof(input[0]));
}
LRESULT
onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
@@ -745,11 +803,22 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
mswin_display_splash_window(TRUE);
break;
case IDM_FUZZ:
if (iflags.debug_fuzzer)
KillTimer(hWnd, IDT_FUZZ_TIMER);
else
SetTimer(hWnd, IDT_FUZZ_TIMER, 10, FuzzTimerProc);
iflags.debug_fuzzer = !iflags.debug_fuzzer;
break;
case IDM_EXIT:
if (iflags.debug_fuzzer)
break;
done2();
break;
case IDM_SAVE:
if (iflags.debug_fuzzer)
break;
if (!program_state.gameover && !program_state.done_hup)
dosave();
else
@@ -829,6 +898,9 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
wchar_t *wtext;
int tlen = 0;
if (iflags.debug_fuzzer)
break;
ZeroMemory(filename, sizeof(filename));
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);

View File

@@ -142,6 +142,7 @@
#define IDM_SETTING_LOCKWINDOWS 32797
#define IDM_SETTING_SCREEN_TO_CLIPBOARD 32798
#define IDM_SETTING_SCREEN_TO_FILE 32799
#define IDM_FUZZ 32800
#define IDC_STATIC -1
// Next default values for new objects
@@ -149,7 +150,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 146
#define _APS_NEXT_COMMAND_VALUE 32800
#define _APS_NEXT_COMMAND_VALUE 32801
#define _APS_NEXT_CONTROL_VALUE 1341
#define _APS_NEXT_SYMED_VALUE 110
#endif