将 javascript 一行代码分解为可读代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7604585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:40:50  来源:igfitidea点击:

break javascript one line code to readable code

javascriptcoding-styleipcomments

提问by JJ Liu

I have seen people put all their JS code into one single line. (something like this: http://www.drasticdata.nl/DrasticTreemap/Examples/js/swfobject.js) I know they are trying to protect their IP. But I want to read the code and study it.

我见过人们把他们所有的 JS 代码放在一行中。(像这样:http: //www.drasticdata.nl/DrasticTreemap/Examples/js/swfobject.js)我知道他们正在努力保护他们的 IP。但我想阅读代码并研究它。

Is there a way to make those one-line code readable? For example, break it down to multiple lines?

有没有办法让这些单行代码可读?例如,将其分解为多行?

Thanks.

谢谢。

回答by xandercoded

A quick google search for "JavaScript de-obfuscator" will return you multiple online parsers that format obfuscated code into something formatted and readable.

谷歌快速搜索“JavaScript de-obfuscator”将返回多个在线解析器,这些解析器将混淆代码格式化为格式化和可读的内容。

The following works pretty well:

以下工作非常好:

http://jsbeautifier.org/

http://jsbeautifier.org/

There is no way to rename variable names to their, once semantic, forms. Something you'll have to tread through...

没有办法将变量名重命名为它们曾经的语义形式。你必须经历的事情......

A couple of terms to note minificationand obfuscation:

需要注意缩小混淆的几个术语:

Minification (Wikipedia)

缩小(维基百科)

Minification (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code, without changing its functionality.

在计算机编程语言,尤其是 JavaScript 中,缩小(也称为最小化或最小化)是从源代码中删除所有不必要的字符而不改变其功能的过程。

Obfuscation (Wikipedia)

混淆(维基百科)

Obfuscated code is source or machine code that has been made difficult to understand for humans. Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source code. Programs known as obfuscators transform readable code into obfuscated code using various techniques.

混淆代码是人类难以理解的源代码或机器代码。程序员可能会故意混淆代码以隐藏其目的(通过隐匿实现安全)或其逻辑以防止篡改、阻止逆向工程,或者作为阅读源代码的人的谜题或娱乐挑战。被称为混淆器的程序使用各种技术将可读代码转换为混淆代码。

References

参考

http://en.wikipedia.org/wiki/Obfuscated_code

http://en.wikipedia.org/wiki/Obfuscated_code

http://en.wikipedia.org/wiki/Minification_(programming)

http://en.wikipedia.org/wiki/Minification_(编程)

回答by DzikiMarian

for eg. this tool has "pretty print" option: http://closure-compiler.appspot.com/home. Some IDEs (eclipse) has it too.

例如。这个工具有“漂亮的打印”选项:http: //closure-compiler.appspot.com/home。一些 IDE (eclipse) 也有。

回答by Jason Barry

You're looking for http://jsbeautifier.org/

您正在寻找http://jsbeautifier.org/

回答by Thor84no

For pretty much any language, just google for a "beautifier". They'll handle all indentation etc., but obviously any shortened variables or obfuscation can't easily be dealt with.

对于几乎任何语言,只需谷歌搜索“美化者”。他们将处理所有缩进等,但显然任何缩短的变量或混淆都不容易处理。

回答by Ben Fleming

You could paste the source into a Javascript beautifier, but you're still stuck with the problem of having variable names that make no sense.

您可以将源代码粘贴到 Javascript 美化器中,但您仍然遇到了变量名称毫无意义的问题。

Considering the source is SWFObject, it is an opensource script by google, and the link to its project home page is in the source you posted: http://code.google.com/p/swfobject/

考虑到源代码是 SWFObject,它是 google 的一个开源脚本,其项目主页的链接在您发布的源代码中:http: //code.google.com/p/swfobject/

You can download the non-obfuscated code at that link.

您可以在该链接下载非混淆代码。

回答by timrwood

If you are using Chrome, there is a Pretty Print button in the scripts panel of the developer tools. This is probably much easier than going to a web app constantly.

如果您使用的是 Chrome,则开发人员工具的脚本面板中有一个 Pretty Print 按钮。这可能比经常访问 Web 应用程序要容易得多。

http://cristian-radulescu.ro/article/pretty-print-javascript-with-google-chrome.html

http://cristian-radulescu.ro/article/pretty-print-javascript-with-google-chrome.html