1

i try to detect debugger and i get error "Cannot resolve symbol 'Dte'" even with envdte reference. Google give me nothing. Thank you.

using EnvDTE;
namespace test
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            foreach (EnvDTE.Process p in Dte.Debugger.DebuggedProcesses) {
                if (p.ProcessID == spawnedProcess.Id) {

                }
            }
        }
    }
}
SLI
  • 713
  • 11
  • 29

2 Answers2

0

C# is a case sensitive language.

Its DTE (in upper case) not Dte. Documentation at https://msdn.microsoft.com/en-us/library/envdte.dte.aspx

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

I need to detect is debugger (like Ollydbg) attached

To check if the process has a debugger attached to yo can use:

How to check if debugger is attached

  • CheckRemoteDebuggerPresent works for any running process and detects native debuggers too.

  • Debugger.IsAttached works only for the current process and detects only managed debuggers. As an example, OllyDbg won't be detected by this.

Code:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

public class DetectDebugger
{
    [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
    static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);

    public static void Main()
    {
        bool isDebuggerPresent = false;
        CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);

        Console.WriteLine("Debugger Attached: " + isDebuggerPresent);
        Console.ReadLine();
    }
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398