简体   繁体   English

如何调试混淆的JavaScript?

[英]How to debug obfuscated JavaScript?

I need to debug obfuscated JavaScript like this example: 我需要像这个例子那样调试混淆的JavaScript:

__d("DataStore",[],function(a,b,c,d,e,f){var g={},h=1;function i(l){if(typeof l=='string'){return 'str_'+l;}else return 'elem_'+(l.__FB_TOKEN||(l.__FB_TOKEN=[h++]))........

JavaScript debuggers embedded in MSIE, Opera and Chrome do not understand that JS uses semicolons and not CRLF as a line breaks; 嵌入在MSIE,Opera和Chrome中的JavaScript调试器不理解JS使用分号而不是CRLF作为换行符; so it is impossible to debug a script like that, because entire function is located on one large line, and the debugger always highlights this one line disallowing me to see what part of code is actually executed. 因此不可能调试这样的脚本,因为整个函数位于一个大行上,调试器总是突出显示这一行,不允许我看看实际执行了哪部分代码。

Is there any way to debug JavaScript files that contain a very long line of code and don't use CRLF to separate code lines? 有没有办法调试包含很长代码行的JavaScript文件,而不使用CRLF来分隔代码行?

Chrome devtools“Scripts / Sources”窗格具有“漂亮打印”模式(在底部工具栏中查找{}按钮)。

Use a Javascript Beautifier to reformat the code and then debug the code. 使用Javascript Beautifier重新格式化代码,然后调试代码。

Check out http://jsbeautifier.org/ 查看http://jsbeautifier.org/

Google Chrome has a "Pretty print" function that allows to reindent the code. 谷歌浏览器具有“漂亮打印”功能,可以重新启动代码。

I don't normally use it, so I don't know since when it exists, but it's present in Chrome 21 dev. 我通常不会使用它,因此我不知道它何时存在,但它存在于Chrome 21 dev中。

There is no single solution for this. 对此没有单一的解决方案。 The first thing you can to to have something a bit more readable is to copy/paste the javascript code into http://jsbeautifier.org/ 首先要将javascript代码复制/粘贴到http://jsbeautifier.org/中,以便更具可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM