js代码function(p,a,c,k,e,r)加密方式如何解密

下面是一段加密后的代码,很晕吧,但事实上只是使用了障眼法,把换行取消掉了而已,让我们排版一下再来看看到底是什么?

eval(function(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c–)r[e(c)]=k||e(c);k=[function(e){return r[e]}];e=function(){return'\w+'};c=1};while(c–)if(k)p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k);return p}('1 t;1 y=R;1 i=l;1 f=x;1 8=2.K;1 6='';5 C(a){i=l;f=x;8=2.13;y=Z;6=a;v();u()}5 u(){k(t!=q){t.L.J=6;t.r()}}5 j(){k(t==q){3.4(“7″).B=”7”;3.4(“7″).9.1a=”18”;t=12 10.X('h',{8:8,T:i,S:f,Q:i,P:f,O:'7',6:6});k(!3.N.M){o();t.r()}}}5 v(){p.n(I,'H',j);p.n(3.4(“h”),'G',j)}5 o(){1 a=3.4(“7”);1 b=3.4(“F”);1 c=0;1 d=0;1 e=b.m;E(e.D!=”V”){c=c+e.W;d=d+e.A;e=e.m}c=c+Y/2+3.4(“h”).19/2;d=d+3.4(“h”).z-17(a.9.z);a.9.14=d+”w”;a.9.11=c+”w”}5 15(a){1 b=16(a).U(/^[\s]+|[\s]+$/g,'');1b b}',62,74,'|var||document|getElementById|function|previewSrc|previewArea|radio|style||||||mHeight||testImage|mWidth|createPreview|if|85|offsetParent|observe|setPreviewWrapPos|Event|null|reset|||resetPreview|observe_pic|px|70|isNeck|height|offsetTop|className|initProduct|tagName|while|pbigImg|mouseover|load|window|src|6666667|previewImg|attachEvent|body|previewWrap|maxHeight|maxWidth|false|minHeight|minWidth|replace|BODY|offsetLeft|ImgWithPreview|310|true|Cropper|left|new|666666667|top|Trim|String|parseInt|absolute|width|position|return'.split('|'),0,{}))

排版后

eval(
function(p,a,c,k,e,r){
e = function(c){
return(c35?String.fromCharCode(c+29):c.toString(36))
};
if(!''.replace(/^/,String)) {
while(c–)r[e(c)]=k||e(c);
k = [function(e){return r[e]}];
e = function(){return'\w+'};
c = 1
};
while (c–) if(k)p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k);
return p;
}('1 t;1 y=R;1 i=l;1 f=x;1 8=2.K;1 6='';5 C(a){i=l;f=x;8=2.13;y=Z;6=a;v();u()}5 u(){k(t!=q){t.L.J=6;t.r()}}5 j(){k(t==q){3.4(“7″).B=”7”;3.4(“7″).9.1a=”18”;t=12 10.X('h',{8:8,T:i,S:f,Q:i,P:f,O:'7',6:6});k(!3.N.M){o();t.r()}}}5 v(){p.n(I,'H',j);p.n(3.4(“h”),'G',j)}5 o(){1 a=3.4(“7”);1 b=3.4(“F”);1 c=0;1 d=0;1 e=b.m;E(e.D!=”V”){c=c+e.W;d=d+e.A;e=e.m}c=c+Y/2+3.4(“h”).19/2;d=d+3.4(“h”).z-17(a.9.z);a.9.14=d+”w”;a.9.11=c+”w”}5 15(a){1 b=16(a).U(/^[\s]+|[\s]+$/g,'');1b b}',62,74,'|var||document|getElementById|function|previewSrc|previewArea|radio|style||||||mHeight||testImage|mWidth|createPreview|if|85|offsetParent|observe|setPreviewWrapPos|Event|null|reset|||resetPreview|observe_pic|px|70|isNeck|height|offsetTop|className|initProduct|tagName|while|pbigImg|mouseover|load|window|src|6666667|previewImg|attachEvent|body|previewWrap|maxHeight|maxWidth|false|minHeight|minWidth|replace|BODY|offsetLeft|ImgWithPreview|310|true|Cropper|left|new|666666667|top|Trim|String|parseInt|absolute|width|position|return'.split('|'),0,{}))

那么熟悉这种函数写法的应该就能明白这个加密原理了吧。只要细心点就能发现其实这种加密手段是用来防止一些拿来主意者。上面加密的js代码如果想得到其原代码可以在“return p;” 之前打印出来既可,例如:“document.writeln(p);”。 顺便介绍一下 eval 方法。

eval 方法
检查 Javascript 代码并执行.

eval(codeString)

必选项 codestring 参数是包含有效 Javascript 代码的字符串值。这个字符串将由 Javascript 分析器进行分析和执行。

说明
eval 函数允许 Javascript 源代码的动态执行。例如,下面的代码创建了一个包含 Date 对象的新变量 mydate :

eval(“var mydate = new Date();”);
传递给 eval 方法的代码执行时的上下文和调用 eval 方法的一样.
这种语法是这样的,例如代码:

var test_func = function (par1, par2) {
alert("par1: "+par1+"npar2: "+par2);
}("我是第一个参数。", "还有我是第二个参数");

和下面代码效果是一样的:

function test_func (par1, par2) {
alert("par1: "+par1+"npar2: "+par2);
}
test_func("我是第一个参数。", "还有我是第二个参数");

解密function(p,a,c,k,e,r)用脚本,运行即可见效果:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <html>
      <HEAD>
        <TITLE> js加密解密 - 志文工作室 </TITLE>
        <META NAME="Generator" CONTENT="EditPlus">
        <META NAME="Author" CONTENT="">
        <META NAME="Keywords" CONTENT="">
        <META NAME="Description" CONTENT="">
      </HEAD> 
      <body>

    <script type="text/javascript"> 
      a=62; 
      function encode() { 
      var code = document.getElementById('code').value; 
      code = code.replace(/[rn]+/g, ''); 
      code = code.replace(/'/g, "\'"); 
      var tmp = code.match(/b(w+)b/g); 
      tmp.sort(); 
      var dict = []; 
      var i, t = ''; 
      for(var i=0; i<tmp.length; i++) { 
        if(tmp<span style="text-decoration: line-through;"> != t) dict.push(t = tmp<span style="text-decoration: line-through;">); 
      } 
      var len = dict.length; 
      var ch; 
      for(i=0; i<len; i++) { 
        ch = num(i); 
        code = code.replace(new RegExp('\b'+dict<span style="text-decoration: line-through;">+'\b','g'), ch); 
        if(ch == dict<span style="text-decoration: line-through;">) dict<span style="text-decoration: line-through;"> = ''; 
      } 
      document.getElementById('code').value = "eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k)p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k);return p}(" + "'"+code+"',"+a+","+len+",'"+ dict.join('|')+"'.split('|'),0,{}))"; 
      } 
      function num(c) { 
      return(c<a?'':num(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36));

      } 
      function run() { 
      eval(document.getElementById('code').value); 
      } 
      function decode() { 
      var code = document.getElementById('code').value; 
      code = code.replace(/^eval/, ''); 
      document.getElementById('code').value = eval(code); 
      } 
      </script> 
      <textarea id=code cols=80 rows=20> 
      </textarea> 
      <input type=button onclick=encode() value="编码(Encode)" /> 
      <input type=button onclick=run() value="(运行)Run" /> 
      <input type=button onclick=decode() value="解码(Decode)" /> 
      </body>
      </html>

推荐一个不错的在线加密解密工具:http://issmall.isgreat.org/

点赞 (1)

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Captcha Code