Exemplo n.º 1
0
        bool Initialize(CorProcess process, string debuggeeVersion)
        {
            try {
                var mgr = new ECallManager(process.ProcessId, debuggeeVersion);
                if (!mgr.FoundClrModule)
                {
                    return(false);
                }

                const string debuggerClassName = "System.Diagnostics.Debugger";
                ulong        addr;
                bool         error = false, b;

                bool isClrV2OrOlder =
                    debuggeeVersion != null &&
                    (debuggeeVersion.StartsWith("v1.", StringComparison.OrdinalIgnoreCase) ||
                     debuggeeVersion.StartsWith("v2.", StringComparison.OrdinalIgnoreCase));

                // Launch() returns true in CLR 4.x and false in earlier CLR versions when there's
                // no debugger. At least on my system...
                b      = mgr.FindFunc(debuggerClassName, "LaunchInternal", out addr);
                error |= !b;
                if (b)
                {
                    error |= !(isClrV2OrOlder ? WriteReturnFalse(process, addr) : WriteReturnTrue(process, addr));
                }

                b = mgr.FindFunc(debuggerClassName, "get_IsAttached", out addr);
                if (!b)
                {
                    b = mgr.FindFunc(debuggerClassName, "IsDebuggerAttached", out addr);
                }
                error |= !b;
                if (b)
                {
                    error |= !WriteReturnFalse(process, addr);
                }

                b      = mgr.FindFunc(debuggerClassName, "IsLogging", out addr);
                error |= !b;
                if (b)
                {
                    error |= !WriteReturnFalse(process, addr);
                }

                return(!error);
            }
            catch {
                return(false);
            }
        }
		bool Initialize(CorProcess process, string debuggeeVersion) {
			try {
				var mgr = new ECallManager(process.ProcessId, debuggeeVersion);
				if (!mgr.FoundClrModule)
					return false;

				const string debuggerClassName = "System.Diagnostics.Debugger";
				ulong addr;
				bool error = false, b;

				bool isClrV2OrOlder =
					debuggeeVersion != null &&
					(debuggeeVersion.StartsWith("v1.", StringComparison.OrdinalIgnoreCase) ||
					debuggeeVersion.StartsWith("v2.", StringComparison.OrdinalIgnoreCase));

				// Launch() returns true in CLR 4.x and false in earlier CLR versions when there's
				// no debugger. At least on my system...
				b = mgr.FindFunc(debuggerClassName, "LaunchInternal", out addr);
				error |= !b;
				if (b)
					error |= !(isClrV2OrOlder ? WriteReturnFalse(process, addr) : WriteReturnTrue(process, addr));

				b = mgr.FindFunc(debuggerClassName, "get_IsAttached", out addr);
				if (!b)
					b = mgr.FindFunc(debuggerClassName, "IsDebuggerAttached", out addr);
				error |= !b;
				if (b)
					error |= !WriteReturnFalse(process, addr);

				b = mgr.FindFunc(debuggerClassName, "IsLogging", out addr);
				error |= !b;
				if (b)
					error |= !WriteReturnFalse(process, addr);

				return !error;
			}
			catch {
				return false;
			}
		}