天天看点

JavaScript 之 解码类似eval(function(p,a,c,k,e,d){}))的JavaScript代码

  这里以解码百度访问统计代码构造函数为示例:

  以下为要统计javascript源码:红色加粗部分将是要修改的地方。

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[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new regexp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('p w(e,d,a,c,b){5.r=8.14(e);5.o=d;5.d=a;5.r=(8.e)?c:(c-2);5.q=0;5.b=b+((8.e)?0:-2);5.x=5.d[0];5.o=5.d[5.d.c-1]}w.p.y=p(b){9 a=15.16(((b-5.x)*5.b/(5.o-5.x)))+((8.e)?2:0);s(a>5.b){a=5.b}17 a};w.p.18=p(){9 a=8.i("k");a.a="1a";a.6.z=5.b+"7";5.r.j(a);9 k=8.i("k");a.j(k);k.a="1b";9 j=0;q(9 g=0;g<5.o.c;g+=2){9 b=5.y(5.o[g]);9 i=5.o[g+1];9 f=8.i("k");a.j(f);f.a="u";f.6.n=5.r+"7";f.6.z=b+"7";f.6.m=5.b-b-1+"7";f.6.g=(j-1)+"7";f.h="&v;";f.f=k;f.t=p(){5.a="v";5.f.6.l="";5.f.h=5.t.l(3,5.t.c);5.f.6.g=5.6.g;5.f.6.m=s(5.6.m)-s(5.f.19)+"7"};f.w=p(){5.a="u";5.f.6.l="z"};9 e=8.i("k");a.j(e);e.6.n=5.r+"7";e.6.m=(8.e)?5.b:5.b+3+"7";9 c=i.10(".");f.t="u"+i.l(0,c)+"\\11"+i.l(c+1,i.c)+"\\12&v;&v;"+5.o[g];s(g%4==0){s((i.l(c+1,i.c)=="1"||i.l(c+1,i.c)=="2")){e.a="13";e.6.g=(j-4)+"7";e.h=i}n{e.a="m";e.6.g=(j-1)+"7";e.h=i.l(c+1,i.c)}}n{e.a="m";e.6.g=(j-1)+"7";e.h=""}j+=5.r+((8.e)?-1:1)}5.q=j+((8.e)?1:-1);a.6.n=5.q+"7";q(9 g=0;g<5.d.c;g++){9 d=5.y(5.d[g]);s(g!=0&&g!=5.d.c-1){9 h=8.i("k");a.j(h);h.a="x";h.6.n=(5.q-((8.e)?1:-1))+"7";h.6.m=(5.b-d-1)+"7"}9 e=8.i("k");a.j(e);e.a="1c";e.6.n="y";e.6.m=(5.b-d-2)+"7";e.6.g=-u+"7";e.h=5.d[g]}};',62,75,'|||||this|style|px|document|var|classname|charth|length|yl|all|ohit|left|innerhtml|createelement|appendchild|div|substring|top|width|xl|function|chartw|barw|if|id|bar|nbsp|chart|minpv|getpvheight|height||||||||||||display|titx|else|maxpv|prototype|for|parent|parseint|onmouseover|42|barhl|onmouseout|liney|35px|none|indexof|u6708|u65e5|titxhl|getelementbyid|math|round|return|create|offsetheight|chart|hit|tity'.split('|'),0,{}));

  其实这个eval(function(p,a,c,k,e,d){}))中自带解码函数e()。

  while(c--){if(k[c]){p=p.replace(new regexp('\\b'+e(c)+'\\b','g'),k[c])}}return p

  while循环产生的每个p就是解码后的函数代码,我们删掉源码中的return p,不用将结果返回,而是直接输出在一个文本区域中,如document.getelementbyid(”textareaid”).innertext=p。

  最终代码:

< !doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

< html xmlns="http://www.w3.org/1999/xhtml">

< head>

< title> crack baidu统计构造函数</title>

< meta http-equiv="content-type" content="text/html; charset=utf-8" />

< meta http-equiv="x-ua-compatible" content="ie=emulateie7" />

