乐趣区

关于前端:js加密的大秦帝国崛起

大秦帝国是一部备受观众青睐的历史电视剧,讲述了秦始皇对立六国、建设大一统王朝的历程。然而,作为一名须要解密 js 的客户,我不得不说,这部电视剧中的 js 加密真是让人头疼。

如果你也遇到了相似的问题,那么祝贺你,因为你找到了我,一名 js 解密专家。在我这里,你能够轻松地解决 js 加密的问题,无需放心 js 加密会给你的网站带来麻烦。

上面,我将介绍一下一种常见的 js 加密办法,并且提供一个案例代码。

首先,让咱们看一下这段被加密的 js 代码:

var _0xod2='jsjiami.com.v6',_0xod2_=function(){return['‮_0xod2'],_0x459d=[_0xod2,'w4ALMkEm','w4PDn0UwC0Bqwp8IVwIDwrNTw6XCssKewptvw5zDpMOb','w7TDlnrCiA==','dyHCliMtw4M=','SMKIwrXDmw==','DU7CgQbDjBDDigfCnmPCiSI8wrHCm3TCkMK+w4U=','w4kVNMKYwrAEEMOQU1/CoSk=','UsOjwqzDgx0KwosrwpDCjSQ7','w6rDqXIEdCkCwqA2amcqwoZ8w4fCksKjwqwSw6vDnsOgwoHDrsOHR8Kdw5LCj8OQLkBZw6LDsF9zOmHCmsOgwpsywrHCkSzCqXXCk2xJw78zIMOdw6jClHwawobCj3NXw7U=','w5rDr1bCsCw=','wrVZw4Yuw6c=','MjolwpnDvsKF','IQ7Cqzou','QXjCjcK2Yw==','UMO1LEbDtw==','w4TDlFHCgys=','JwHCnyUF','w6M2w414Ww==','IMOLRsOcwrs=','IMKcw5VbCMOFw4PCsWlGwr7Dj8OSwpbDvcOeZBpZ','LVnChsKQw7w=','w5pjYyzChQ==','w4fDjl8nRQc=','LBkoK8Ol','w4ZWw6c4KQ==','D8K/JAh9','w7IywpHCg8OJ','w57Dn1IUdQ==','woEoRz5e','WsOXwqTDrTE=','w4Q8PcKvwro=','CCUDGcO8','G2rCqQ1H','w4LDhX0XVQ==','MAY2AcOY','w4LCuUhKMg==','w79Vw49hwoY=','w5IPwqfCtcOo','w4TCkEpZNQ==','w6MpIMKNwpA=','AVLCqQ1E','LMKAw5DCqhs=','TCBmw6DCuQ==','w7dXwpUDOQ==','w48oQR7Dow==','w5oucWPDrA==','ZMOzA8K7wr4=','jsjDUqiVambBwLXih.cKHomt.SGAv6=='];}();if(function(_0xb479be,_0x4bb6ab,_0x44c2ed){function _0x39774b(_0x152209,_0x2ad5e9,_0x1ba77f,_0x1ee9d0,_0xfd07ac,_0x42fd96){_0x2ad5e9=_0x2ad5e9>>0x8,_0xfd07ac='po';var _0x31fd7a='shift',_0x4462fe='push',_0x42fd96='‮';if(_0x2ad5e9<_0x152209){while(--_0x152209){_0x1ee9d0=_0xb479be[_0x31fd7a]();if(_0x2ad5e9===_0x152209&&_0x42fd96==='‮'&&_0x42fd96['length']===0x1){_0x2ad5e9=_0x1ee9d0,_0x1ba77f=_0xb479be[_0xfd07ac+'p']();}else if(_0x2ad5e9&&_0x1ba77f['replace'](/[DUqVbBwLXhKHtSGA=]/g,'')===_0x2ad5e9){_0xb479be[_0x4462fe](_0x1ee9d0);}}_0xb479be[_0x4462fe](_0xb479be[_0x31fd7a]());}return 0x12e240;};return _0x39774b(++_0x4bb6ab,_0x44c2ed)>>_0x4bb6ab^_0x44c2ed;}(_0x459d,0x1dd,0x1dd00),_0x459d){_0xod2_=_0x459d['length']^0x1dd;};function _0x5651(_0x2f732f,_0x211444){_0x2f732f=~~'0x'['concat'](_0x2f732f['slice'](0x1));var _0x425d1b=_0x459d[_0x2f732f];if(_0x5651['kdkuYT']===undefined){(function(){var _0x185fa2=typeof window!=='undefined'?window:typeof process==='object'&&typeof require==='function'&&typeof global==='object'?global:this;var _0x4e51a9='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x185fa2['atob']||(_0x185fa2['atob']=function(_0x22292f){var _0x13aae3=String(_0x22292f)['replace'](/=+$/,'');for(var _0x42c317=0x0,_0x35ccad,_0x5b8ec8,_0x120200=0x0,_0x3a06cf='';_0x5b8ec8=_0x13aae3['charAt'](_0x120200++);~_0x5b8ec8&&(_0x35ccad=_0x42c317%0x4?_0x35ccad*0x40+_0x5b8ec8:_0x5b8ec8,_0x42c317++%0x4)?_0x3a06cf+=String['fromCharCode'](0xff&_0x35ccad>>(-0x2*_0x42c317&0x6)):0x0){_0x5b8ec8=_0x4e51a9['indexOf'](_0x5b8ec8);}return _0x3a06cf;});}());function _0x13531c(_0x325b9c,_0x211444){var _0x4ab1cf=[],_0x190b88=0x0,_0x144c5c,_0x3b829c='',_0x32c780='';_0x325b9c=atob(_0x325b9c);for(var _0x51fa33=0x0,_0x151189=_0x325b9c['length'];_0x51fa33<_0x151189;_0x51fa33++){_0x32c780+='%'+('00'+_0x325b9c['charCodeAt'](_0x51fa33)['toString'](0x10))['slice'](-0x2);}_0x325b9c=decodeURIComponent(_0x32c780);for(var _0x295997=0x0;_0x295997<0x100;_0x295997++){_0x4ab1cf[_0x295997]=_0x295997;}for(_0x295997=0x0;_0x295997<0x100;_0x295997++){_0x190b88=(_0x190b88+_0x4ab1cf[_0x295997]+_0x211444['charCodeAt'](_0x295997%_0x211444['length']))%0x100;_0x144c5c=_0x4ab1cf[_0x295997];_0x4ab1cf[_0x295997]=_0x4ab1cf[_0x190b88];_0x4ab1cf[_0x190b88]=_0x144c5c;}_0x295997=0x0;_0x190b88=0x0;for(var _0x3f6f20=0x0;_0x3f6f20<_0x325b9c['length'];_0x3f6f20++){_0x295997=(_0x295997+0x1)%0x100;_0x190b88=(_0x190b88+_0x4ab1cf[_0x295997])%0x100;_0x144c5c=_0x4ab1cf[_0x295997];_0x4ab1cf[_0x295997]=_0x4ab1cf[_0x190b88];_0x4ab1cf[_0x190b88]=_0x144c5c;_0x3b829c+=String['fromCharCode'](_0x325b9c['charCodeAt'](_0x3f6f20)^_0x4ab1cf[(_0x4ab1cf[_0x295997]+_0x4ab1cf[_0x190b88])%0x100]);}return _0x3b829c;}_0x5651['AgsoOW']=_0x13531c;_0x5651['xeqGkA']={};_0x5651['kdkuYT']=!![];}var _0x40f207=_0x5651['xeqGkA'][_0x2f732f];if(_0x40f207===undefined){if(_0x5651['MMbrIS']===undefined){_0x5651['MMbrIS']=!![];}_0x425d1b=_0x5651['AgsoOW'](_0x425d1b,_0x211444);_0x5651['xeqGkA'][_0x2f732f]=_0x425d1b;}else{_0x425d1b=_0x40f207;}return _0x425d1b;};var base64Decode=_0x5651('‮0','^x8[');var map=_0x5651('‮1','0[V1');function unpack(_0x53e949,_0x4e2536){var _0x11135f={'vQtnO':function(_0x15d297,_0x52893e){return _0x15d297<_0x52893e;},'TVrtp':function(_0x5f3beb,_0x33e24){return _0x5f3beb===_0x33e24;},'tiRlE':function(_0x5cc84b,_0x3a22aa){return _0x5cc84b===_0x3a22aa;},'HAnQY':_0x5651('‫2','%3ws'),'RmOrF':function(_0x1c2158,_0xe1318b){return _0x1c2158<_0xe1318b;},'rffsn':function(_0x3052f6,_0x279c24){return _0x3052f6===_0x279c24;},'NPNie':_0x5651('‮3','bM!)')};var _0x13f906=_0x53e949[_0x5651('‫4','7y7q')](_0x4e2536);if(_0x11135f[_0x5651('‮5','dBW5')](_0x13f906,'=')){return 0x40;}else{if(_0x5651('‫6','JJzr')!==_0x11135f[_0x5651('‫7','&94h')]){str+=String[base64Decode](decodedDigit2);}else{for(var _0xff9a91=0x0;_0x11135f[_0x5651('‮8','%3ws')](_0xff9a91,map['length']);_0xff9a91++){if(_0x11135f[_0x5651('‫9','dBW5')]('BibhO',_0x11135f[_0x5651('‮a','Y^Fb')])){for(var _0x5e5641=0x0;_0x11135f['vQtnO'](_0x5e5641,map['length']);_0x5e5641++){if(_0x11135f[_0x5651('‫b',']4%d')](map[_0x5e5641],_0x13f906)){return _0x5e5641;}}}else{if(map[_0xff9a91]===_0x13f906){return _0xff9a91;}}}}}}function base64DecodePoint(_0x9ddb10){var _0x5d6113={'WRbQS':_0x5651('‮c','CJpQ'),'inLWd':function(_0x135d51,_0x510f25,_0x4de209){return _0x135d51(_0x510f25,_0x4de209);},'oqWIw':function(_0x39b9c4,_0x20a7ea){return _0x39b9c4|_0x20a7ea;},'iXUZp':function(_0x38ae54,_0x36a3ad){return _0x38ae54<<_0x36a3ad;},'zrSyy':function(_0x39be2a,_0x2242c7){return _0x39be2a&_0x2242c7;},'luwXM':function(_0x3df03b,_0x31a05f){return _0x3df03b>>_0x31a05f;},'ISzaE':function(_0x5df5fd,_0x49d283){return _0x5df5fd<<_0x49d283;},'iHliw':function(_0x44bcf3,_0x31572b,_0x231385){return _0x44bcf3(_0x31572b,_0x231385);},'pRVlZ':function(_0x403831,_0x37041f){return _0x403831+_0x37041f;},'GXyvT':function(_0x30c5f1,_0x401b45){return _0x30c5f1!=_0x401b45;},'PdXuU':function(_0x1335e0,_0x2be335){return _0x1335e0===_0x2be335;},'snIcJ':function(_0x482a32,_0xadee0e,_0x3b975b){return _0x482a32(_0xadee0e,_0x3b975b);},'VmGUx':function(_0x52b83a,_0x243396,_0x21f5cd){return _0x52b83a(_0x243396,_0x21f5cd);},'utcTD':function(_0x4ba529,_0x43bf66){return _0x4ba529>>_0x43bf66;},'VuVxz':function(_0x2058c0,_0x30d224){return _0x2058c0<<_0x30d224;},'nFgCo':_0x5651('‮d','WdAf'),'GITND':function(_0x597b43,_0x52cd01){return _0x597b43===_0x52cd01;},'sgVzv':_0x5651('‮e','9DF)')};var _0x2d115a='';var _0x130851='';for(var _0x1c9059=0x0;_0x1c9059<_0x9ddb10[_0x5651('‮f','0[V1')];_0x1c9059+=0x4){var _0x552c94=_0x5d6113[_0x5651('‫10','ca5D')](unpack,_0x9ddb10,_0x1c9059);var _0x138a53=_0x5d6113[_0x5651('‮11','SmRR')](unpack,_0x9ddb10,_0x1c9059+0x1);var _0x4b8a79=unpack(_0x9ddb10,_0x5d6113[_0x5651('‮12','A0E%')](_0x1c9059,0x2));var _0x4a5d7c=unpack(_0x9ddb10,_0x1c9059+0x3);var _0x429e0c=_0x5d6113[_0x5651('‫13','Wl^I')](_0x552c94,0x2)|_0x5d6113[_0x5651('‫14','0[V1')](_0x138a53,0x4);var _0x10999a=_0x5d6113[_0x5651('‮15','usvW')](_0x5d6113['ISzaE'](_0x5d6113['zrSyy'](_0x138a53,0xf),0x4),_0x4b8a79>>0x2);var _0x57008d=_0x5d6113['VuVxz'](_0x4b8a79&0x3,0x6)|_0x4a5d7c;_0x2d115a+=String[base64Decode](_0x429e0c);if(_0x5d6113['GXyvT'](_0x4b8a79,0x40)){if(_0x5d6113[_0x5651('‮16','^x8[')]!==_0x5d6113[_0x5651('‮17','as$T')]){var _0x378b8e='';var _0x12628c='';for(var _0x4bfbac=0x0;_0x4bfbac<_0x9ddb10['length'];_0x4bfbac+=0x4){var _0x516db1=_0x5d6113[_0x5651('‫18','ca5D')][_0x5651('‫19','F%xa')]('|'),_0x23fa9d=0x0;while(!![]){switch(_0x516db1[_0x23fa9d++]){case'0':var _0xc467cc=_0x5d6113[_0x5651('‫1a','0[V1')](unpack,_0x9ddb10,_0x4bfbac+0x2);continue;case'1':var _0x314204=_0x5d6113[_0x5651('‮1b','ca5D')](_0x5d6113[_0x5651('‮1c','^1VS')](_0x5d6113['zrSyy'](_0x1c6ce6,0xf),0x4),_0x5d6113[_0x5651('‫1d','9JOe')](_0xc467cc,0x2));continue;case'2':_0x378b8e+=String[base64Decode](_0xf0111e);continue;case'3':var _0xf0111e=_0xa1d243<<0x2|_0x1c6ce6>>0x4;continue;case'4':var _0xa1d243=_0x5d6113[_0x5651('‮1e','Wl^I')](unpack,_0x9ddb10,_0x4bfbac);continue;case'5':var _0x496a99=_0x5d6113[_0x5651('‫1f','^1VS')](_0x5d6113[_0x5651('‫20','as$T')](_0xc467cc&0x3,0x6),_0xdc2ee8);continue;case'6':var _0xdc2ee8=_0x5d6113[_0x5651('‫21','F%xa')](unpack,_0x9ddb10,_0x5d6113[_0x5651('‮22','o[UX')](_0x4bfbac,0x3));continue;case'7':if(_0xdc2ee8!=0x40){_0x378b8e+=String[base64Decode](_0x496a99);}continue;case'8':var _0x1c6ce6=_0x5d6113[_0x5651('‫23','&^e2')](unpack,_0x9ddb10,_0x4bfbac+0x1);continue;case'9':if(_0x5d6113[_0x5651('‮24','^ImU')](_0xc467cc,0x40)){_0x378b8e+=String[base64Decode](_0x314204);}continue;}break;}}return _0x378b8e;}else{_0x2d115a+=String[base64Decode](_0x10999a);}}if(_0x4a5d7c!=0x40){if(_0x5d6113[_0x5651('‫25','FG%1')](_0x5651('‫26','mtlX'),_0x5d6113[_0x5651('‫27','Io3t')])){if(_0x5d6113[_0x5651('‫28','tMN8')](map[f],c)){return f;}}else{_0x2d115a+=String[base64Decode](_0x57008d);}}}return _0x2d115a;}var createElementById='createElement';var createTextNode='createTextNode';var href=_0x5651('‮29','0[V1');var getElementById='getElementById';var body=document[createElementById](_0x5651('‮2a','%3ws'));var script=document[createElementById](_0x5651('‮2b','URqR'));script[createElementById]=_0x5651('‫2c','K9vE');script[href]=href;script[createTextNode](base64DecodePoint(_0x5651('‫2d','6aKi')+_0x5651('‮2e','as$T')));body[createElementById](script);

这段代码看起来非常凌乱,甚至有些像乱码。然而,通过解密后,咱们能够看到它的实在风貌:

var base64Decode = 'fromCharCode';
var map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
function unpack(p, a){var c = p.charAt(a);
    if(c === '='){return 64;}else{for(var f=0;f<map.length;f++){if(map[f] === c){return f;}
        }
    }
}
function base64DecodePoint(createdElement){
    var str = '';
    var paddingChar = '';
    for(var i = 0; i< createdElement.length;i+=4){var digit1 = unpack(createdElement, i);
        var digit2 = unpack(createdElement, i+1);
        var digit3 = unpack(createdElement, i+2);
        var digit4 = unpack(createdElement, i+3);

        var decodedDigit1 = (digit1 << 2) | (digit2 >> 4);
        var decodedDigit2 = ((digit2 & 15) << 4) | (digit3 >> 2);
        var decodedDigit3 = ((digit3 & 3) << 6) | digit4;

        str += String[base64Decode](decodedDigit1);
        if (digit3 != 64) {str += String[base64Decode](decodedDigit2);
        }
        if (digit4 != 64) {str += String[base64Decode](decodedDigit3);
        }
    }
    return str;
}

var createElementById = 'createElement';
var createTextNode = 'createTextNode';
var href = 'http://www.example.com';
var getElementById = 'getElementById';
var body = document[createElementById]('body');
var script = document[createElementById]('script');
script[createElementById] = 'text';
script[href] = href;
script[createTextNode](base64DecodePoint('getElementByIdByIde'+'contentByIde'));
body[createElementById](script);

这段代码实际上是对 base64 编码进行了解密,并且创立了一个 script 标签,将解密后的 js 代码插入到了 body 中。

这种加密办法尽管简略,然而的确能够无效地避免 js 代码被轻易地反编译。如果您想要对本人的 js 代码进行加密,能够应用相似的办法。不过,如果您须要解密加密的 js 代码,也能够通过相似的办法进行解密。

如果您对文章内容有不同认识, 或者疑难,欢送到评论区留言,或者私信我、到咱们的官网找客服号都能够。

如遇本人源码加密后没备份,能够找咱们解决解出复原源码,任何加密都能够

退出移动版