通用Debugger拦截器

// ==UserScript==
// @name         通用Debugger拦截器
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  拦截并阻止网站使用debugger进行反调试
// @author       doubao
// @match        *://*/*
// @grant        document-start
// ==/UserScript==

(function() {
    'use strict';

    // Hook构造函数
    Function.prototype._constructor = Function.prototype.constructor;
    Function.prototype.constructor = function() {
        if (arguments.toString().includes("debugger")) {
            return null;
        }
        return Function.prototype._constructor.apply(this, arguments);
    };

    // Hook Function
    const F_ = Function;
    Function = function(s) {
        if (s === 'debugger') {
            return () => {};
        }
        return F_.apply(this, arguments);
    };
    Function.prototype = F_.prototype;

    // Hook eval
    const eval_ = eval;
    eval = function(a) {
        if (a && a.toString().includes("debugger")) {
            return "";
        }
        return eval_.call(window, a);
    };

    // Hook setInterval
    const setInterval_back = setInterval;
    setInterval = function(a, b) {
        if (a.toString().includes('debugger')) {
            return null;
        }
        return setInterval_back.apply(this, arguments);
    };

    // Hook setTimeout
    const setTimeout_back = setTimeout;
    setTimeout = function(a, b) {
        if (a.toString().includes('debugger')) {
            return null;
        }
        return setTimeout_back.apply(this, arguments);
    };

    // Hook HTML插入
    const oldAppendChild = Node.prototype.appendChild;
    Node.prototype.appendChild = function() {
        if (arguments[0] && arguments[0].innerHTML && arguments[0].innerHTML.indexOf('debugger') !== -1) {
            arguments[0].innerHTML = arguments[0].innerHTML.replace(/debugger/g, '');
        }
        return oldAppendChild.apply(this, arguments);
    };

    // Hook属性设置
    const oldSetAttribute = Element.prototype.setAttribute;
    Element.prototype.setAttribute = function(name, value) {
        if (name === 'onload' && value.includes('debugger')) {
            value = value.replace(/debugger/g, '');
        }
        return oldSetAttribute.apply(this, arguments);
    };

    console.log('[Debugger拦截器] 已启动,正在保护您的浏览器环境');
})();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值