开发者

break javascript one line code to readable code

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

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

Thanks.


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

The following works pretty well:

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 minification and 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.

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/Minification_(programming)


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


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


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.


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.

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/

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


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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