eval(function(p,a,c,k,e,d) 加密破解JS代码的方法

eval(function(p,a,c,k,e,d) 加密破解JS代码de方法
最近遇到了一段js代码是通过 eval(function(p,a,c,k,e,d) 方式加密的。

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}

想了一下,其实这种加密方式解密很非常简单,因为函数本地就带有解密函数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就可以了。

 

其实还可以这样 eval()函数 直接换成输出document.write()函数直接将js代码输出就ok了。不过这里需要注意 在输出的js代码前后加上 <xmp>   </xmp>。

例如:
document.write(“<xmp>”);
/*eval*/document.write(“function(){…..代码}”);
document.write(“</xmp>”);

 

这样获取到了 js源码 在用格式化工具格式一下就更清晰了:

http://tool.chinaz.com/Tools/JsFormat.aspx

发表评论

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