天天看點

最新js解密方法

廢話不多說,代碼敏感,隻上部分。

源代碼

(function() {
    let _0xce6384;
    try {
        const _0x20cdc4 = Function('return\x20(function()\x20' + '{}.constructor(\x22return\x20this\x22)(\x20)' + ');');
        _0xce6384 = _0x20cdc4();
    } catch (_0x46317e) {
        _0xce6384 = window;
    }
    const _0x348798 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    _0xce6384['atob'] || (_0xce6384['atob'] = function(_0x4e070f) {
        const _0x1d59b8 = String(_0x4e070f)['replace'](/=+$/, '');
        let _0x1dc99e = '';
        for (let _0x3327e6 = 0x0, _0x169c0b, _0x52066b, _0x4f42b7 = 0x0; _0x52066b = _0x1d59b8['charAt'](_0x4f42b7++); ~_0x52066b && (_0x169c0b = _0x3327e6 % 0x4 ? _0x169c0b * 0x40 + _0x52066b : _0x52066b, _0x3327e6++ % 0x4) ? _0x1dc99e += String['fromCharCode'](0xff & _0x169c0b >> (-0x2 * _0x3327e6 & 0x6)) : 0x0) {
            _0x52066b = _0x348798['indexOf'](_0x52066b);
        }
        return _0x1dc99e;
    });
}());      

先在​​JS加密​​工具站初步解一下碼,太複雜的也可以找客服人工解碼

(function() {
    let _0xce6384;
    try {
        const _0x20cdc4 = Function('return (function() ' + '{}.constructor("return this")( )' + ');');
        _0xce6384 = _0x20cdc4();
    } catch (_0x46317e) {
        _0xce6384 = window;
    }
    const _0x348798 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
    _0xce6384['atob'] || (_0xce6384['atob'] = function(_0x4e070f) {
        const _0x1d59b8 = String(_0x4e070f)['replace'](/=+$/, '');
        let _0x1dc99e = '';
        for (let _0x3327e6 = 0x0, _0x169c0b, _0x52066b, _0x4f42b7 = 0x0; _0x52066b = _0x1d59b8['charAt'](_0x4f42b7++); ~_0x52066b && (_0x169c0b = _0x3327e6 % 0x4 ? _0x169c0b * 0x40 + _0x52066b : _0x52066b, _0x3327e6++ % 0x4) ? _0x1dc99e += String['fromCharCode'](0xff & _0x169c0b >> (-0x2 * _0x3327e6 & 0x6)) : 0x0) {
            _0x52066b = _0x348798['indexOf'](_0x52066b);
        }
        return _0x1dc99e;
    });
}());      

問題點

這個JS加密在NodeJs環境下運作會報錯,window對象找不到,這個比較好解決,直接var window = global;就行了,随後又報錯,atob方法找不到。

由此可以分析出,由于nodejs中沒有window對象,隻有global,而global中又沒有atob方法。

解決方法

window内置的atob和btoa其實就是Base64的加密解密方法,我們自己用js寫一個Base64就行了,之前的文章中也有寫過,代碼可以在往期文章中找。

完全解碼後(部分代碼)

function base64Success() {
  if (H5Url.indexOf('?') != -1) {
    H5Url += "&isQuickapp=1";
  } else {
    H5Url += "?isQuickapp=1";
  }

  webUrlBase64 = Base64.encode("{\"url\":\"" + H5Url + "\"}");
}

function getQueryVariable(url) {
  var searchStr = window.location.search.substring(1);

  var prmAry = searchStr.split('&');

  for (var i = 0; i < prmAry.length; i++) {
    var prm = prmAry[i].split('=');

    if (prm[0] == url) {
      return prm[1];
    }
  }

  return false;
}      

結語