< meta name="author" content=www.gemingcao.com />

< meta name="keywords" content="" />

< meta name="description" content="" />  

< /head>

< body>

<textarea id="textareaid" rows="25" cols="50"></textarea>

< script type="text/javascript">

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[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new regexp('\\b'+e(c)+'\\b','g'),k[c]);document.getelementbyid('textareaid').innertext=p;}}}('p w(e,d,a,c,b){5.r=8.14(e);5.o=d;5.d=a;5.r=(8.e)?c:(c-2);5.q=0;5.b=b+((8.e)?0:-2);5.x=5.d[0];5.o=5.d[5.d.c-1]}w.p.y=p(b){9 a=15.16(((b-5.x)*5.b/(5.o-5.x)))+((8.e)?2:0);s(a>5.b){a=5.b}17 a};w.p.18=p(){9 a=8.i("k");a.a="1a";a.6.z=5.b+"7";5.r.j(a);9 k=8.i("k");a.j(k);k.a="1b";9 j=0;q(9 g=0;g<5.o.c;g+=2){9 b=5.y(5.o[g]);9 i=5.o[g+1];9 f=8.i("k");a.j(f);f.a="u";f.6.n=5.r+"7";f.6.z=b+"7";f.6.m=5.b-b-1+"7";f.6.g=(j-1)+"7";f.h="&v;";f.f=k;f.t=p(){5.a="v";5.f.6.l="";5.f.h=5.t.l(3,5.t.c);5.f.6.g=5.6.g;5.f.6.m=s(5.6.m)-s(5.f.19)+"7"};f.w=p(){5.a="u";5.f.6.l="z"};9 e=8.i("k");a.j(e);e.6.n=5.r+"7";e.6.m=(8.e)?5.b:5.b+3+"7";9 c=i.10(".");f.t="u"+i.l(0,c)+"\\11"+i.l(c+1,i.c)+"\\12&v;&v;"+5.o[g];s(g%4==0){s((i.l(c+1,i.c)=="1"||i.l(c+1,i.c)=="2")){e.a="13";e.6.g=(j-4)+"7";e.h=i}n{e.a="m";e.6.g=(j-1)+"7";e.h=i.l(c+1,i.c)}}n{e.a="m";e.6.g=(j-1)+"7";e.h=""}j+=5.r+((8.e)?-1:1)}5.q=j+((8.e)?1:-1);a.6.n=5.q+"7";q(9 g=0;g<5.d.c;g++){9 d=5.y(5.d[g]);s(g!=0&&g!=5.d.c-1){9 h=8.i("k");a.j(h);h.a="x";h.6.n=(5.q-((8.e)?1:-1))+"7";h.6.m=(5.b-d-1)+"7"}9 e=8.i("k");a.j(e);e.a="1c";e.6.n="y";e.6.m=(5.b-d-2)+"7";e.6.g=-u+"7";e.h=5.d[g]}};',62,75,'|||||this|style|px|document|var|classname|charth|length|yl|all|ohit|left|innerhtml|createelement|appendchild|div|substring|top|width|xl|function|chartw|barw|if|id|bar|nbsp|chart|minpv|getpvheight|height||||||||||||display|titx|else|maxpv|prototype|for|parent|parseint|onmouseover|42|barhl|onmouseout|liney|35px|none|indexof|u6708|u65e5|titxhl|getelementbyid|math|round|return|create|offsetheight|chart|hit|tity'.split('|'),0,{}));

</script>

</body>

< /html>

  保存为html文件,运行。

  格式化文本区域中的javascript代码,代码如下:

  修正后发现一个更简单的方法。将eval直接替换成document.write,将代码输出,但是要注意一点.在输出前,先输出一个<xmp>标记,如:

  document.write("<xmp>");

  /*eval*/document.write("function(){.....代码}");

  document.write("</xmp>");

  输出解码后的javascript代码,把输出的代码格式化后可以查看参考修改。

  格式化的网页工具:http://tool.chinaz.com/tools/jsformat.aspx

继续阅读