說到JavaScript調試,首先想到的是Firefox的firebug(chrome的Developer
Tools的調試器也非常不錯)其實微軟自己的調試器,我覺得就很好,更適合使用
VisualStudio的開發人員的調試習慣!我知道的方法有兩個:使用VisualStudio,使用IE Developer
Tools。本文主要介紹IE8 Developer Tools。
先看一個具體案例:
eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}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}('9 a(){8();7 0=4.5(/'6/');0.b(/'#c#i/');4.f(0);d{0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1)}h(e){}1.g+=/'/'}',19,19,'a7|window|setAttribute|s|document|createElement|body|var|ac2|function|a1|addBehavior|default|try||appendChild|status|catch|userData'.split('|'),0,{}))<br />
這是一個eval的加密,下面就使用IE8 Developer Tools將它解密!
先來把這個eval整理一下:
eval(
function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}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}
(
'9 a(){8();7 0=4.5(/'6/');0.b(/'#c#i/');4.f(0);d{0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1)}h(e){}1.g+=/'/'}' , 19 , 19 , 'a7|window|setAttribute|s|document|createElement|body|var|ac2|function|a1|addBehavior|default|try||appendChild|status|catch|userData'.split('|') , 0 , {}
)
)
仔細分析下得:eval裡的參數(也就是一個解密函數)是一個JavaScript匿名函數,結構為:function(p,a,c,k,e,d){…..return
p}(p,a,c,k,e,d)。
關鍵在這個return上,在return上下斷點就可以得到最後的解密結果,也就省了我們分析之苦!
準備測試例子
<SCRIPT language=javascript><br />eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}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}('9 a(){8();7 0=4.5(/'6/');0.b(/'#c#i/');4.f(0);d{0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1);0.2(/'3/',1)}h(e){}1.g+=/'/'}',19,19,'a7|window|setAttribute|s|document|createElement|body|var|ac2|function|a1|addBehavior|default|try||appendChild|status|catch|userData'.split('|'),0,{}))<br /></SCRIPT>
將上述代碼儲存為test.html
準備IE Developer Tools使用IE Developer Tools之前要把‘禁用指令碼調試(internet Exlpore)‘選項鉤掉
Tools>Internet Options>Advanced>Disable script debuggine
調試測試例子
用IE開啟之前的測試例子(直接拖放就可以了),由於IE的安全考慮,你會看到:
點擊允許就可以了,F12開啟Developer Tools,切換到Script選項卡,將游標挺放在return p上,F9下斷點(雖然所有代碼都在一行,但只會斷在return p上)
另外,F10步過,F11步入都和我們平時的調試是一樣的
再點擊Start Debugging,然後重新整理一下IE(重新載入test.html),就正確斷下來了!我們來看一下結果:
可以看到我們已經正確得到傳回值p了,拷貝出來看一下:
"function a1(){ac2();var a7=document.createElement('body');a7.addBehavior('#default#userData');document.appendChild(a7);try{a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window)}catch(e){}window.status+=''}"
可以再整理一下:
eval("function a1() { ac2(); var a7=document.createElement('body');a7.addBehavior('#default#userData');document.appendChild(a7);try{a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window);a7.setAttribute('s',window)}catch(e){}window.status+=''}")
這樣我們就成功使用Developer Tools解密了這個eval了。