天天看點

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

繼續閱讀