xpcom/windbgdlg/windbgdlg.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
michael@0 8 #include <windows.h>
michael@0 9 #include <stdlib.h>
michael@0 10 #ifdef _MSC_VER
michael@0 11 #include <strsafe.h>
michael@0 12 #endif
michael@0 13 #ifdef __MINGW32__
michael@0 14 /* MingW currently does not implement a wide version of the
michael@0 15 startup routines. Workaround is to implement something like
michael@0 16 it ourselves. See bug 472063 */
michael@0 17 #include <stdio.h>
michael@0 18 #include <shellapi.h>
michael@0 19 int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
michael@0 20
michael@0 21 #undef __argc
michael@0 22 #undef __wargv
michael@0 23
michael@0 24 static int __argc;
michael@0 25 static wchar_t** __wargv;
michael@0 26
michael@0 27 int WINAPI
michael@0 28 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
michael@0 29 LPSTR lpszCommandLine, int nCmdShow)
michael@0 30 {
michael@0 31 LPWSTR commandLine = GetCommandLineW();
michael@0 32
michael@0 33 /* parse for __argc and __wargv for compatibility, since mingw
michael@0 34 * doesn't claim to support it :(
michael@0 35 */
michael@0 36 __wargv = CommandLineToArgvW(commandLine, &__argc);
michael@0 37 if (!__wargv)
michael@0 38 return 127;
michael@0 39
michael@0 40 /* need to strip off any leading whitespace plus the first argument
michael@0 41 * (the executable itself) to match what should be passed to wWinMain
michael@0 42 */
michael@0 43 while ((*commandLine <= L' ') && *commandLine) {
michael@0 44 ++commandLine;
michael@0 45 }
michael@0 46 if (*commandLine == L'"') {
michael@0 47 ++commandLine;
michael@0 48 while ((*commandLine != L'"') && *commandLine) {
michael@0 49 ++commandLine;
michael@0 50 }
michael@0 51 if (*commandLine) {
michael@0 52 ++commandLine;
michael@0 53 }
michael@0 54 } else {
michael@0 55 while (*commandLine > L' ') {
michael@0 56 ++commandLine;
michael@0 57 }
michael@0 58 }
michael@0 59 while ((*commandLine <= L' ') && *commandLine) {
michael@0 60 ++commandLine;
michael@0 61 }
michael@0 62
michael@0 63 int result = wWinMain(hInstance, hPrevInstance, commandLine, nCmdShow);
michael@0 64 LocalFree(__wargv);
michael@0 65 return result;
michael@0 66 }
michael@0 67 #endif /* __MINGW32__ */
michael@0 68
michael@0 69
michael@0 70 int WINAPI
michael@0 71 wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
michael@0 72 LPWSTR lpszCmdLine, int nCmdShow)
michael@0 73 {
michael@0 74 /* support for auto answering based on words in the assertion.
michael@0 75 * the assertion message is sent as a series of arguements (words) to the commandline.
michael@0 76 * set a "word" to 0xffffffff to let the word not affect this code.
michael@0 77 * set a "word" to 0xfffffffe to show the dialog.
michael@0 78 * set a "word" to 0x5 to ignore (program should continue).
michael@0 79 * set a "word" to 0x4 to retry (should fall into debugger).
michael@0 80 * set a "word" to 0x3 to abort (die).
michael@0 81 */
michael@0 82 DWORD regType;
michael@0 83 DWORD regValue = -1;
michael@0 84 DWORD regLength = sizeof regValue;
michael@0 85 HKEY hkeyCU, hkeyLM;
michael@0 86 RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyCU);
michael@0 87 RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyLM);
michael@0 88 int argc =0;
michael@0 89 for (int i = __argc - 1; regValue == (DWORD)-1 && i; --i) {
michael@0 90 bool ok = false;
michael@0 91 if (hkeyCU)
michael@0 92 ok = RegQueryValueExW(hkeyCU, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
michael@0 93 if (!ok && hkeyLM)
michael@0 94 ok = RegQueryValueExW(hkeyLM, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
michael@0 95 if (!ok)
michael@0 96 regValue = -1;
michael@0 97 }
michael@0 98 if (hkeyCU)
michael@0 99 RegCloseKey(hkeyCU);
michael@0 100 if (hkeyLM)
michael@0 101 RegCloseKey(hkeyLM);
michael@0 102 if (regValue != (DWORD)-1 && regValue != (DWORD)-2)
michael@0 103 return regValue;
michael@0 104 static const int size = 4096;
michael@0 105 static WCHAR msg[size];
michael@0 106
michael@0 107 #ifdef _MSC_VER
michael@0 108 StringCchPrintfW(msg,
michael@0 109 #else
michael@0 110 snwprintf(msg,
michael@0 111 #endif
michael@0 112 size,
michael@0 113 L"%s\n\nClick Abort to exit the Application.\n"
michael@0 114 L"Click Retry to Debug the Application.\n"
michael@0 115 L"Click Ignore to continue running the Application.",
michael@0 116 lpszCmdLine);
michael@0 117 msg[size - 1] = L'\0';
michael@0 118 return MessageBoxW(nullptr, msg, L"NSGlue_Assertion",
michael@0 119 MB_ICONSTOP | MB_SYSTEMMODAL |
michael@0 120 MB_ABORTRETRYIGNORE | MB_DEFBUTTON3);
michael@0 121 }

mercurial