防止页面被非法调试的方法以及前端页面加密的方法

2022-10-28 12:09:18 浏览数 (1)

阻止非法调试

方法一:

代码语言:javascript复制
// var element = new Image();
 Object.defineProperty(element,'id',{get:function(){window.location.href="https://www.baidu.com"}});

方法二:

代码语言:javascript复制
// 反调试函数,参数:开关,执行代码
    function endebug(off, code) {
        if (!off) {
            ! function(e) {
                function n(e) {
                    function n() {
                        return u;
                    }

                    function o() {
                        window.Firebug && window.Firebug.chrome && window.Firebug.chrome.isInitialized ? t("on") : (a = "off", console.log(d), console.clear(), t(a));
                    }

                    function t(e) {
                        u !== e && (u = e, "function" == typeof c.onchange && c.onchange(e));
                    }

                    function r() {
                        l || (l = !0, window.removeEventListener("resize", o), clearInterval(f));
                    }
                    "function" == typeof e && (e = {
                        onchange: e
                    });
                    var i = (e = e || {}).delay || 500,
                        c = {};
                    c.onchange = e.onchange;
                    var a, d = new Image;
                    d.__defineGetter__("id", function() {
                        a = "on"
                    });
                    var u = "unknown";
                    c.getStatus = n;
                    var f = setInterval(o, i);
                    window.addEventListener("resize", o);
                    var l;
                    return c.free = r, c;
                }
                var o = o || {};
                o.create = n, "function" == typeof define ? (define.amd || define.cmd) && define(function() {
                    return o
                }) : "undefined" != typeof module && module.exports ? module.exports = o : window.jdetects = o
            }(), jdetects.create(function(e) {
                var a = 0;
                var n = setInterval(function() {
                    if ("on" == e) {
                        setTimeout(function() {
                            if (a == 0) {
                                a = 1;
                                setTimeout(code);
                            }
                        }, 200);
                    }
                }, 100);
            })
        }
    }

调用方法

代码语言:javascript复制
 endebug(false, function() {
    // 非法调试执行的代码(不要使用控制台输出的提醒)
    document.write("检测到非法调试,请关闭后刷新重试!");
});

前端代码加密网站:

https://www.sojson.com/charEncode.html

如上述方案一的代码加密后:

