| 4621 | |
| 4622 | |
| 4623 | ResultType ShowMainWindow(MainWindowModes aMode, bool aRestricted) |
| 4624 | // Always returns OK for caller convenience. |
| 4625 | { |
| 4626 | // v1.0.30.05: Increased from 32 KB to 64 KB, which is the maximum size of an Edit |
| 4627 | // in Win9x: |
| 4628 | TCHAR buf_temp[65534]; // Formerly 32767. |
| 4629 | *buf_temp = '\0'; |
| 4630 | bool jump_to_bottom = false; // Set default behavior for edit control. |
| 4631 | static MainWindowModes current_mode = MAIN_MODE_NO_CHANGE; |
| 4632 | |
| 4633 | // If we were called from a restricted place, such as via the Tray Menu or the Main Menu, |
| 4634 | // don't allow potentially sensitive info such as script lines and variables to be shown. |
| 4635 | // This is done so that scripts can be compiled more securely, making it difficult for anyone |
| 4636 | // to use ListLines to see the author's source code. Rather than make exceptions for things |
| 4637 | // like KeyHistory, it seems best to forbid all information reporting except in cases where |
| 4638 | // existing info in the main window -- which must have gotten there via an allowed function |
| 4639 | // such as ListLines encountered in the script -- is being refreshed. This is because in |
| 4640 | // that case, the script author has given de facto permission for that loophole (and it's |
| 4641 | // a pretty small one, not easy to exploit): |
| 4642 | if (aRestricted && !g_AllowMainWindow && (current_mode == MAIN_MODE_NO_CHANGE || aMode != MAIN_MODE_REFRESH)) |
| 4643 | { |
| 4644 | // This used to set g_hWndEdit's text to an explanation for why the information will not |
| 4645 | // be shown, but it would never be seen unless the window was shown by some other means. |
| 4646 | // Since the menu items are disabled or removed, execution probably reached here as a |
| 4647 | // result of direct PostMessage to the script, so whoever did it can probably deal with |
| 4648 | // the lack of explanation (if the window was even visible). The explanation contained |
| 4649 | // obsolete syntax (Menu, Tray, MainWindow) and was removed rather than updated to reduce |
| 4650 | // code size. It seems unnecessary to even clear g_hWndEdit: either it's already empty, |
| 4651 | // or content was placed there deliberately and was already accessible. |
| 4652 | //SendMessage(g_hWndEdit, WM_SETTEXT, 0, (LPARAM)_T("Disabled")); |
| 4653 | return OK; |
| 4654 | } |
| 4655 | |
| 4656 | // If the window is empty, caller wants us to default it to showing the most recently |
| 4657 | // executed script lines: |
| 4658 | if (current_mode == MAIN_MODE_NO_CHANGE && (aMode == MAIN_MODE_NO_CHANGE || aMode == MAIN_MODE_REFRESH)) |
| 4659 | aMode = MAIN_MODE_LINES; |
| 4660 | |
| 4661 | switch (aMode) |
| 4662 | { |
| 4663 | // case MAIN_MODE_NO_CHANGE: do nothing |
| 4664 | case MAIN_MODE_LINES: |
| 4665 | Line::LogToText(buf_temp, _countof(buf_temp)); |
| 4666 | jump_to_bottom = true; |
| 4667 | break; |
| 4668 | case MAIN_MODE_VARS: |
| 4669 | g_script.ListVars(buf_temp, _countof(buf_temp)); |
| 4670 | break; |
| 4671 | case MAIN_MODE_HOTKEYS: |
| 4672 | Hotkey::ListHotkeys(buf_temp, _countof(buf_temp)); |
| 4673 | break; |
| 4674 | case MAIN_MODE_KEYHISTORY: |
| 4675 | g_script.ListKeyHistory(buf_temp, _countof(buf_temp)); |
| 4676 | break; |
| 4677 | case MAIN_MODE_REFRESH: |
| 4678 | // Rather than do a recursive call to self, which might stress the stack if the script is heavily recursed: |
| 4679 | switch (current_mode) |
| 4680 | { |
no test coverage detected