// ==UserScript== // @name 超星学习通 反调试彻底解除(debugger死循环) // @namespace https://github.com/anti-debug // @version 1.0.0 // @description 彻底解除超星课程页的 debugger 死循环反调试(混淆+eval 动态构造 debugger),恢复 F12 正常使用 // @author you // @match *://*.chaoxing.com/* // @match *://*.xuexitong.com/* // @run-at document-start // @grant none // @license MIT // ==/UserScript== (function () { 'use strict'; // 判断一段代码里是否含 debugger(兼容混淆后 toString 的结果) function hasDebugger(code) { if (code == null) return false; var s = typeof code === 'function' ? String(code) : String(code); // debugger 关键字可能在混淆后仍以某种形式出现;这里用宽松匹配 return /debugger/.test(s); } // ===== 1. 拦截 setInterval / setTimeout(高频循环入口)===== var _setInterval = window.setInterval; var _setTimeout = window.setTimeout; window.setInterval = function (fn, delay) { var s = typeof fn === 'function' ? fn.toString() : String(fn); if (hasDebugger(s)) { // 含 debugger,直接返回 0,不启动定时器 return 0; } return _setInterval.apply(this, arguments); }; window.setTimeout = function (fn, delay) { var s = typeof fn === 'function' ? fn.toString() : String(fn); if (hasDebugger(s)) { return 0; } return _setTimeout.apply(this, arguments); }; // ===== 2. 拦截 eval(动态构造 debugger 的核心)===== var _eval = window.eval; window.eval = function (code) { if (typeof code === 'string' && hasDebugger(code)) { // 含 debugger 的 eval,直接吞掉不执行 return undefined; } return _eval.apply(this, arguments); }; // 覆盖 eval.toString 避免被检测 try { window.eval.toString = function () { return _eval.toString(); }; } catch (e) {} // ===== 3. 拦截 Function 构造器(new Function('debugger') 或 Function('debugger'))===== var _Function = window.Function; var _FunctionProto = window.Function.prototype; var safeFunction = function () { var args = Array.prototype.slice.call(arguments); var body = args[args.length - 1] || ''; var s = typeof body === 'string' ? body : String(body); if (hasDebugger(s)) { // 含 debugger,返回一个空函数 return function () {}; } return _Function.apply(this, args); }; safeFunction.prototype = _FunctionProto; safeFunction.toString = function () { return _Function.toString(); }; safeFunction.prototype.constructor = safeFunction; window.Function = safeFunction; // 同时覆盖 Object.prototype.constructor 链上的 Function(有些混淆代码用 .constructor 取 Function) try { var _ObjProto = Object.prototype; // 不改原型链本身,只改 window.Function 引用 // 拦截 (function(){}).constructor,即所有函数的 constructor 属性指向 // 通过覆盖 Function.prototype.constructor 即可,已在上面处理 } catch (e) {} // ===== 4. 拦截 requestAnimationFrame(另一常见循环入口)===== var _rAF = window.requestAnimationFrame; window.requestAnimationFrame = function (cb) { if (typeof cb === 'function' && hasDebugger(cb)) { return 0; } return _rAF.apply(this, arguments); }; // ===== 5. 拦截间接 eval(通过 window.eval 的别名,如 (0, eval))===== // 有些混淆代码用 (0, eval)('debugger') 绕过。用更底层的办法: // 通过 Object.defineProperty 在 globalThis 上覆盖 eval 的 getter try { var _origEvalDesc = Object.getOwnPropertyDescriptor(window, 'eval'); if (_origEvalDesc && _origEvalDesc.configurable) { Object.defineProperty(window, 'eval', { get: function () { return function (code) { if (typeof code === 'string' && hasDebugger(code)) return undefined; return _eval(code); }; }, set: function (v) { /* 阻止页面覆盖我们的拦截 */ }, configurable: true }); } } catch (e) {} console.log('%c[反调试解除] 已拦截 debugger 死循环,F12 可正常使用', 'color:#00c853;font-weight:bold'); })();