mirror of
https://github.com/yck1509/ConfuserEx
synced 2026-06-08 18:29:44 +00:00
0e283a1b9c
Fix #412
39 lines
945 B
C#
39 lines
945 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
|
|
namespace Confuser.Runtime {
|
|
internal static class AntiDebugSafe {
|
|
static void Initialize() {
|
|
string x = "COR";
|
|
var env = typeof(Environment);
|
|
var method = env.GetMethod("GetEnvironmentVariable", new[] { typeof(string) });
|
|
if (method != null &&
|
|
"1".Equals(method.Invoke(null, new object[] { x + "_ENABLE_PROFILING" })))
|
|
Environment.FailFast(null);
|
|
|
|
var thread = new Thread(Worker);
|
|
thread.IsBackground = true;
|
|
thread.Start(null);
|
|
}
|
|
|
|
static void Worker(object thread) {
|
|
var th = thread as Thread;
|
|
if (th == null) {
|
|
th = new Thread(Worker);
|
|
th.IsBackground = true;
|
|
th.Start(Thread.CurrentThread);
|
|
Thread.Sleep(500);
|
|
}
|
|
while (true) {
|
|
if (Debugger.IsAttached || Debugger.IsLogging())
|
|
Environment.FailFast(null);
|
|
|
|
if (!th.IsAlive)
|
|
Environment.FailFast(null);
|
|
|
|
Thread.Sleep(1000);
|
|
}
|
|
}
|
|
}
|
|
} |