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();
}
}