代码语言:javascript复制
;var encode_version = 'sojson.v5', eachd = '__0x899ea',  __0x899ea=['wqnClMKxKcKC','wrd1VBTDhQ==','w7ojRsKVw7TChR8G','w5XCu1TDhw==','w7U4AsKOwqQ=','Y21f','w4vCoMKR','w5XCusKp','54us5p I5Y i776bwqnDnuS l WtneactuW/mOeqh  8pei oOiulOaXrOaOjuaLu S5gOeZneW3tOS8hw==','w5gvDQ==','RcORwo5AGgtcDGE=','w6UjT8KHw6/Cgl4eTA==','5Ym46ZqS54uw5p2z5Y B7768wp0j5L b5ayq5p2P5b2N56mq','Om8qHxo=','FcKlw74=','wr1Qw7LDmmDCtho/Og==','wo0mw6BOPw==','54uK5p6l5Y24772ww7V65L X5ay15pyA5b 756ug77yB6LyJ6K2m5pSX5o6i5oqy5Lqj55u85baL5L6L','Kk49Dyg=','VsOAw6fDm10=','fMOWw7XDsm4=','wq5ZWBvDgQ==','wqLCrsKjCMKT','wr7DncO1wrHCmQ=='];(function(_0x51f261,_0x1027c7){var _0x2ed6ea=function(_0x4a3b40){while(--_0x4a3b40){_0x51f261['push'](_0x51f261['shift']());}};_0x2ed6ea(  _0x1027c7);}(__0x899ea,0x7a));var _0x4a7f=function(_0x3fbbff,_0x1e8ac1){_0x3fbbff=_0x3fbbff-0x0;var _0x73d2fb=__0x899ea[_0x3fbbff];if(_0x4a7f['initialized']===undefined){(function(){var _0x204bb5=typeof window!=='undefined'?window:typeof process==='object'&&typeof require==='function'&&typeof global==='object'?global:this;var _0xfedab1='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 /=';_0x204bb5['atob']||(_0x204bb5['atob']=function(_0x3bca93){var _0x3cec97=String(_0x3bca93)['replace'](/= $/,'');for(var _0x57d638=0x0,_0x492ef0,_0x483bc0,_0x2cee4c=0x0,_0x3b7158='';_0x483bc0=_0x3cec97['charAt'](_0x2cee4c  );~_0x483bc0&&(_0x492ef0=_0x57d638%0x4?_0x492ef0*0x40 _0x483bc0:_0x483bc0,_0x57d638  %0x4)?_0x3b7158 =String['fromCharCode'](0xff&_0x492ef0>>(-0x2*_0x57d638&0x6)):0x0){_0x483bc0=_0xfedab1['indexOf'](_0x483bc0);}return _0x3b7158;});}());var _0x4111fd=function(_0x409262,_0x2f9ccc){var _0x386d0a=[],_0x4a57db=0x0,_0x149a09,_0x43c064='',_0x110c79='';_0x409262=atob(_0x409262);for(var _0x52f3c0=0x0,_0x18ba07=_0x409262['length'];_0x52f3c0<_0x18ba07;_0x52f3c0  ){_0x110c79 ='%' ('00' _0x409262['charCodeAt'](_0x52f3c0)['toString'](0x10))['slice'](-0x2);}_0x409262=decodeURIComponent(_0x110c79);for(var _0x5735a9=0x0;_0x5735a9<0x100;_0x5735a9  ){_0x386d0a[_0x5735a9]=_0x5735a9;}for(_0x5735a9=0x0;_0x5735a9<0x100;_0x5735a9  ){_0x4a57db=(_0x4a57db _0x386d0a[_0x5735a9] _0x2f9ccc['charCodeAt'](_0x5735a9%_0x2f9ccc['length']))%0x100;_0x149a09=_0x386d0a[_0x5735a9];_0x386d0a[_0x5735a9]=_0x386d0a[_0x4a57db];_0x386d0a[_0x4a57db]=_0x149a09;}_0x5735a9=0x0;_0x4a57db=0x0;for(var _0x5b2357=0x0;_0x5b2357<_0x409262['length'];_0x5b2357  ){_0x5735a9=(_0x5735a9 0x1)%0x100;_0x4a57db=(_0x4a57db _0x386d0a[_0x5735a9])%0x100;_0x149a09=_0x386d0a[_0x5735a9];_0x386d0a[_0x5735a9]=_0x386d0a[_0x4a57db];_0x386d0a[_0x4a57db]=_0x149a09;_0x43c064 =String['fromCharCode'](_0x409262['charCodeAt'](_0x5b2357)^_0x386d0a[(_0x386d0a[_0x5735a9] _0x386d0a[_0x4a57db])%0x100]);}return _0x43c064;};_0x4a7f['rc4']=_0x4111fd;_0x4a7f['data']={};_0x4a7f['initialized']=!![];}var _0x4ac9d6=_0x4a7f['data'][_0x3fbbff];if(_0x4ac9d6===undefined){if(_0x4a7f['once']===undefined){_0x4a7f['once']=!![];}_0x73d2fb=_0x4a7f['rc4'](_0x73d2fb,_0x1e8ac1);_0x4a7f['data'][_0x3fbbff]=_0x73d2fb;}else{_0x73d2fb=_0x4ac9d6;}return _0x73d2fb;};Object['defineProperty'](element,'id',{'get':function(){var _0x5b46b2={'Mcwkk':'https://www.baidu.com'};window[_0x4a7f('0x0','KP#0')][_0x4a7f('0x1','vAEu')]=_0x5b46b2[_0x4a7f('0x2','bQBx')];}});;(function(_0x136402,_0x51b22b,_0x5454a7){var _0x13b02f={'hZmdt':function _0x353016(_0x16a0ce,_0x49d464){return _0x16a0ce===_0x49d464;},'qlpFj':_0x4a7f('0x3',']b09'),'dYHIx':function _0x5205b3(_0x376a9a,_0x5e3d90){return _0x376a9a===_0x5e3d90;},'KsaCX':_0x4a7f('0x4','Di8k'),'laopY':_0x4a7f('0x5','^8D8'),'dHJiv':function _0x5d676f(_0x4478a8,_0xd0373d){return _0x4478a8 _0xd0373d;},'aMgVX':function _0x141585(_0x2b4ec1,_0x17e6ec){return _0x2b4ec1 _0x17e6ec;},'hNCcy':_0x4a7f('0x6','@KEI'),'BXQJJ':_0x4a7f('0x7','i96$'),'PiUeS':function _0x571800(_0xc58e0f,_0xd73df5){return _0xc58e0f!==_0xd73df5;},'FyuIJ':_0x4a7f('0x8','rS@!'),'sGXGG':_0x4a7f('0x9','KP#0'),'aQFiR':function _0x10f588(_0xb7d3f8,_0x41b913){return _0xb7d3f8 _0x41b913;},'jkTHC':_0x4a7f('0xa','feyi')};_0x5454a7='al';try{if(_0x13b02f['hZmdt']('WWe',_0x13b02f[_0x4a7f('0xb','t69k')])){_0x5454a7 =_0x4a7f('0xc','2t2^');_0x51b22b=encode_version;if(!(typeof _0x51b22b!==_0x4a7f('0xd','8IVu')&&_0x51b22b==='sojson.v5')){if(_0x13b02f[_0x4a7f('0xe','mV6(')](_0x13b02f['KsaCX'],_0x13b02f['laopY'])){_0x136402[_0x5454a7](_0x13b02f['dHJiv']('删除',_0x4a7f('0xf','R0Kq')));}else{_0x136402[_0x5454a7](_0x13b02f[_0x4a7f('0x10','t69k')]('删除',_0x13b02f[_0x4a7f('0x11','nVHb')]));}}}else{_0x5454a7='al';try{_0x5454a7 =_0x13b02f[_0x4a7f('0x12','nVHb')];_0x51b22b=encode_version;if(!(_0x13b02f['PiUeS'](typeof _0x51b22b,_0x13b02f['FyuIJ'])&&_0x51b22b===_0x13b02f[_0x4a7f('0x13','qqoT')])){_0x136402[_0x5454a7](_0x13b02f[_0x4a7f('0x14','MV5]')]('删除',_0x13b02f[_0x4a7f('0x15','%Hq*')]));}}catch(_0xd584ea){_0x136402[_0x5454a7](_0x13b02f[_0x4a7f('0x16','MV5]')]);}}}catch(_0x187e1f){_0x136402[_0x5454a7](_0x13b02f[_0x4a7f('0x17','qqoT')]);}}(window));;encode_version = 'sojson.v5';

0 人点赞