Small improvements to fuzzer for NetHackW.
Can toggle fuzzer on/off using "Pause" key if attached to debugger. Extended command selected randomly.
This commit is contained in:
@@ -22,5 +22,6 @@ struct ext_func_tab {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct ext_func_tab extcmdlist[];
|
extern struct ext_func_tab extcmdlist[];
|
||||||
|
extern int extcmdlist_length;
|
||||||
|
|
||||||
#endif /* FUNC_TAB_H */
|
#endif /* FUNC_TAB_H */
|
||||||
|
|||||||
@@ -3406,6 +3406,8 @@ struct ext_func_tab extcmdlist[] = {
|
|||||||
{ '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */
|
{ '\0', (char *) 0, (char *) 0, donull, 0, (char *) 0 } /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int extcmdlist_length = SIZE(extcmdlist) - 1;
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
key2extcmddesc(key)
|
key2extcmddesc(key)
|
||||||
uchar key;
|
uchar key;
|
||||||
|
|||||||
@@ -167,6 +167,15 @@ INT_PTR CALLBACK ExtCmdDlgProc(HWND, UINT, WPARAM, LPARAM);
|
|||||||
int
|
int
|
||||||
mswin_ext_cmd_window(int *selection)
|
mswin_ext_cmd_window(int *selection)
|
||||||
{
|
{
|
||||||
|
if (iflags.debug_fuzzer) {
|
||||||
|
*selection = rn2(extcmdlist_length + 1) - 1;
|
||||||
|
|
||||||
|
if (*selection != -1)
|
||||||
|
return IDOK;
|
||||||
|
else
|
||||||
|
return IDCANCEL;
|
||||||
|
}
|
||||||
|
|
||||||
INT_PTR ret;
|
INT_PTR ret;
|
||||||
struct extcmd_data data;
|
struct extcmd_data data;
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ static const char scanmap[] = {
|
|||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
PNHMainWindow data;
|
PNHMainWindow data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
@@ -225,7 +225,6 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_KEYDOWN: {
|
case WM_KEYDOWN: {
|
||||||
data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
|
||||||
|
|
||||||
/* translate arrow keys into nethack commands */
|
/* translate arrow keys into nethack commands */
|
||||||
switch (wParam) {
|
switch (wParam) {
|
||||||
@@ -332,6 +331,15 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
NHEVENT_KBD(KEYTABLE(KEY_PLUS));
|
NHEVENT_KBD(KEYTABLE(KEY_PLUS));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
#if defined(DEBUG) && defined(_MSC_VER)
|
||||||
|
case VK_PAUSE:
|
||||||
|
if (IsDebuggerPresent()) {
|
||||||
|
iflags.debug_fuzzer = !iflags.debug_fuzzer;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case VK_CLEAR: /* This is the '5' key */
|
case VK_CLEAR: /* This is the '5' key */
|
||||||
NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING));
|
NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING));
|
||||||
return 0;
|
return 0;
|
||||||
@@ -530,9 +538,10 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|||||||
child = GetNHApp()->windowlist[msg_param->wid].win;
|
child = GetNHApp()->windowlist[msg_param->wid].win;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSNH_MSG_RANDOM_INPUT:
|
case MSNH_MSG_RANDOM_INPUT: {
|
||||||
nhassert(0); // unexpected
|
nhassert(iflags.debug_fuzzer);
|
||||||
break;
|
NHEVENT_KBD(randomkey());
|
||||||
|
} break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -689,14 +689,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSNH_MSG_RANDOM_INPUT: {
|
case MSNH_MSG_RANDOM_INPUT: {
|
||||||
char c = randomkey();
|
PostMessage(GetMenuControl(hWnd),
|
||||||
if (c == '\n')
|
WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
|
||||||
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
|
||||||
else if (c == '\033')
|
|
||||||
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
|
|
||||||
else
|
|
||||||
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0);
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1601,6 +1595,7 @@ reset_menu_count(HWND hwndList, PNHMenuWindow data)
|
|||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
HWND hWndParent = GetParent(hWnd);
|
||||||
BOOL bUpdateFocusItem;
|
BOOL bUpdateFocusItem;
|
||||||
|
|
||||||
/* we will redraw focused item whenever horizontal scrolling occurs
|
/* we will redraw focused item whenever horizontal scrolling occurs
|
||||||
@@ -1632,6 +1627,20 @@ NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
SetFocus(GetNHApp()->hMainWnd);
|
SetFocus(GetNHApp()->hMainWnd);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
case WM_MSNH_COMMAND:
|
||||||
|
if (wParam == MSNH_MSG_RANDOM_INPUT) {
|
||||||
|
char c = randomkey();
|
||||||
|
if (c == '\n')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
||||||
|
else if (c == '\033')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
|
||||||
|
else
|
||||||
|
PostMessage(hWnd, WM_CHAR, c, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update focused item */
|
/* update focused item */
|
||||||
@@ -1659,6 +1668,7 @@ NHMenuListWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
HWND hWndParent = GetParent(hWnd);
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
|
||||||
@@ -1686,8 +1696,7 @@ NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
|
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
|
||||||
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
|
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
|
||||||
else
|
else
|
||||||
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
||||||
0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case VK_NEXT:
|
case VK_NEXT:
|
||||||
@@ -1726,6 +1735,20 @@ NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_SETFOCUS:
|
case WM_SETFOCUS:
|
||||||
HideCaret(hWnd);
|
HideCaret(hWnd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case WM_MSNH_COMMAND:
|
||||||
|
if (wParam == MSNH_MSG_RANDOM_INPUT) {
|
||||||
|
char c = randomkey();
|
||||||
|
if (c == '\n')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
||||||
|
else if (c == '\033')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
|
||||||
|
else
|
||||||
|
PostMessage(hWnd, WM_CHAR, c, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editControlWndProc)
|
if (editControlWndProc)
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ HWND
|
|||||||
mswin_init_text_window()
|
mswin_init_text_window()
|
||||||
{
|
{
|
||||||
HWND ret;
|
HWND ret;
|
||||||
PNHTextWindow data;
|
|
||||||
RECT rt;
|
RECT rt;
|
||||||
|
|
||||||
/* get window position */
|
/* get window position */
|
||||||
@@ -52,13 +51,6 @@ mswin_init_text_window()
|
|||||||
/* Set window caption */
|
/* Set window caption */
|
||||||
SetWindowText(ret, "Text");
|
SetWindowText(ret, "Text");
|
||||||
|
|
||||||
/* create and set window data */
|
|
||||||
data = (PNHTextWindow) malloc(sizeof(NHTextWindow));
|
|
||||||
if (!data)
|
|
||||||
panic("out of memory");
|
|
||||||
ZeroMemory(data, sizeof(NHTextWindow));
|
|
||||||
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
|
|
||||||
|
|
||||||
mswin_apply_window_style(ret);
|
mswin_apply_window_style(ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -88,6 +80,12 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_INITDIALOG: {
|
case WM_INITDIALOG: {
|
||||||
|
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
|
||||||
|
if (!data)
|
||||||
|
panic("out of memory");
|
||||||
|
ZeroMemory(data, sizeof(NHTextWindow));
|
||||||
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data);
|
||||||
|
|
||||||
HWND control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
|
HWND control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
|
||||||
HDC hdc = GetDC(control);
|
HDC hdc = GetDC(control);
|
||||||
cached_font * font = mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE);
|
cached_font * font = mswin_get_font(NHW_TEXT, ATR_NONE, hdc, FALSE);
|
||||||
@@ -177,7 +175,10 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,14 +215,8 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case MSNH_MSG_RANDOM_INPUT: {
|
case MSNH_MSG_RANDOM_INPUT: {
|
||||||
char c = randomkey();
|
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL),
|
||||||
if (c == '\n')
|
WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
|
||||||
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
|
||||||
else if (c == '\033')
|
|
||||||
PostMessage(hWnd, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
|
|
||||||
else
|
|
||||||
PostMessage(GetDlgItem(hWnd, IDC_TEXT_CONTROL), WM_CHAR, c, 0);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -278,6 +273,7 @@ LayoutText(HWND hWnd)
|
|||||||
LRESULT CALLBACK
|
LRESULT CALLBACK
|
||||||
NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
HWND hWndParent = GetParent(hWnd);
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
RECT rc;
|
RECT rc;
|
||||||
|
|
||||||
@@ -305,8 +301,7 @@ NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
|
&& (si.nPos + (int) si.nPage) <= (si.nMax - si.nMin))
|
||||||
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
|
SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0);
|
||||||
else
|
else
|
||||||
PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0),
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
||||||
0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case VK_NEXT:
|
case VK_NEXT:
|
||||||
@@ -346,6 +341,20 @@ NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case WM_SETFOCUS:
|
case WM_SETFOCUS:
|
||||||
HideCaret(hWnd);
|
HideCaret(hWnd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case WM_MSNH_COMMAND:
|
||||||
|
if (wParam == MSNH_MSG_RANDOM_INPUT) {
|
||||||
|
char c = randomkey();
|
||||||
|
if (c == '\n')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDOK, 0), 0);
|
||||||
|
else if (c == '\033')
|
||||||
|
PostMessage(hWndParent, WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
|
||||||
|
else
|
||||||
|
PostMessage(hWnd, WM_CHAR, c, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editControlWndProc)
|
if (editControlWndProc)
|
||||||
|
|||||||
@@ -2102,24 +2102,25 @@ mswin_main_loop()
|
|||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
|
||||||
while (!mswin_have_input()) {
|
while (!mswin_have_input()) {
|
||||||
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
|
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
|
||||||
if(GetMessage(&msg, NULL, 0, 0) != 0) {
|
if(GetMessage(&msg, NULL, 0, 0) != 0) {
|
||||||
if (GetNHApp()->regNetHackMode
|
if (GetNHApp()->regNetHackMode
|
||||||
|| !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
|
|| !TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
|
||||||
&msg)) {
|
&msg)) {
|
||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* WM_QUIT */
|
/* WM_QUIT */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nhassert(iflags.debug_fuzzer);
|
nhassert(iflags.debug_fuzzer);
|
||||||
NHEVENT_KBD(randomkey());
|
PostMessage(GetNHApp()->hMainWnd, WM_MSNH_COMMAND,
|
||||||
}
|
MSNH_MSG_RANDOM_INPUT, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clean up and quit */
|
/* clean up and quit */
|
||||||
@@ -2232,25 +2233,26 @@ mswin_popup_display(HWND hWnd, int *done_indicator)
|
|||||||
SetFocus(hWnd);
|
SetFocus(hWnd);
|
||||||
|
|
||||||
/* go into message loop */
|
/* go into message loop */
|
||||||
while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator)) {
|
while (IsWindow(hWnd) && (done_indicator == NULL || !*done_indicator)) {
|
||||||
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
|
if (!iflags.debug_fuzzer || PeekMessage(&msg, NULL, 0, 0, FALSE)) {
|
||||||
if(GetMessage(&msg, NULL, 0, 0) != 0) {
|
if(GetMessage(&msg, NULL, 0, 0) != 0) {
|
||||||
if (!IsDialogMessage(hWnd, &msg)) {
|
if (msg.message == WM_MSNH_COMMAND ||
|
||||||
if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable,
|
!IsDialogMessage(hWnd, &msg)) {
|
||||||
&msg)) {
|
if (!TranslateAccelerator(msg.hwnd,
|
||||||
TranslateMessage(&msg);
|
GetNHApp()->hAccelTable, &msg)) {
|
||||||
DispatchMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
}
|
DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
/* WM_QUIT */
|
} else {
|
||||||
break;
|
/* WM_QUIT */
|
||||||
}
|
break;
|
||||||
} else {
|
}
|
||||||
nhassert(iflags.debug_fuzzer);
|
} else {
|
||||||
PostMessage(hWnd, WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
|
nhassert(iflags.debug_fuzzer);
|
||||||
}
|
PostMessage(hWnd, WM_MSNH_COMMAND, MSNH_MSG_RANDOM_INPUT, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user