public static void StartAntiDebug() { if (!AntiManagedProfiler.Initialize()) { Environment.Exit(0); } if (!AntiManagedDebugger.Initialize()) { Environment.Exit(0); } while (true) { if (IsDebugging()) { Environment.Exit(0); } Thread.Sleep(250); } }
public static int main(string[] args) { Console.WriteLine(); Console.WriteLine("CLR: {0} - {1}", Environment.Version, IntPtr.Size == 4 ? "x86" : "x64"); Console.WriteLine(); Console.WriteLine("Profiler attached: can't determine that yet"); Console.WriteLine("Debugger.IsAttached: {0}", Debugger.IsAttached); Console.WriteLine("Press any key to initialize anti-managed debugger/profiler code..."); Console.ReadKey(); Console.WriteLine(sep); if (AntiManagedProfiler.Initialize()) { Console.WriteLine("Anti-managed profiler code has been successfully initialized"); } else { Console.Error.WriteLine(seperr); Console.Error.WriteLine("FAILED TO INITIALIZE ANTI-PROFILER CODE"); Console.Error.WriteLine(seperr); } if (AntiManagedDebugger.Initialize()) { Console.WriteLine("Anti-managed debugger code has been successfully initialized"); } else { Console.Error.WriteLine(seperr); Console.Error.WriteLine("FAILED TO INITIALIZE ANTI-DEBUGGER CODE"); Console.Error.WriteLine(seperr); } Console.WriteLine(); Console.WriteLine("Profiler attached: {0}", AntiManagedProfiler.IsProfilerAttached); if (AntiManagedProfiler.IsProfilerAttached) { Console.WriteLine("Preventing the profiler from receiving messages."); // NB: It's better to terminate the program since the profiler can still // call into the CLR and do stuff to your program. AntiManagedProfiler.PreventActiveProfilerFromReceivingProfilingMessages(); Console.WriteLine("Prevented the profiler from receiving messages"); Console.WriteLine("Profiler attached: {0} (at least that's what the CLR thinks)", AntiManagedProfiler.IsProfilerAttached); } Console.WriteLine("Debugger.IsAttached: {0}", Debugger.IsAttached); Console.WriteLine("Try to attach a debugger or profiler."); Console.WriteLine("Press any key to execute some code for the profiler..."); Console.ReadKey(); Console.WriteLine(sep); GenerateProfilerEvents(); Console.WriteLine("Profiler attached: {0}", AntiManagedProfiler.IsProfilerAttached); Console.WriteLine("Debugger.IsAttached: {0}", Debugger.IsAttached); Console.WriteLine("Let's exit. Press any key (again!)..."); Console.ReadKey(); Console.WriteLine(sep); Console.WriteLine("Profiler attached: {0}", AntiManagedProfiler.IsProfilerAttached); Console.WriteLine("Debugger.IsAttached: {0}", Debugger.IsAttached); return(0); }